mirror of
https://github.com/yattee/yattee.git
synced 2025-08-06 10:44:06 +00:00
Settings for iOS/macOS
This commit is contained in:
33
Shared/Navigation/AccountsMenuView.swift
Normal file
33
Shared/Navigation/AccountsMenuView.swift
Normal file
@@ -0,0 +1,33 @@
|
||||
import Defaults
|
||||
import SwiftUI
|
||||
|
||||
struct AccountsMenuView: View {
|
||||
@EnvironmentObject<InvidiousAPI> private var api
|
||||
|
||||
@Default(.instances) private var instances
|
||||
|
||||
var body: some View {
|
||||
Menu {
|
||||
ForEach(instances, id: \.self) { instance in
|
||||
Button(accountButtonTitle(instance: instance, account: instance.anonymousAccount)) {
|
||||
api.setAccount(instance.anonymousAccount)
|
||||
}
|
||||
|
||||
ForEach(instance.accounts, id: \.self) { account in
|
||||
Button(accountButtonTitle(instance: instance, account: account)) {
|
||||
api.setAccount(account)
|
||||
}
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
Label(api.account?.name ?? "Accounts", systemImage: "person.crop.circle")
|
||||
.labelStyle(.titleAndIcon)
|
||||
}
|
||||
.disabled(instances.isEmpty)
|
||||
.transaction { t in t.animation = .none }
|
||||
}
|
||||
|
||||
func accountButtonTitle(instance: Instance, account: Instance.Account) -> String {
|
||||
instances.count > 1 ? "\(account.description) — \(instance.shortDescription)" : account.description
|
||||
}
|
||||
}
|
@@ -12,16 +12,18 @@ struct AppSidebarNavigation: View {
|
||||
}
|
||||
}
|
||||
|
||||
@EnvironmentObject<NavigationState> private var navigationState
|
||||
@EnvironmentObject<Playlists> private var playlists
|
||||
@EnvironmentObject<InvidiousAPI> private var api
|
||||
@EnvironmentObject<InstancesModel> private var instances
|
||||
@EnvironmentObject<NavigationModel> private var navigation
|
||||
@EnvironmentObject<PlaylistsModel> private var playlists
|
||||
@EnvironmentObject<Recents> private var recents
|
||||
@EnvironmentObject<SearchState> private var searchState
|
||||
@EnvironmentObject<Subscriptions> private var subscriptions
|
||||
@EnvironmentObject<SearchModel> private var search
|
||||
@EnvironmentObject<SubscriptionsModel> private var subscriptions
|
||||
|
||||
@State private var didApplyPrimaryViewWorkAround = false
|
||||
|
||||
var selection: Binding<TabSelection?> {
|
||||
navigationState.tabSelectionOptionalBinding
|
||||
navigation.tabSelectionOptionalBinding
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@@ -30,11 +32,10 @@ struct AppSidebarNavigation: View {
|
||||
// workaround for an empty supplementary view on launch
|
||||
// the supplementary view is determined by the default selection inside the
|
||||
// primary view, but the primary view is not loaded so its selection is not read
|
||||
// We work around that by briefly showing the primary view.
|
||||
// We work around that by showing the primary view
|
||||
if !didApplyPrimaryViewWorkAround, let splitVC = viewController.children.first as? UISplitViewController {
|
||||
UIView.performWithoutAnimation {
|
||||
splitVC.show(.primary)
|
||||
splitVC.hide(.primary)
|
||||
}
|
||||
didApplyPrimaryViewWorkAround = true
|
||||
}
|
||||
@@ -44,31 +45,33 @@ struct AppSidebarNavigation: View {
|
||||
#endif
|
||||
}
|
||||
|
||||
let sidebarMinWidth: Double = 280
|
||||
|
||||
var content: some View {
|
||||
NavigationView {
|
||||
sidebar
|
||||
.frame(minWidth: 180)
|
||||
.toolbar { toolbarContent }
|
||||
.frame(minWidth: sidebarMinWidth)
|
||||
|
||||
Text("Select section")
|
||||
}
|
||||
.environment(\.navigationStyle, .sidebar)
|
||||
.searchable(text: $searchState.queryText, placement: .sidebar) {
|
||||
ForEach(searchState.querySuggestions.collection, id: \.self) { suggestion in
|
||||
.searchable(text: $search.queryText, placement: .sidebar) {
|
||||
ForEach(search.querySuggestions.collection, id: \.self) { suggestion in
|
||||
Text(suggestion)
|
||||
.searchCompletion(suggestion)
|
||||
}
|
||||
}
|
||||
.onChange(of: searchState.queryText) { query in
|
||||
searchState.loadQuerySuggestions(query)
|
||||
.onChange(of: search.queryText) { query in
|
||||
search.loadSuggestions(query)
|
||||
}
|
||||
.onSubmit(of: .search) {
|
||||
searchState.changeQuery { query in
|
||||
query.query = searchState.queryText
|
||||
search.changeQuery { query in
|
||||
query.query = search.queryText
|
||||
}
|
||||
recents.open(RecentItem(from: search.queryText))
|
||||
|
||||
recents.open(RecentItem(from: searchState.queryText))
|
||||
|
||||
navigationState.tabSelection = .search
|
||||
navigation.tabSelection = .search
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,8 +83,8 @@ struct AppSidebarNavigation: View {
|
||||
.id(group)
|
||||
}
|
||||
|
||||
.onChange(of: navigationState.sidebarSectionChanged) { _ in
|
||||
scrollScrollViewToItem(scrollView: scrollView, for: navigationState.tabSelection)
|
||||
.onChange(of: navigation.sidebarSectionChanged) { _ in
|
||||
scrollScrollViewToItem(scrollView: scrollView, for: navigation.tabSelection)
|
||||
}
|
||||
}
|
||||
.background {
|
||||
@@ -93,13 +96,7 @@ struct AppSidebarNavigation: View {
|
||||
.listStyle(.sidebar)
|
||||
}
|
||||
.toolbar {
|
||||
#if os(macOS)
|
||||
ToolbarItemGroup {
|
||||
Button(action: toggleSidebar) {
|
||||
Image(systemName: "sidebar.left").help("Toggle Sidebar")
|
||||
}
|
||||
}
|
||||
#endif
|
||||
toolbarContent
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,25 +112,27 @@ struct AppSidebarNavigation: View {
|
||||
|
||||
AppSidebarRecents(selection: selection)
|
||||
.id("recentlyOpened")
|
||||
AppSidebarSubscriptions(selection: selection)
|
||||
AppSidebarPlaylists(selection: selection)
|
||||
|
||||
if api.signedIn {
|
||||
AppSidebarSubscriptions(selection: selection)
|
||||
AppSidebarPlaylists(selection: selection)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var mainNavigationLinks: some View {
|
||||
Section("Videos") {
|
||||
NavigationLink(tag: TabSelection.watchNow, selection: selection) {
|
||||
WatchNowView()
|
||||
}
|
||||
label: {
|
||||
NavigationLink(destination: LazyView(WatchNowView()), tag: TabSelection.watchNow, selection: selection) {
|
||||
Label("Watch Now", systemImage: "play.circle")
|
||||
.accessibility(label: Text("Watch Now"))
|
||||
}
|
||||
|
||||
NavigationLink(destination: LazyView(SubscriptionsView()), tag: TabSelection.subscriptions, selection: selection) {
|
||||
Label("Subscriptions", systemImage: "star.circle")
|
||||
.accessibility(label: Text("Subscriptions"))
|
||||
if api.signedIn {
|
||||
NavigationLink(destination: LazyView(SubscriptionsView()), tag: TabSelection.subscriptions, selection: selection) {
|
||||
Label("Subscriptions", systemImage: "star.circle")
|
||||
.accessibility(label: Text("Subscriptions"))
|
||||
}
|
||||
}
|
||||
|
||||
NavigationLink(destination: LazyView(PopularView()), tag: TabSelection.popular, selection: selection) {
|
||||
@@ -145,11 +144,6 @@ struct AppSidebarNavigation: View {
|
||||
Label("Trending", systemImage: "chart.line.uptrend.xyaxis")
|
||||
.accessibility(label: Text("Trending"))
|
||||
}
|
||||
|
||||
NavigationLink(destination: LazyView(PlaylistsView()), tag: TabSelection.playlists, selection: selection) {
|
||||
Label("Playlists", systemImage: "list.and.film")
|
||||
.accessibility(label: Text("Playlists"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,6 +159,36 @@ struct AppSidebarNavigation: View {
|
||||
}
|
||||
}
|
||||
|
||||
var toolbarContent: some ToolbarContent {
|
||||
Group {
|
||||
#if os(iOS)
|
||||
ToolbarItemGroup(placement: .navigationBarTrailing) {
|
||||
Button(action: { navigation.presentingSettings = true }) {
|
||||
Image(systemName: "gearshape.2")
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
ToolbarItem(placement: accountsMenuToolbarItemPlacement) {
|
||||
AccountsMenuView()
|
||||
.help(
|
||||
"Switch Instances and Accounts\n" +
|
||||
"Current Instance: \n" +
|
||||
"\(api.account?.url ?? "Not Set")\n" +
|
||||
"Current User: \(api.account?.description ?? "Not set")"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var accountsMenuToolbarItemPlacement: ToolbarItemPlacement {
|
||||
#if os(iOS)
|
||||
return .bottomBar
|
||||
#else
|
||||
return .automatic
|
||||
#endif
|
||||
}
|
||||
|
||||
#if os(macOS)
|
||||
private func toggleSidebar() {
|
||||
NSApp.keyWindow?.contentViewController?.tryToPerform(#selector(NSSplitViewController.toggleSidebar(_:)), with: nil)
|
||||
@@ -177,6 +201,6 @@ struct AppSidebarNavigation: View {
|
||||
|
||||
let symbolName = firstLetter?.range(of: regex, options: .regularExpression) != nil ? firstLetter! : "questionmark"
|
||||
|
||||
return "\(symbolName).square"
|
||||
return "\(symbolName).circle"
|
||||
}
|
||||
}
|
||||
|
@@ -1,14 +1,14 @@
|
||||
import SwiftUI
|
||||
|
||||
struct AppSidebarPlaylists: View {
|
||||
@EnvironmentObject<NavigationState> private var navigationState
|
||||
@EnvironmentObject<Playlists> private var playlists
|
||||
@EnvironmentObject<NavigationModel> private var navigation
|
||||
@EnvironmentObject<PlaylistsModel> private var playlists
|
||||
|
||||
@Binding var selection: TabSelection?
|
||||
|
||||
var body: some View {
|
||||
Section(header: Text("Playlists")) {
|
||||
ForEach(playlists.all) { playlist in
|
||||
ForEach(playlists.playlists.sorted { $0.title.lowercased() < $1.title.lowercased() }) { playlist in
|
||||
NavigationLink(tag: TabSelection.playlist(playlist.id), selection: $selection) {
|
||||
LazyView(PlaylistVideosView(playlist))
|
||||
} label: {
|
||||
@@ -18,7 +18,7 @@ struct AppSidebarPlaylists: View {
|
||||
.id(playlist.id)
|
||||
.contextMenu {
|
||||
Button("Edit") {
|
||||
navigationState.presentEditPlaylistForm(playlists.find(id: playlist.id))
|
||||
navigation.presentEditPlaylistForm(playlists.find(id: playlist.id))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,11 +26,14 @@ struct AppSidebarPlaylists: View {
|
||||
newPlaylistButton
|
||||
.padding(.top, 8)
|
||||
}
|
||||
.onAppear {
|
||||
playlists.load()
|
||||
}
|
||||
}
|
||||
|
||||
var newPlaylistButton: some View {
|
||||
Button(action: { navigationState.presentNewPlaylistForm() }) {
|
||||
Label("New Playlist", systemImage: "plus.square")
|
||||
Button(action: { navigation.presentNewPlaylistForm() }) {
|
||||
Label("New Playlist", systemImage: "plus.circle")
|
||||
}
|
||||
.foregroundColor(.secondary)
|
||||
.buttonStyle(.plain)
|
||||
|
@@ -4,7 +4,7 @@ import SwiftUI
|
||||
struct AppSidebarRecents: View {
|
||||
@Binding var selection: TabSelection?
|
||||
|
||||
@EnvironmentObject<NavigationState> private var navigationState
|
||||
@EnvironmentObject<NavigationModel> private var navigation
|
||||
@EnvironmentObject<Recents> private var recents
|
||||
|
||||
@Default(.recentlyOpened) private var recentItems
|
||||
@@ -18,7 +18,7 @@ struct AppSidebarRecents: View {
|
||||
switch recent.type {
|
||||
case .channel:
|
||||
RecentNavigationLink(recent: recent, selection: $selection) {
|
||||
LazyView(ChannelVideosView(Channel(id: recent.id, name: recent.title)))
|
||||
LazyView(ChannelVideosView(channel: Channel(id: recent.id, name: recent.title)))
|
||||
}
|
||||
case .query:
|
||||
RecentNavigationLink(recent: recent, selection: $selection, systemImage: "magnifyingglass") {
|
||||
|
@@ -1,8 +1,9 @@
|
||||
import Defaults
|
||||
import SwiftUI
|
||||
|
||||
struct AppSidebarSubscriptions: View {
|
||||
@EnvironmentObject<NavigationState> private var navigationState
|
||||
@EnvironmentObject<Subscriptions> private var subscriptions
|
||||
@EnvironmentObject<NavigationModel> private var navigation
|
||||
@EnvironmentObject<SubscriptionsModel> private var subscriptions
|
||||
|
||||
@Binding var selection: TabSelection?
|
||||
|
||||
@@ -10,22 +11,25 @@ struct AppSidebarSubscriptions: View {
|
||||
Section(header: Text("Subscriptions")) {
|
||||
ForEach(subscriptions.all) { channel in
|
||||
NavigationLink(tag: TabSelection.channel(channel.id), selection: $selection) {
|
||||
LazyView(ChannelVideosView(channel))
|
||||
LazyView(ChannelVideosView(channel: channel))
|
||||
} label: {
|
||||
Label(channel.name, systemImage: AppSidebarNavigation.symbolSystemImage(channel.name))
|
||||
}
|
||||
.contextMenu {
|
||||
Button("Unsubscribe") {
|
||||
navigationState.presentUnsubscribeAlert(channel)
|
||||
navigation.presentUnsubscribeAlert(channel)
|
||||
}
|
||||
}
|
||||
.modifier(UnsubscribeAlertModifier())
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
subscriptions.load()
|
||||
}
|
||||
}
|
||||
|
||||
var unsubscribeAlertTitle: String {
|
||||
if let channel = navigationState.channelToUnsubscribe {
|
||||
if let channel = navigation.channelToUnsubscribe {
|
||||
return "Unsubscribe from \(channel.name)"
|
||||
}
|
||||
|
||||
|
@@ -2,14 +2,15 @@ import Defaults
|
||||
import SwiftUI
|
||||
|
||||
struct AppTabNavigation: View {
|
||||
@EnvironmentObject<NavigationState> private var navigationState
|
||||
@EnvironmentObject<SearchState> private var searchState
|
||||
@EnvironmentObject<NavigationModel> private var navigation
|
||||
@EnvironmentObject<SearchModel> private var search
|
||||
@EnvironmentObject<Recents> private var recents
|
||||
|
||||
var body: some View {
|
||||
TabView(selection: $navigationState.tabSelection) {
|
||||
TabView(selection: $navigation.tabSelection) {
|
||||
NavigationView {
|
||||
WatchNowView()
|
||||
LazyView(WatchNowView())
|
||||
.toolbar { toolbarContent }
|
||||
}
|
||||
.tabItem {
|
||||
Label("Watch Now", systemImage: "play.circle")
|
||||
@@ -18,7 +19,8 @@ struct AppTabNavigation: View {
|
||||
.tag(TabSelection.watchNow)
|
||||
|
||||
NavigationView {
|
||||
SubscriptionsView()
|
||||
LazyView(SubscriptionsView())
|
||||
.toolbar { toolbarContent }
|
||||
}
|
||||
.tabItem {
|
||||
Label("Subscriptions", systemImage: "star.circle.fill")
|
||||
@@ -29,7 +31,8 @@ struct AppTabNavigation: View {
|
||||
// TODO: reenable with settings
|
||||
// ============================
|
||||
// NavigationView {
|
||||
// PopularView()
|
||||
// LazyView(PopularView())
|
||||
// .toolbar { toolbarContent }
|
||||
// }
|
||||
// .tabItem {
|
||||
// Label("Popular", systemImage: "chart.bar")
|
||||
@@ -38,7 +41,8 @@ struct AppTabNavigation: View {
|
||||
// .tag(TabSelection.popular)
|
||||
|
||||
NavigationView {
|
||||
TrendingView()
|
||||
LazyView(TrendingView())
|
||||
.toolbar { toolbarContent }
|
||||
}
|
||||
.tabItem {
|
||||
Label("Trending", systemImage: "chart.line.uptrend.xyaxis")
|
||||
@@ -47,7 +51,8 @@ struct AppTabNavigation: View {
|
||||
.tag(TabSelection.trending)
|
||||
|
||||
NavigationView {
|
||||
PlaylistsView()
|
||||
LazyView(PlaylistsView())
|
||||
.toolbar { toolbarContent }
|
||||
}
|
||||
.tabItem {
|
||||
Label("Playlists", systemImage: "list.and.film")
|
||||
@@ -56,25 +61,28 @@ struct AppTabNavigation: View {
|
||||
.tag(TabSelection.playlists)
|
||||
|
||||
NavigationView {
|
||||
SearchView()
|
||||
.searchable(text: $searchState.queryText, placement: .navigationBarDrawer(displayMode: .always)) {
|
||||
ForEach(searchState.querySuggestions.collection, id: \.self) { suggestion in
|
||||
Text(suggestion)
|
||||
.searchCompletion(suggestion)
|
||||
LazyView(
|
||||
SearchView()
|
||||
.toolbar { toolbarContent }
|
||||
.searchable(text: $search.queryText, placement: .navigationBarDrawer(displayMode: .always)) {
|
||||
ForEach(search.querySuggestions.collection, id: \.self) { suggestion in
|
||||
Text(suggestion)
|
||||
.searchCompletion(suggestion)
|
||||
}
|
||||
}
|
||||
}
|
||||
.onChange(of: searchState.queryText) { query in
|
||||
searchState.loadQuerySuggestions(query)
|
||||
}
|
||||
.onSubmit(of: .search) {
|
||||
searchState.changeQuery { query in
|
||||
query.query = searchState.queryText
|
||||
.onChange(of: search.queryText) { query in
|
||||
search.loadSuggestions(query)
|
||||
}
|
||||
.onSubmit(of: .search) {
|
||||
search.changeQuery { query in
|
||||
query.query = search.queryText
|
||||
}
|
||||
|
||||
recents.open(RecentItem(from: searchState.queryText))
|
||||
recents.open(RecentItem(from: search.queryText))
|
||||
|
||||
navigationState.tabSelection = .search
|
||||
}
|
||||
navigation.tabSelection = .search
|
||||
}
|
||||
)
|
||||
}
|
||||
.tabItem {
|
||||
Label("Search", systemImage: "magnifyingglass")
|
||||
@@ -83,7 +91,7 @@ struct AppTabNavigation: View {
|
||||
.tag(TabSelection.search)
|
||||
}
|
||||
.environment(\.navigationStyle, .tab)
|
||||
.sheet(isPresented: $navigationState.isChannelOpen, onDismiss: {
|
||||
.sheet(isPresented: $navigation.isChannelOpen, onDismiss: {
|
||||
if let channel = recents.presentedChannel {
|
||||
let recent = RecentItem(from: channel)
|
||||
recents.close(recent)
|
||||
@@ -91,10 +99,26 @@ struct AppTabNavigation: View {
|
||||
}) {
|
||||
if recents.presentedChannel != nil {
|
||||
NavigationView {
|
||||
ChannelVideosView(recents.presentedChannel!)
|
||||
ChannelVideosView(channel: recents.presentedChannel!)
|
||||
.environment(\.inNavigationView, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var toolbarContent: some ToolbarContent {
|
||||
#if os(iOS)
|
||||
Group {
|
||||
ToolbarItemGroup(placement: .navigationBarLeading) {
|
||||
Button(action: { navigation.presentingSettings = true }) {
|
||||
Image(systemName: "gearshape.2")
|
||||
}
|
||||
}
|
||||
|
||||
ToolbarItemGroup(placement: .navigationBarTrailing) {
|
||||
AccountsMenuView()
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@@ -1,12 +1,13 @@
|
||||
import Defaults
|
||||
import SwiftUI
|
||||
|
||||
struct ContentView: View {
|
||||
@StateObject private var navigationState = NavigationState()
|
||||
@StateObject private var playbackState = PlaybackState()
|
||||
@StateObject private var playlists = Playlists()
|
||||
@StateObject private var navigation = NavigationModel()
|
||||
@StateObject private var playback = PlaybackModel()
|
||||
@StateObject private var recents = Recents()
|
||||
@StateObject private var searchState = SearchState()
|
||||
@StateObject private var subscriptions = Subscriptions()
|
||||
|
||||
@EnvironmentObject<InvidiousAPI> private var api
|
||||
@EnvironmentObject<InstancesModel> private var instances
|
||||
|
||||
#if os(iOS)
|
||||
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
|
||||
@@ -26,29 +27,29 @@ struct ContentView: View {
|
||||
TVNavigationView()
|
||||
#endif
|
||||
}
|
||||
.environmentObject(navigation)
|
||||
.environmentObject(playback)
|
||||
.environmentObject(recents)
|
||||
#if !os(tvOS)
|
||||
.sheet(isPresented: $navigationState.showingVideo) {
|
||||
if let video = navigationState.video {
|
||||
.sheet(isPresented: $navigation.showingVideo) {
|
||||
if let video = navigation.video {
|
||||
VideoPlayerView(video)
|
||||
|
||||
#if !os(iOS)
|
||||
.frame(minWidth: 550, minHeight: 720)
|
||||
.onExitCommand {
|
||||
navigationState.showingVideo = false
|
||||
navigation.showingVideo = false
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $navigationState.presentingPlaylistForm) {
|
||||
PlaylistFormView(playlist: $navigationState.editedPlaylist)
|
||||
.sheet(isPresented: $navigation.presentingPlaylistForm) {
|
||||
PlaylistFormView(playlist: $navigation.editedPlaylist)
|
||||
}
|
||||
.sheet(isPresented: $navigation.presentingSettings) {
|
||||
SettingsView()
|
||||
}
|
||||
#endif
|
||||
.environmentObject(navigationState)
|
||||
.environmentObject(playbackState)
|
||||
.environmentObject(playlists)
|
||||
.environmentObject(recents)
|
||||
.environmentObject(searchState)
|
||||
.environmentObject(subscriptions)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user