summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-06-26 07:05:04 -0700
committerFuwn <[email protected]>2025-06-26 07:05:04 -0700
commitbf612d8a54317f94f0be2febd342819192f461f6 (patch)
treeaf38635f016632f7eba57137afce55c098dd57f9
parentfeat: Development commit (diff)
downloadsora-testing-bf612d8a54317f94f0be2febd342819192f461f6.tar.xz
sora-testing-bf612d8a54317f94f0be2febd342819192f461f6.zip
feat: Development commit
-rw-r--r--Localizable.xcstrings6
-rw-r--r--Sora/Data/PostGridViewState.swift5
-rw-r--r--Sora/Data/PostGridViewStateItem.swift6
-rw-r--r--Sora/Extensions/UUID+NilUUID.swift7
-rw-r--r--Sora/Views/ContentView.swift74
-rw-r--r--Sora/Views/Post/Grid/PostGridView.swift8
6 files changed, 93 insertions, 13 deletions
diff --git a/Localizable.xcstrings b/Localizable.xcstrings
index 0a0b9a0..49b207b 100644
--- a/Localizable.xcstrings
+++ b/Localizable.xcstrings
@@ -206,6 +206,9 @@
"No matching items found" : {
},
+ "No Tags" : {
+
+ },
"OK" : {
},
@@ -320,6 +323,9 @@
"Save to Photos" : {
},
+ "Save to Pictures" : {
+
+ },
"Saves post tags in a file alongside the downloaded image." : {
},
diff --git a/Sora/Data/PostGridViewState.swift b/Sora/Data/PostGridViewState.swift
index 0e0d15b..266d05c 100644
--- a/Sora/Data/PostGridViewState.swift
+++ b/Sora/Data/PostGridViewState.swift
@@ -1,5 +1,8 @@
-struct PostGridViewState {
+import Foundation
+
+struct PostGridViewState: Equatable {
var posts: [BooruPost] = []
var currentPage: Int = 1
var selectedPost: BooruPost?
+ let createdAt = Date()
}
diff --git a/Sora/Data/PostGridViewStateItem.swift b/Sora/Data/PostGridViewStateItem.swift
new file mode 100644
index 0000000..3eb66c9
--- /dev/null
+++ b/Sora/Data/PostGridViewStateItem.swift
@@ -0,0 +1,6 @@
+import Foundation
+
+struct PostGridViewStateItem: Equatable {
+ let id: UUID
+ let state: PostGridViewState
+}
diff --git a/Sora/Extensions/UUID+NilUUID.swift b/Sora/Extensions/UUID+NilUUID.swift
new file mode 100644
index 0000000..656ce40
--- /dev/null
+++ b/Sora/Extensions/UUID+NilUUID.swift
@@ -0,0 +1,7 @@
+import Foundation
+
+extension UUID {
+ static func nilUUID() -> UUID {
+ UUID(uuidString: "00000000-0000-0000-0000-000000000000")!
+ }
+}
diff --git a/Sora/Views/ContentView.swift b/Sora/Views/ContentView.swift
index 1eea6c2..4758828 100644
--- a/Sora/Views/ContentView.swift
+++ b/Sora/Views/ContentView.swift
@@ -3,10 +3,37 @@ 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 body: some View {
#if os(macOS)
- NavigationSplitView {
+ NavigationSplitView(columnVisibility: $columnVisibility) {
+ List(selection: $viewStateSelection) {
+ let history = Dictionary(uniqueKeysWithValues: manager.searchHistory.map { ($0.id, $0) })
+
+ 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)
+ }
+ }
+ }
+ } content: {
switch selectedTab {
case 1:
PostGridSearchHistoryView(
@@ -21,7 +48,11 @@ struct ContentView: View {
SettingsView()
default:
- PostGridView(selectedTab: $selectedTab)
+ PostGridView(
+ selectedTab: $selectedTab,
+ viewStates: $viewStates,
+ viewStateSelection: $viewStateSelection
+ )
}
} detail: {
if let post = manager.selectedPost {
@@ -31,17 +62,38 @@ struct ContentView: View {
.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)
- .navigationDestination(
- isPresented: Binding(
- get: { manager.selectedPost != nil },
- set: { if !$0 { manager.selectedPost = nil } }
- )
- ) {
- if let post = manager.selectedPost { PostDetailsView(post: post) }
- }
+ 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) }
+ }
}
#endif
}
diff --git a/Sora/Views/Post/Grid/PostGridView.swift b/Sora/Views/Post/Grid/PostGridView.swift
index 4b32c88..33deabc 100644
--- a/Sora/Views/Post/Grid/PostGridView.swift
+++ b/Sora/Views/Post/Grid/PostGridView.swift
@@ -6,7 +6,8 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length
@EnvironmentObject var manager: BooruManager
@State private var isSearchHistoryPresented = false
@Binding var selectedTab: Int
- @State private var viewStates: [UUID: PostGridViewState] = [:]
+ @Binding var viewStates: [UUID: PostGridViewState]
+ @Binding var viewStateSelection: UUID?
@State private var isSearchablePresented = false
@State private var cachedSuggestions: [Either<BooruTag, BooruSearchQuery>] = []
@State private var suppressNextSearchSubmit = false
@@ -359,6 +360,7 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length
selectedPost: BooruPost? = nil,
resetSelectedPost: Bool = false
) {
+ let wasNewlyCreated = viewStates[queryID] == nil
var state = viewStates[queryID] ?? PostGridViewState()
if !posts.isEmpty { state.posts = posts }
@@ -372,5 +374,9 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length
}
viewStates[queryID] = state
+
+ if wasNewlyCreated {
+ viewStateSelection = queryID
+ }
}
}