2021-11-02 03:26:18 +05:30
|
|
|
import Defaults
|
|
|
|
import Siesta
|
|
|
|
import SwiftUI
|
|
|
|
import UniformTypeIdentifiers
|
|
|
|
|
|
|
|
struct FavoritesView: View {
|
|
|
|
@EnvironmentObject<AccountsModel> private var accounts
|
|
|
|
@EnvironmentObject<PlaylistsModel> private var playlists
|
|
|
|
|
|
|
|
@State private var dragging: FavoriteItem?
|
|
|
|
@State private var presentingEditFavorites = false
|
|
|
|
|
2021-11-07 22:22:42 +05:30
|
|
|
@State private var favoritesChanged = false
|
|
|
|
|
|
|
|
var favoritesObserver: Any?
|
|
|
|
|
|
|
|
#if !os(tvOS)
|
|
|
|
@Default(.favorites) private var favorites
|
|
|
|
#endif
|
|
|
|
|
2021-11-02 03:26:18 +05:30
|
|
|
var body: some View {
|
|
|
|
PlayerControlsView {
|
|
|
|
ScrollView(.vertical, showsIndicators: false) {
|
|
|
|
if !accounts.current.isNil {
|
|
|
|
#if os(tvOS)
|
2021-11-07 22:22:42 +05:30
|
|
|
ForEach(Defaults[.favorites]) { item in
|
|
|
|
FavoriteItemView(item: item, dragging: $dragging)
|
|
|
|
}
|
|
|
|
#else
|
2022-01-05 21:55:57 +05:30
|
|
|
#if os(iOS)
|
|
|
|
let first = favorites.first
|
|
|
|
#endif
|
2021-11-07 22:22:42 +05:30
|
|
|
ForEach(favorites) { item in
|
|
|
|
FavoriteItemView(item: item, dragging: $dragging)
|
2021-12-03 00:49:10 +05:30
|
|
|
#if os(macOS)
|
|
|
|
.workaroundForVerticalScrollingBug()
|
|
|
|
#endif
|
2022-01-05 21:55:57 +05:30
|
|
|
#if os(iOS)
|
|
|
|
.padding(.top, item == first && RefreshControl.navigationBarTitleDisplayMode == .inline ? 10 : 0)
|
|
|
|
#endif
|
2021-11-02 03:26:18 +05:30
|
|
|
}
|
2022-02-04 23:08:29 +05:30
|
|
|
Color.clear.padding(.bottom, 30)
|
2021-11-02 03:26:18 +05:30
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2021-11-07 22:22:42 +05:30
|
|
|
.onAppear {
|
|
|
|
Defaults.observe(.favorites) { _ in
|
|
|
|
favoritesChanged.toggle()
|
|
|
|
}
|
|
|
|
.tieToLifetime(of: accounts)
|
|
|
|
}
|
|
|
|
.redrawOn(change: favoritesChanged)
|
|
|
|
|
2021-11-02 03:26:18 +05:30
|
|
|
#if os(tvOS)
|
|
|
|
.edgesIgnoringSafeArea(.horizontal)
|
|
|
|
#else
|
|
|
|
.onDrop(of: [UTType.text], delegate: DropFavoriteOutside(current: $dragging))
|
|
|
|
.navigationTitle("Favorites")
|
|
|
|
#endif
|
|
|
|
#if os(macOS)
|
2021-12-20 05:06:12 +05:30
|
|
|
.background(Color.secondaryBackground)
|
2021-11-08 21:59:35 +05:30
|
|
|
.frame(minWidth: 360)
|
2021-11-02 03:26:18 +05:30
|
|
|
#endif
|
2022-01-05 21:55:57 +05:30
|
|
|
#if os(iOS)
|
|
|
|
.navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode)
|
|
|
|
#endif
|
2021-11-02 03:26:18 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Favorites_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
FavoritesView()
|
|
|
|
.injectFixtureEnvironmentObjects()
|
|
|
|
}
|
|
|
|
}
|