yattee/tvOS/EditFavorites.swift

97 lines
2.9 KiB
Swift
Raw Normal View History

2021-11-01 21:56:18 +00:00
import Defaults
import SwiftUI
struct EditFavorites: View {
@EnvironmentObject<PlaylistsModel> private var playlistsModel
private var model = FavoritesModel.shared
@Default(.favorites) private var favorites
var body: some View {
VStack {
ScrollView {
ForEach(favorites) { item in
HStack {
Text(label(item))
Spacer()
HStack(spacing: 30) {
Button {
model.moveUp(item)
} label: {
Image(systemName: "arrow.up")
}
Button {
model.moveDown(item)
} label: {
Image(systemName: "arrow.down")
}
Button {
model.remove(item)
} label: {
Image(systemName: "trash")
}
}
}
}
.padding(.trailing, 40)
Divider()
.padding(20)
ForEach(model.addableItems()) { item in
HStack {
2021-11-07 20:51:22 +00:00
HStack {
Text(label(item))
Spacer()
Text("only with Invidious")
.foregroundColor(.secondary)
}
2021-11-01 21:56:18 +00:00
Spacer()
Button {
model.add(item)
} label: {
Label("Add to Favorites", systemImage: "heart")
2021-11-07 20:51:22 +00:00
.font(.system(size: 30))
2021-11-01 21:56:18 +00:00
}
}
}
.padding(.trailing, 40)
HStack {
2021-11-09 17:43:15 +00:00
Text("Add Channels, Playlists and Searches to Favorites using")
2021-11-01 21:56:18 +00:00
Button {} label: {
Label("Add to Favorites", systemImage: "heart")
.labelStyle(.iconOnly)
}
.disabled(true)
}
.foregroundColor(.secondary)
.padding(.top, 80)
}
.frame(width: 1000, alignment: .leading)
}
2021-11-07 16:52:42 +00:00
.navigationTitle("Edit Favorites")
2021-11-01 21:56:18 +00:00
}
func label(_ item: FavoriteItem) -> String {
if case let .playlist(id) = item.section {
2021-11-02 19:40:49 +00:00
return playlistsModel.find(id: id)?.title ?? "Playlist"
2021-11-01 21:56:18 +00:00
}
return item.section.label
}
}
struct EditFavorites_Previews: PreviewProvider {
static var previews: some View {
EditFavorites()
.injectFixtureEnvironmentObjects()
}
}