yattee/Shared/Favorites/FavoritesView.swift

67 lines
2.0 KiB
Swift
Raw Normal View History

2021-11-01 21:56:18 +00:00
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 16:52:42 +00:00
@State private var favoritesChanged = false
var favoritesObserver: Any?
#if !os(tvOS)
@Default(.favorites) private var favorites
#endif
2021-11-01 21:56:18 +00:00
var body: some View {
PlayerControlsView {
ScrollView(.vertical, showsIndicators: false) {
if !accounts.current.isNil {
#if os(tvOS)
2021-11-07 16:52:42 +00:00
ForEach(Defaults[.favorites]) { item in
FavoriteItemView(item: item, dragging: $dragging)
}
#else
ForEach(favorites) { item in
FavoriteItemView(item: item, dragging: $dragging)
#if os(macOS)
.workaroundForVerticalScrollingBug()
#endif
2021-11-01 21:56:18 +00:00
}
#endif
}
}
2021-11-07 16:52:42 +00:00
.onAppear {
Defaults.observe(.favorites) { _ in
favoritesChanged.toggle()
}
.tieToLifetime(of: accounts)
}
.redrawOn(change: favoritesChanged)
2021-11-01 21:56:18 +00:00
#if os(tvOS)
.edgesIgnoringSafeArea(.horizontal)
#else
.onDrop(of: [UTType.text], delegate: DropFavoriteOutside(current: $dragging))
.navigationTitle("Favorites")
#endif
#if os(macOS)
2021-11-28 14:37:55 +00:00
.background(Color.tertiaryBackground)
2021-11-08 16:29:35 +00:00
.frame(minWidth: 360)
2021-11-01 21:56:18 +00:00
#endif
}
}
}
struct Favorites_Previews: PreviewProvider {
static var previews: some View {
FavoritesView()
.injectFixtureEnvironmentObjects()
}
}