mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Add Edit favorites
This commit is contained in:
@@ -23,6 +23,9 @@ struct BrowsingSettings: View {
|
||||
@EnvironmentObject<AccountsModel> private var accounts
|
||||
|
||||
@State private var homeHistoryItemsText = ""
|
||||
#if os(macOS)
|
||||
@State private var presentingEditFavoritesSheet = false
|
||||
#endif
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
@@ -67,9 +70,6 @@ struct BrowsingSettings: View {
|
||||
}
|
||||
#endif
|
||||
Toggle("Show Open Videos quick actions", isOn: $showOpenActionsInHome)
|
||||
if !accounts.isEmpty {
|
||||
Toggle("Show Favorites", isOn: $showFavoritesInHome)
|
||||
}
|
||||
HStack {
|
||||
Text("Recent history")
|
||||
TextField("Recent history", text: $homeHistoryItemsText)
|
||||
@@ -85,6 +85,36 @@ struct BrowsingSettings: View {
|
||||
}
|
||||
}
|
||||
.multilineTextAlignment(.trailing)
|
||||
if !accounts.isEmpty {
|
||||
Toggle("Show Favorites", isOn: $showFavoritesInHome)
|
||||
|
||||
Group {
|
||||
#if os(macOS)
|
||||
Button {
|
||||
presentingEditFavoritesSheet = true
|
||||
} label: {
|
||||
Text("Edit Favorites...")
|
||||
}
|
||||
.sheet(isPresented: $presentingEditFavoritesSheet) {
|
||||
VStack(alignment: .leading) {
|
||||
Button("Done") {
|
||||
presentingEditFavoritesSheet = false
|
||||
}
|
||||
.padding()
|
||||
.keyboardShortcut(.cancelAction)
|
||||
|
||||
EditFavorites()
|
||||
}
|
||||
.frame(width: 500, height: 300)
|
||||
}
|
||||
#else
|
||||
NavigationLink(destination: LazyView(EditFavorites())) {
|
||||
Text("Edit Favorites...")
|
||||
}
|
||||
#endif
|
||||
}
|
||||
.disabled(!showFavoritesInHome)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
105
Shared/Settings/EditFavorites.swift
Normal file
105
Shared/Settings/EditFavorites.swift
Normal file
@@ -0,0 +1,105 @@
|
||||
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 {
|
||||
Group {
|
||||
List {
|
||||
Section(header: Text("Favorites")) {
|
||||
if favorites.isEmpty {
|
||||
Text("Favorites is empty")
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
ForEach(favorites) { item in
|
||||
HStack {
|
||||
Text(label(item))
|
||||
|
||||
Spacer()
|
||||
HStack(spacing: 30) {
|
||||
Button {
|
||||
model.moveUp(item)
|
||||
} label: {
|
||||
Label("Move Up", systemImage: "arrow.up")
|
||||
}
|
||||
|
||||
Button {
|
||||
model.moveDown(item)
|
||||
} label: {
|
||||
Label("Move Down", systemImage: "arrow.down")
|
||||
}
|
||||
|
||||
Button {
|
||||
model.remove(item)
|
||||
} label: {
|
||||
Label("Remove", systemImage: "trash")
|
||||
}
|
||||
}
|
||||
#if !os(tvOS)
|
||||
.buttonStyle(.borderless)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
#if os(tvOS)
|
||||
.padding(.trailing, 40)
|
||||
#endif
|
||||
|
||||
#if os(tvOS)
|
||||
Divider()
|
||||
.padding(20)
|
||||
#endif
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#if os(tvOS)
|
||||
.padding(.trailing, 40)
|
||||
#endif
|
||||
}
|
||||
.labelStyle(.iconOnly)
|
||||
.frame(alignment: .leading)
|
||||
#if os(tvOS)
|
||||
.frame(width: 1000)
|
||||
#endif
|
||||
}
|
||||
.navigationTitle("Favorites")
|
||||
}
|
||||
|
||||
func label(_ item: FavoriteItem) -> String {
|
||||
if case let .playlist(id) = item.section {
|
||||
return playlistsModel.find(id: id)?.title ?? "Playlist"
|
||||
}
|
||||
|
||||
return item.section.label
|
||||
}
|
||||
}
|
||||
|
||||
struct EditFavorites_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
NavigationView {
|
||||
EditFavorites()
|
||||
}
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user