summaryrefslogtreecommitdiff
path: root/Sora/Views/MainView.swift
diff options
context:
space:
mode:
Diffstat (limited to 'Sora/Views/MainView.swift')
-rw-r--r--Sora/Views/MainView.swift125
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) {