diff options
| author | Fuwn <[email protected]> | 2025-08-28 15:14:10 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-08-28 15:14:10 -0700 |
| commit | a741e13d18a0927e984dfb6eb3d760f49afe3896 (patch) | |
| tree | 34ba76fddeb26c80d902e7c1790a7fd192a52ff3 /Sora/Views/ContentView.swift | |
| parent | feat: Development commit (diff) | |
| download | sora-testing-a741e13d18a0927e984dfb6eb3d760f49afe3896.tar.xz sora-testing-a741e13d18a0927e984dfb6eb3d760f49afe3896.zip | |
feat: Development commit
Diffstat (limited to 'Sora/Views/ContentView.swift')
| -rw-r--r-- | Sora/Views/ContentView.swift | 82 |
1 files changed, 19 insertions, 63 deletions
diff --git a/Sora/Views/ContentView.swift b/Sora/Views/ContentView.swift index a88fa1b..8adb8f5 100644 --- a/Sora/Views/ContentView.swift +++ b/Sora/Views/ContentView.swift @@ -3,37 +3,15 @@ import SwiftUI struct ContentView: View { @EnvironmentObject var manager: BooruManager @Binding var selectedTab: Int - @State private var viewStates: [UUID: PostGridViewState] = [:] - @State private var viewStateSelection: UUID? @State private var columnVisibility = NavigationSplitViewVisibility.doubleColumn - - var sortedViewStates: [PostGridViewStateItem] { - viewStates - .map { PostGridViewStateItem(id: $0.key, state: $0.value) } - .sorted { $0.state.createdAt > $1.state.createdAt } - } - - var history: [UUID: BooruSearchQuery] { - Dictionary(uniqueKeysWithValues: manager.searchHistory.map { ($0.id, $0) }) - } + @State private var navigationPath = NavigationPath() var body: some View { #if os(macOS) NavigationSplitView(columnVisibility: $columnVisibility) { - List(selection: $viewStateSelection) { - if viewStates.isEmpty { - Text("No Tags") - .tag(UUID.nilUUID()) - } - - ForEach(sortedViewStates, id: \.id) { item in - if let entry = history[item.id] { - let tags = entry.tags.joined(separator: " ") - - Text(tags.isEmpty ? "No Tags" : tags) - .tag(item.id) - } - } + List { + Text("Posts") + .tag(0) } } content: { switch selectedTab { @@ -50,52 +28,30 @@ struct ContentView: View { SettingsView() default: - PostGridView( - selectedTab: $selectedTab, - viewStates: $viewStates, - viewStateSelection: $viewStateSelection - ) + PostGridView(selectedTab: $selectedTab, navigationPath: $navigationPath) } } detail: { if let post = manager.selectedPost { - PostDetailsView(post: post) + PostDetailsView(post: post, navigationPath: $navigationPath, posts: nil) } else { Text("Select a Post") .foregroundColor(.secondary) } } - .onChange(of: viewStateSelection) { _, newValue in - guard let selectedID = newValue else { return } - - if let index = manager.searchHistory.firstIndex(where: { $0.id == selectedID }) { - manager.historyIndex = index - } - } - .onChange(of: sortedViewStates) { _, newKeys in - if viewStateSelection == nil || !newKeys.contains(where: { $0.id == viewStateSelection }) { - viewStateSelection = newKeys.first?.id ?? UUID.nilUUID() - } - } - .onAppear { - if viewStates.isEmpty && viewStateSelection == nil { - viewStateSelection = UUID.nilUUID() - } - } #else - NavigationStack { - PostGridView( - selectedTab: $selectedTab, - viewStates: $viewStates, - viewStateSelection: $viewStateSelection - ) - .navigationDestination( - isPresented: Binding( - get: { manager.selectedPost != nil }, - set: { if !$0 { manager.selectedPost = nil } } - ) - ) { - if let post = manager.selectedPost { PostDetailsView(post: post) } - } + NavigationStack(path: $navigationPath) { + PostGridView(selectedTab: $selectedTab, navigationPath: $navigationPath) + .navigationDestination(for: BooruPost.self) { post in + PostDetailsView(post: post, navigationPath: $navigationPath, posts: nil) + } + .navigationDestination(for: PostWithContext.self) { context in + PostDetailsView( + post: context.post, navigationPath: $navigationPath, posts: context.posts) + } + .navigationDestination(for: String.self) { tag in + PostGridView( + selectedTab: $selectedTab, initialTag: tag, navigationPath: $navigationPath) + } } #endif } |