1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30
yattee/Shared/Settings/EditFavorites.swift

119 lines
3.5 KiB
Swift
Raw Normal View History

2022-11-12 06:17:31 +05:30
import Defaults
import SwiftUI
struct EditFavorites: View {
private var playlistsModel = PlaylistsModel.shared
2022-11-12 06:17:31 +05:30
private var model = FavoritesModel.shared
@Default(.favorites) private var favorites
var body: some View {
Group {
2022-11-12 07:09:44 +05:30
#if os(tvOS)
ScrollView {
VStack {
editor
2022-11-12 06:17:31 +05:30
}
2022-11-12 07:09:44 +05:30
}
.frame(width: 1000)
#else
List {
editor
}
#endif
}
.navigationTitle("Favorites")
}
2022-11-12 06:17:31 +05:30
2022-11-12 07:09:44 +05:30
var editor: some View {
Group {
Section(header: Text("Favorites")) {
if favorites.isEmpty {
Text("Favorites is empty")
.foregroundColor(.secondary)
}
ForEach(favorites) { item in
HStack {
Text(label(item))
2022-11-12 06:17:31 +05:30
2022-11-12 07:09:44 +05:30
Spacer()
HStack(spacing: 30) {
Button {
model.moveUp(item)
} label: {
Label("Move Up", systemImage: "arrow.up")
}
2022-11-12 06:17:31 +05:30
2022-11-12 07:09:44 +05:30
Button {
model.moveDown(item)
} label: {
Label("Move Down", systemImage: "arrow.down")
}
Button {
model.remove(item)
} label: {
Label("Remove", systemImage: "trash")
2022-11-12 06:17:31 +05:30
}
}
2022-11-12 07:09:44 +05:30
#if !os(tvOS)
.buttonStyle(.borderless)
#endif
2022-11-12 06:17:31 +05:30
}
}
2022-11-12 07:09:44 +05:30
}
#if os(tvOS)
.padding(.trailing, 40)
#endif
2022-11-12 06:17:31 +05:30
2022-11-12 07:09:44 +05:30
#if os(tvOS)
Divider()
.padding(20)
#endif
2022-11-12 06:17:31 +05:30
2022-11-12 07:09:44 +05:30
if !model.addableItems().isEmpty {
2022-11-12 06:17:31 +05:30
Section(header: Text("Available")) {
ForEach(model.addableItems()) { item in
HStack {
Text(label(item))
Spacer()
Button {
model.add(item)
} label: {
Label("Add to Favorites", systemImage: "heart")
#if os(tvOS)
.font(.system(size: 30))
#endif
}
2022-11-12 07:09:44 +05:30
#if !os(tvOS)
.buttonStyle(.borderless)
#endif
2022-11-12 06:17:31 +05:30
}
}
}
#if os(tvOS)
.padding(.trailing, 40)
#endif
}
}
2022-11-12 07:09:44 +05:30
.labelStyle(.iconOnly)
2022-11-12 06:17:31 +05:30
}
func label(_ item: FavoriteItem) -> String {
if case let .playlist(id) = item.section {
return playlistsModel.find(id: id)?.title ?? "Playlist".localized()
2022-11-12 06:17:31 +05:30
}
return item.section.label.localized()
2022-11-12 06:17:31 +05:30
}
}
struct EditFavorites_Previews: PreviewProvider {
static var previews: some View {
2022-11-12 07:09:44 +05:30
EditFavorites()
.injectFixtureEnvironmentObjects()
2022-11-12 06:17:31 +05:30
}
}