diff options
| author | Fuwn <[email protected]> | 2026-03-24 07:57:46 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-03-24 07:57:46 +0000 |
| commit | 021e6f20a376797df32db4e4121eb4766903a995 (patch) | |
| tree | f73c6047e6f462a17c1be1a1f3369c7ea79af024 /Sora/Views/MainView.swift | |
| parent | Refine settings language and structure (diff) | |
| download | sora-testing-021e6f20a376797df32db4e4121eb4766903a995.tar.xz sora-testing-021e6f20a376797df32db4e4121eb4766903a995.zip | |
Refocus navigation around core content
Diffstat (limited to 'Sora/Views/MainView.swift')
| -rw-r--r-- | Sora/Views/MainView.swift | 125 |
1 files changed, 84 insertions, 41 deletions
diff --git a/Sora/Views/MainView.swift b/Sora/Views/MainView.swift index 603f7a1..06e067b 100644 --- a/Sora/Views/MainView.swift +++ b/Sora/Views/MainView.swift @@ -1,8 +1,41 @@ import SwiftUI struct MainView: View { + private enum MainSidebarSection: Int, CaseIterable, Hashable { + case posts = 0 + case bookmarks = 1 + case favorites = 2 + + var title: String { + switch self { + case .posts: + "Posts" + + case .bookmarks: + "Bookmarks" + + case .favorites: + "Favorites" + } + } + + var systemImage: String { + switch self { + case .posts: + "rectangle.stack" + + case .bookmarks: + "bookmark" + + case .favorites: + "heart" + } + } + } + @EnvironmentObject var settings: SettingsManager @State private var selectedTab: Int = 0 + @State private var selectedSidebarSection: MainSidebarSection? = .posts @State private var manager = BooruManager(.yandere) var body: some View { @@ -23,13 +56,20 @@ struct MainView: View { .onChange(of: settings.sendBooruUserAgent) { updateManager(settings.preferredBooru) } .onChange(of: settings.customBooruUserAgent) { updateManager(settings.preferredBooru) } #if os(macOS) - .onChange(of: selectedTab) { _, newValue in - if newValue == 0 { + .onChange(of: selectedSidebarSection) { _, newValue in + guard let newValue else { return } + + selectedTab = newValue.rawValue + + if newValue == .posts { Task(priority: .userInitiated) { await manager.fetchPosts() } } } + .onChange(of: selectedTab) { _, newValue in + selectedSidebarSection = MainSidebarSection(rawValue: newValue) ?? .posts + } #endif } @@ -51,21 +91,6 @@ struct MainView: View { FavoritesView(selectedTab: $selectedTab, isPresented: .constant(false)) } } - - #if os(macOS) - Tab("Search History", systemImage: "clock.arrow.circlepath", value: 4) { - PostGridSearchHistoryView( - selectedTab: $selectedTab, - isPresented: .constant(false) - ) - } - #endif - - #if DEBUG || !os(macOS) - Tab("Settings", systemImage: "gear", value: 3) { - SettingsView() - } - #endif } } else { TabView(selection: $selectedTab) { @@ -84,36 +109,54 @@ struct MainView: View { } .tabItem { Label("Favorites", systemImage: "heart") } .tag(2) - - #if os(macOS) - NavigationStack { - PostGridSearchHistoryView( - selectedTab: $selectedTab, - isPresented: .constant(false) - ) - } - .tabItem { Label("Search History", systemImage: "clock.arrow.circlepath") } - .tag(4) - #endif - - #if DEBUG || !os(macOS) - SettingsView() - .tabItem { Label("Settings", systemImage: "gear") } - .tag(3) - #endif } } } + #if os(macOS) + @ViewBuilder private var sidebarContent: some View { + List(selection: $selectedSidebarSection) { + ForEach(MainSidebarSection.allCases, id: \.self) { section in + Label(section.title, systemImage: section.systemImage) + .tag(section) + } + } + .navigationTitle("Sora") + } + + @ViewBuilder private var sidebarDetailContent: some View { + switch selectedSidebarSection ?? .posts { + case .posts: + ContentView(selectedTab: $selectedTab) + + case .bookmarks: + NavigationStack { + BookmarksView(selectedTab: $selectedTab) + } + + case .favorites: + NavigationStack { + FavoritesView(selectedTab: $selectedTab, isPresented: .constant(false)) + } + } + } + #endif + @ViewBuilder private var platformSpecificContent: some View { - if #available(iOS 26, *) { - tabViewContent - #if !os(macOS) + #if os(macOS) + NavigationSplitView { + sidebarContent + } detail: { + sidebarDetailContent + } + #else + if #available(iOS 26, *) { + tabViewContent .tabBarMinimizeBehavior(.onScrollDown) - #endif - } else { - tabViewContent - } + } else { + tabViewContent + } + #endif } private func updateManager(_ provider: BooruProvider) { |