mirror of
https://github.com/yattee/yattee.git
synced 2025-08-06 10:44:06 +00:00
Managing Favorites sections
This commit is contained in:
@@ -40,9 +40,16 @@ struct ChannelPlaylistView: View {
|
||||
var content: some View {
|
||||
VStack(alignment: .leading) {
|
||||
#if os(tvOS)
|
||||
Text(playlist.title)
|
||||
.font(.title2)
|
||||
.frame(alignment: .leading)
|
||||
HStack {
|
||||
Text(playlist.title)
|
||||
.font(.title2)
|
||||
.frame(alignment: .leading)
|
||||
|
||||
Spacer()
|
||||
|
||||
FavoriteButton(item: FavoriteItem(section: .channelPlaylist(playlist.id, playlist.title)))
|
||||
.labelStyle(.iconOnly)
|
||||
}
|
||||
#endif
|
||||
VerticalCells(items: items)
|
||||
}
|
||||
@@ -66,12 +73,8 @@ struct ChannelPlaylistView: View {
|
||||
)
|
||||
}
|
||||
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
if inNavigationView {
|
||||
Button("Done") {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
ToolbarItem {
|
||||
FavoriteButton(item: FavoriteItem(section: .channelPlaylist(playlist.id, playlist.title)))
|
||||
}
|
||||
}
|
||||
.navigationTitle(playlist.title)
|
||||
|
@@ -51,6 +51,9 @@ struct ChannelVideosView: View {
|
||||
|
||||
Spacer()
|
||||
|
||||
FavoriteButton(item: FavoriteItem(section: .channel(channel.id, channel.name)))
|
||||
.labelStyle(.iconOnly)
|
||||
|
||||
if let subscribers = store.item?.subscriptionsString {
|
||||
Text("**\(subscribers)** subscribers")
|
||||
.foregroundColor(.secondary)
|
||||
@@ -87,14 +90,8 @@ struct ChannelVideosView: View {
|
||||
.opacity(store.item?.subscriptionsString != nil ? 1 : 0)
|
||||
|
||||
subscriptionToggleButton
|
||||
}
|
||||
}
|
||||
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
if inNavigationView {
|
||||
Button("Done") {
|
||||
dismiss()
|
||||
}
|
||||
FavoriteButton(item: FavoriteItem(section: .channel(channel.id, channel.name)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
25
Shared/Views/FavoriteButton.swift
Normal file
25
Shared/Views/FavoriteButton.swift
Normal file
@@ -0,0 +1,25 @@
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct FavoriteButton: View {
|
||||
let item: FavoriteItem
|
||||
let favorites = FavoritesModel.shared
|
||||
|
||||
@State private var isFavorite = false
|
||||
|
||||
var body: some View {
|
||||
Button {
|
||||
favorites.toggle(item)
|
||||
isFavorite.toggle()
|
||||
} label: {
|
||||
if isFavorite {
|
||||
Label("Remove from Favorites", systemImage: "heart.fill")
|
||||
} else {
|
||||
Label("Add to Favorites", systemImage: "heart")
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
isFavorite = favorites.contains(item)
|
||||
}
|
||||
}
|
||||
}
|
@@ -19,5 +19,10 @@ struct PlaylistVideosView: View {
|
||||
.navigationTitle("\(playlist.title) Playlist")
|
||||
#endif
|
||||
}
|
||||
.toolbar {
|
||||
ToolbarItem {
|
||||
FavoriteButton(item: FavoriteItem(section: .playlist(playlist.id)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -25,5 +25,10 @@ struct PopularView: View {
|
||||
.navigationTitle("Popular")
|
||||
#endif
|
||||
}
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .automatic) {
|
||||
FavoriteButton(item: FavoriteItem(section: .popular))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -26,6 +26,11 @@ struct SubscriptionsView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .automatic) {
|
||||
FavoriteButton(item: FavoriteItem(section: .subscriptions))
|
||||
}
|
||||
}
|
||||
.refreshable {
|
||||
loadResources(force: true)
|
||||
}
|
||||
|
Reference in New Issue
Block a user