diff options
| author | Fuwn <[email protected]> | 2025-09-01 18:51:11 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-09-01 18:51:11 -0700 |
| commit | 4fab43ffa975500e886acbebbcd901c3fb4dc6ae (patch) | |
| tree | fdbb21b3a3e11de5feb1400ec1b51a7b272895f4 | |
| parent | feat: Development commit (diff) | |
| download | sora-testing-4fab43ffa975500e886acbebbcd901c3fb4dc6ae.tar.xz sora-testing-4fab43ffa975500e886acbebbcd901c3fb4dc6ae.zip | |
feat: Development commit
| -rw-r--r-- | Sora/Data/PostWithContext.swift | 1 | ||||
| -rw-r--r-- | Sora/Views/ContentView.swift | 5 | ||||
| -rw-r--r-- | Sora/Views/Post/Details/PostDetailsTagsView.swift | 40 | ||||
| -rw-r--r-- | Sora/Views/Post/Details/PostDetailsView.swift | 8 | ||||
| -rw-r--r-- | Sora/Views/Post/Grid/PostGridView.swift | 13 |
5 files changed, 57 insertions, 10 deletions
diff --git a/Sora/Data/PostWithContext.swift b/Sora/Data/PostWithContext.swift index b98a191..bd8549e 100644 --- a/Sora/Data/PostWithContext.swift +++ b/Sora/Data/PostWithContext.swift @@ -4,6 +4,7 @@ struct PostWithContext: Hashable { let post: BooruPost // swiftlint:disable:next discouraged_optional_collection let posts: [BooruPost]? + let baseSearchText: String? func hash(into hasher: inout Hasher) { hasher.combine(post.id) diff --git a/Sora/Views/ContentView.swift b/Sora/Views/ContentView.swift index 7471c9f..fa3a69f 100644 --- a/Sora/Views/ContentView.swift +++ b/Sora/Views/ContentView.swift @@ -46,7 +46,10 @@ struct ContentView: View { } .navigationDestination(for: PostWithContext.self) { context in PostDetailsView( - post: context.post, navigationPath: $navigationPath, posts: context.posts + post: context.post, + navigationPath: $navigationPath, + posts: context.posts, + baseSearchText: context.baseSearchText ) } .navigationDestination(for: String.self) { tag in diff --git a/Sora/Views/Post/Details/PostDetailsTagsView.swift b/Sora/Views/Post/Details/PostDetailsTagsView.swift index 2c583ab..b99b124 100644 --- a/Sora/Views/Post/Details/PostDetailsTagsView.swift +++ b/Sora/Views/Post/Details/PostDetailsTagsView.swift @@ -7,6 +7,7 @@ struct PostDetailsTagsView: View { @Binding var navigationPath: NavigationPath var tags: [String] var isNestedContext: Bool = false + var baseSearchText: String? var body: some View { List { @@ -23,17 +24,46 @@ struct PostDetailsTagsView: View { .id(tag) .contextMenu { Button(action: { - if !isNestedContext { - Task { @MainActor in - manager.searchText += " \(tag)" + Task { @MainActor in + if isNestedContext { + let mainTokens = manager.tags + let baseTokens = (baseSearchText ?? "") + .components(separatedBy: .whitespaces) + .filter { !$0.isEmpty } + var merged = Array(Set(mainTokens + baseTokens)).sorted() - search() + if !merged.contains(tag) { merged.append(tag) } + + manager.searchText = merged.joined(separator: " ") + navigationPath = NavigationPath() + isPresented = false + + let localManager = manager + let localSettings = settings + + Task(priority: .userInitiated) { + await localManager.performSearch(settings: localSettings) + } + } else { + var tokens = manager.tags + + if !tokens.contains(tag) { tokens.append(tag) } + + manager.searchText = tokens.joined(separator: " ") + isPresented = false + + let localManager = manager + let localSettings = settings + + Task(priority: .userInitiated) { + await localManager.performSearch(settings: localSettings) + } } } }) { Label("Add to Search", systemImage: "plus") } - .disabled(isNestedContext || manager.searchText.contains(tag)) + .disabled(manager.tags.contains(tag)) BookmarkMenuButtonView( tags: [tag], diff --git a/Sora/Views/Post/Details/PostDetailsView.swift b/Sora/Views/Post/Details/PostDetailsView.swift index 2253f40..4a7daf3 100644 --- a/Sora/Views/Post/Details/PostDetailsView.swift +++ b/Sora/Views/Post/Details/PostDetailsView.swift @@ -9,6 +9,7 @@ struct PostDetailsView: View { @State private var isTagsSheetPresented = false // swiftlint:disable:next discouraged_optional_collection let posts: [BooruPost]? + let baseSearchText: String? private var imageURL: URL? { switch settings.detailViewQuality { @@ -27,11 +28,13 @@ struct PostDetailsView: View { post: BooruPost, navigationPath: Binding<NavigationPath>, // swiftlint:disable:next discouraged_optional_collection - posts: [BooruPost]? = nil + posts: [BooruPost]? = nil, + baseSearchText: String? = nil ) { self.post = post self._navigationPath = navigationPath self.posts = posts + self.baseSearchText = baseSearchText } var filteredPosts: [BooruPost] { @@ -144,7 +147,8 @@ struct PostDetailsView: View { isPresented: $isTagsSheetPresented, navigationPath: $navigationPath, tags: post.tags, - isNestedContext: posts != nil + isNestedContext: posts != nil, + baseSearchText: baseSearchText ) #if os(macOS) .frame( diff --git a/Sora/Views/Post/Grid/PostGridView.swift b/Sora/Views/Post/Grid/PostGridView.swift index 4fd5ffb..0ad34f5 100644 --- a/Sora/Views/Post/Grid/PostGridView.swift +++ b/Sora/Views/Post/Grid/PostGridView.swift @@ -220,7 +220,12 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length } } .navigationDestination(for: PostWithContext.self) { context in - PostDetailsView(post: context.post, navigationPath: $navigationPath, posts: context.posts) + PostDetailsView( + post: context.post, + navigationPath: $navigationPath, + posts: context.posts, + baseSearchText: context.baseSearchText + ) } .onChange(of: isSearchablePresented) { _, isPresented in if !isPresented, searchText.wrappedValue.isEmpty, !manager.isNavigatingHistory { @@ -417,7 +422,11 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length private func waterfallGridContent(post: BooruPost) -> some View { NavigationLink( - value: PostWithContext(post: post, posts: initialTag != nil ? localPosts : nil) + value: PostWithContext( + post: post, + posts: initialTag != nil ? localPosts : nil, + baseSearchText: initialTag != nil ? localSearchText : nil + ) ) { PostGridThumbnailView( post: post, |