mirror of
https://github.com/yattee/yattee.git
synced 2025-04-25 08:06:31 +00:00
Fix video context menu channel subscription button (fixes #41)
This commit is contained in:
parent
f132ba9683
commit
0a5cb5b542
@ -28,7 +28,7 @@ final class PlaylistsModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func load(force: Bool = false, onSuccess: @escaping () -> Void = {}) {
|
func load(force: Bool = false, onSuccess: @escaping () -> Void = {}) {
|
||||||
guard !resource.isNil else {
|
guard accounts.app.supportsUserPlaylists, accounts.signedIn else {
|
||||||
playlists = []
|
playlists = []
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -35,9 +35,11 @@ final class SubscriptionsModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func load(force: Bool = false, onSuccess: @escaping () -> Void = {}) {
|
func load(force: Bool = false, onSuccess: @escaping () -> Void = {}) {
|
||||||
guard accounts.app.supportsSubscriptions else {
|
guard accounts.app.supportsSubscriptions, accounts.signedIn else {
|
||||||
|
channels = []
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let request = force ? resource?.load() : resource?.loadIfNeeded()
|
let request = force ? resource?.load() : resource?.loadIfNeeded()
|
||||||
|
|
||||||
request?
|
request?
|
||||||
|
@ -9,6 +9,10 @@ private struct InChannelViewKey: EnvironmentKey {
|
|||||||
static let defaultValue = false
|
static let defaultValue = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private struct InChannelPlaylistViewKey: EnvironmentKey {
|
||||||
|
static let defaultValue = false
|
||||||
|
}
|
||||||
|
|
||||||
private struct HorizontalCellsKey: EnvironmentKey {
|
private struct HorizontalCellsKey: EnvironmentKey {
|
||||||
static let defaultValue = false
|
static let defaultValue = false
|
||||||
}
|
}
|
||||||
@ -36,6 +40,11 @@ extension EnvironmentValues {
|
|||||||
set { self[InChannelViewKey.self] = newValue }
|
set { self[InChannelViewKey.self] = newValue }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var inChannelPlaylistView: Bool {
|
||||||
|
get { self[InChannelPlaylistViewKey.self] }
|
||||||
|
set { self[InChannelPlaylistViewKey.self] = newValue }
|
||||||
|
}
|
||||||
|
|
||||||
var horizontalCells: Bool {
|
var horizontalCells: Bool {
|
||||||
get { self[HorizontalCellsKey.self] }
|
get { self[HorizontalCellsKey.self] }
|
||||||
set { self[HorizontalCellsKey.self] = newValue }
|
set { self[HorizontalCellsKey.self] = newValue }
|
||||||
|
@ -39,6 +39,10 @@ struct ContentView: View {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
.onAppear(perform: configure)
|
.onAppear(perform: configure)
|
||||||
|
.onChange(of: accounts.signedIn) { _ in
|
||||||
|
subscriptions.load(force: true)
|
||||||
|
playlists.load(force: true)
|
||||||
|
}
|
||||||
|
|
||||||
.environmentObject(accounts)
|
.environmentObject(accounts)
|
||||||
.environmentObject(comments)
|
.environmentObject(comments)
|
||||||
@ -83,6 +87,17 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
#endif
|
#endif
|
||||||
|
.alert(isPresented: $navigation.presentingUnsubscribeAlert) {
|
||||||
|
Alert(
|
||||||
|
title: Text(
|
||||||
|
"Are you sure you want to unsubscribe from \(navigation.channelToUnsubscribe.name)?"
|
||||||
|
),
|
||||||
|
primaryButton: .destructive(Text("Unsubscribe")) {
|
||||||
|
subscriptions.unsubscribe(navigation.channelToUnsubscribe.id)
|
||||||
|
},
|
||||||
|
secondaryButton: .cancel()
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func configure() {
|
func configure() {
|
||||||
@ -135,6 +150,9 @@ struct ContentView: View {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
navigation.tabSelection = section ?? .search
|
navigation.tabSelection = section ?? .search
|
||||||
|
|
||||||
|
subscriptions.load()
|
||||||
|
playlists.load()
|
||||||
}
|
}
|
||||||
|
|
||||||
func openWelcomeScreenIfAccountEmpty() {
|
func openWelcomeScreenIfAccountEmpty() {
|
||||||
|
@ -29,14 +29,6 @@ struct Sidebar: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onAppear {
|
|
||||||
subscriptions.load()
|
|
||||||
playlists.load()
|
|
||||||
}
|
|
||||||
.onChange(of: accounts.signedIn) { _ in
|
|
||||||
subscriptions.load(force: true)
|
|
||||||
playlists.load(force: true)
|
|
||||||
}
|
|
||||||
.onChange(of: navigation.sidebarSectionChanged) { _ in
|
.onChange(of: navigation.sidebarSectionChanged) { _ in
|
||||||
scrollScrollViewToItem(scrollView: scrollView, for: navigation.tabSelection)
|
scrollScrollViewToItem(scrollView: scrollView, for: navigation.tabSelection)
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,7 @@ struct ChannelPlaylistView: View {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
VerticalCells(items: items)
|
VerticalCells(items: items)
|
||||||
|
.environment(\.inChannelPlaylistView, true)
|
||||||
}
|
}
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
.sheet(isPresented: $presentingShareSheet) {
|
.sheet(isPresented: $presentingShareSheet) {
|
||||||
|
@ -67,46 +67,40 @@ struct ChannelVideosView: View {
|
|||||||
.frame(maxWidth: .infinity)
|
.frame(maxWidth: .infinity)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if os(iOS)
|
VerticalCells(items: videos)
|
||||||
VerticalCells(items: videos)
|
.environment(\.inChannelView, true)
|
||||||
#else
|
#if os(tvOS)
|
||||||
if #available(macOS 12.0, *) {
|
.prefersDefaultFocus(in: focusNamespace)
|
||||||
VerticalCells(items: videos)
|
|
||||||
.prefersDefaultFocus(in: focusNamespace)
|
|
||||||
} else {
|
|
||||||
VerticalCells(items: videos)
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
.environment(\.inChannelView, true)
|
|
||||||
|
|
||||||
#if !os(tvOS)
|
#if !os(tvOS)
|
||||||
.toolbar {
|
.toolbar {
|
||||||
ToolbarItem(placement: .navigation) {
|
ToolbarItem(placement: .navigation) {
|
||||||
ShareButton(
|
ShareButton(
|
||||||
contentItem: contentItem,
|
contentItem: contentItem,
|
||||||
presentingShareSheet: $presentingShareSheet,
|
presentingShareSheet: $presentingShareSheet,
|
||||||
shareURL: $shareURL
|
shareURL: $shareURL
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
ToolbarItem {
|
ToolbarItem {
|
||||||
HStack {
|
HStack {
|
||||||
HStack(spacing: 3) {
|
HStack(spacing: 3) {
|
||||||
Text("\(store.item?.subscriptionsString ?? "loading")")
|
Text("\(store.item?.subscriptionsString ?? "loading")")
|
||||||
.fontWeight(.bold)
|
.fontWeight(.bold)
|
||||||
Text(" subscribers")
|
Text(" subscribers")
|
||||||
}
|
|
||||||
.allowsTightening(true)
|
|
||||||
.foregroundColor(.secondary)
|
|
||||||
.opacity(store.item?.subscriptionsString != nil ? 1 : 0)
|
|
||||||
|
|
||||||
subscriptionToggleButton
|
|
||||||
|
|
||||||
FavoriteButton(item: FavoriteItem(section: .channel(channel.id, channel.name)))
|
|
||||||
}
|
}
|
||||||
|
.allowsTightening(true)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
.opacity(store.item?.subscriptionsString != nil ? 1 : 0)
|
||||||
|
|
||||||
|
subscriptionToggleButton
|
||||||
|
|
||||||
|
FavoriteButton(item: FavoriteItem(section: .channel(channel.id, channel.name)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
.sheet(isPresented: $presentingShareSheet) {
|
.sheet(isPresented: $presentingShareSheet) {
|
||||||
@ -164,17 +158,6 @@ struct ChannelVideosView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.alert(isPresented: $navigation.presentingUnsubscribeAlert) {
|
|
||||||
Alert(
|
|
||||||
title: Text(
|
|
||||||
"Are you sure you want to unsubscribe from \(channel.name)?"
|
|
||||||
),
|
|
||||||
primaryButton: .destructive(Text("Unsubscribe")) {
|
|
||||||
subscriptions.unsubscribe(channel.id)
|
|
||||||
},
|
|
||||||
secondaryButton: .cancel()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var contentItem: ContentItem {
|
private var contentItem: ContentItem {
|
||||||
|
@ -8,6 +8,7 @@ struct VideoContextMenuView: View {
|
|||||||
|
|
||||||
@Environment(\.inNavigationView) private var inNavigationView
|
@Environment(\.inNavigationView) private var inNavigationView
|
||||||
@Environment(\.inChannelView) private var inChannelView
|
@Environment(\.inChannelView) private var inChannelView
|
||||||
|
@Environment(\.inChannelPlaylistView) private var inChannelPlaylistView
|
||||||
@Environment(\.navigationStyle) private var navigationStyle
|
@Environment(\.navigationStyle) private var navigationStyle
|
||||||
@Environment(\.currentPlaylistID) private var playlistID
|
@Environment(\.currentPlaylistID) private var playlistID
|
||||||
|
|
||||||
@ -28,11 +29,11 @@ struct VideoContextMenuView: View {
|
|||||||
addToQueueButton
|
addToQueueButton
|
||||||
}
|
}
|
||||||
|
|
||||||
if !inChannelView {
|
if !inChannelView, !inChannelPlaylistView {
|
||||||
Section {
|
Section {
|
||||||
openChannelButton
|
openChannelButton
|
||||||
|
|
||||||
if accounts.app.supportsSubscriptions {
|
if accounts.app.supportsSubscriptions, accounts.api.signedIn {
|
||||||
subscriptionButton
|
subscriptionButton
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user