diff options
| author | Fuwn <[email protected]> | 2025-08-28 15:23:28 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-08-28 15:23:28 -0700 |
| commit | d7af80d2d1edcc45c043bb237c098c4cb0c026fa (patch) | |
| tree | c9775296945ce4b38e611d59e586000675f3d44c | |
| parent | feat: Development commit (diff) | |
| download | sora-testing-d7af80d2d1edcc45c043bb237c098c4cb0c026fa.tar.xz sora-testing-d7af80d2d1edcc45c043bb237c098c4cb0c026fa.zip | |
feat: Development commit
| -rw-r--r-- | Sora/Data/Booru/BooruManager.swift | 2 | ||||
| -rw-r--r-- | Sora/Data/PostWithContext.swift | 8 | ||||
| -rw-r--r-- | Sora/Views/ContentView.swift | 6 | ||||
| -rw-r--r-- | Sora/Views/Post/Details/PostDetailsView.swift | 8 | ||||
| -rw-r--r-- | Sora/Views/Post/Grid/PostGridView.swift | 46 |
5 files changed, 43 insertions, 27 deletions
diff --git a/Sora/Data/Booru/BooruManager.swift b/Sora/Data/Booru/BooruManager.swift index 5160c9d..b5b5ea7 100644 --- a/Sora/Data/Booru/BooruManager.swift +++ b/Sora/Data/Booru/BooruManager.swift @@ -102,7 +102,7 @@ class BooruManager: ObservableObject { // swiftlint:disable:this type_body_leng let provider = self.provider let newPosts = await withCheckedContinuation { continuation in DispatchQueue.global(qos: .userInitiated).async { - let parsedPosts = BooruManager.parsePosts( + let parsedPosts = Self.parsePosts( from: data, flavor: flavor, provider: provider diff --git a/Sora/Data/PostWithContext.swift b/Sora/Data/PostWithContext.swift index c8cb2f6..b98a191 100644 --- a/Sora/Data/PostWithContext.swift +++ b/Sora/Data/PostWithContext.swift @@ -2,18 +2,14 @@ import Foundation struct PostWithContext: Hashable { let post: BooruPost + // swiftlint:disable:next discouraged_optional_collection let posts: [BooruPost]? - init(post: BooruPost, posts: [BooruPost]?) { - self.post = post - self.posts = posts - } - func hash(into hasher: inout Hasher) { hasher.combine(post.id) } - static func == (lhs: PostWithContext, rhs: PostWithContext) -> Bool { + static func == (lhs: Self, rhs: Self) -> Bool { lhs.post.id == rhs.post.id } } diff --git a/Sora/Views/ContentView.swift b/Sora/Views/ContentView.swift index 8adb8f5..7471c9f 100644 --- a/Sora/Views/ContentView.swift +++ b/Sora/Views/ContentView.swift @@ -46,11 +46,13 @@ 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 + ) } .navigationDestination(for: String.self) { tag in PostGridView( - selectedTab: $selectedTab, initialTag: tag, navigationPath: $navigationPath) + selectedTab: $selectedTab, navigationPath: $navigationPath, initialTag: tag + ) } } #endif diff --git a/Sora/Views/Post/Details/PostDetailsView.swift b/Sora/Views/Post/Details/PostDetailsView.swift index 8051cf2..aa4c3cd 100644 --- a/Sora/Views/Post/Details/PostDetailsView.swift +++ b/Sora/Views/Post/Details/PostDetailsView.swift @@ -7,6 +7,7 @@ struct PostDetailsView: View { @Binding var navigationPath: NavigationPath @State private var loadingStage: BooruPostLoadingState = .loadingPreview @State private var isTagsSheetPresented = false + // swiftlint:disable:next discouraged_optional_collection let posts: [BooruPost]? private var imageURL: URL? { @@ -22,7 +23,12 @@ struct PostDetailsView: View { } } - init(post: BooruPost, navigationPath: Binding<NavigationPath>, posts: [BooruPost]? = nil) { + init( + post: BooruPost, + navigationPath: Binding<NavigationPath>, + // swiftlint:disable:next discouraged_optional_collection + posts: [BooruPost]? = nil + ) { self.post = post self._navigationPath = navigationPath self.posts = posts diff --git a/Sora/Views/Post/Grid/PostGridView.swift b/Sora/Views/Post/Grid/PostGridView.swift index ebeac31..4205309 100644 --- a/Sora/Views/Post/Grid/PostGridView.swift +++ b/Sora/Views/Post/Grid/PostGridView.swift @@ -24,7 +24,7 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length @State private var localError: Error? init( - selectedTab: Binding<Int>, initialTag: String? = nil, navigationPath: Binding<NavigationPath> + selectedTab: Binding<Int>, navigationPath: Binding<NavigationPath>, initialTag: String? = nil ) { self._selectedTab = selectedTab self.initialTag = initialTag @@ -50,12 +50,12 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length get: { localSearchText }, set: { localSearchText = $0 } ) - } else { - return Binding( - get: { manager.searchText }, - set: { manager.searchText = $0 } - ) } + + return Binding( + get: { manager.searchText }, + set: { manager.searchText = $0 } + ) } @ViewBuilder private var gridContent: some View { @@ -230,7 +230,7 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length } } .onAppear { - if let initialTag = initialTag { + if let initialTag { localSearchText = initialTag Task(priority: .userInitiated) { @@ -246,9 +246,11 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length if initialTag != nil { await fetchLocalPosts( page: 1, - tags: localSearchText.components(separatedBy: .whitespaces).filter { - !$0.isEmpty - }, replace: true) + tags: localSearchText.components(separatedBy: .whitespaces).filter { component in + !component.isEmpty + }, + replace: true + ) } else { await manager.fetchPosts(page: 1, tags: manager.tags, replace: true) } @@ -275,7 +277,9 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length PlatformSpecificToolbarItem { PostGridBookmarkButtonView( tags: initialTag != nil - ? localSearchText.components(separatedBy: .whitespaces).filter { !$0.isEmpty } + ? localSearchText.components(separatedBy: .whitespaces).filter { component in + !component.isEmpty + } : manager.tags, provider: manager.provider ) @@ -361,8 +365,11 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length if initialTag != nil { await fetchLocalPosts( page: 1, - tags: localSearchText.components(separatedBy: .whitespaces).filter { !$0.isEmpty }, - replace: true) + tags: localSearchText.components(separatedBy: .whitespaces).filter { component in + !component.isEmpty + }, + replace: true + ) } else { manager.clearCachedPages() Task(priority: .userInitiated) { @@ -405,8 +412,9 @@ 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)) - { + NavigationLink( + value: PostWithContext(post: post, posts: initialTag != nil ? localPosts : nil) + ) { PostGridThumbnailView( post: post, posts: activePosts, @@ -440,7 +448,9 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length // MARK: - Local Search Methods private func performLocalSearch() async { - let inputTags = localSearchText.components(separatedBy: .whitespaces).filter { !$0.isEmpty } + let inputTags = localSearchText.components(separatedBy: .whitespaces).filter { component in + !component.isEmpty + } await fetchLocalPosts(page: 1, tags: inputTags, replace: true) } @@ -450,7 +460,9 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length localCurrentPage += 1 - let inputTags = localSearchText.components(separatedBy: .whitespaces).filter { !$0.isEmpty } + let inputTags = localSearchText.components(separatedBy: .whitespaces).filter { component in + !component.isEmpty + } await fetchLocalPosts(page: localCurrentPage, tags: inputTags, replace: false) } |