diff options
| author | Fuwn <[email protected]> | 2025-02-28 03:27:07 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-02-28 03:27:07 -0800 |
| commit | d4fd7e8d5f75f1ac7718aac6c1299c3ff740de75 (patch) | |
| tree | dfd4776c3a1bbe3b448310f9572d5949c80695a5 /Sora/Views | |
| parent | feat: Development commit (diff) | |
| download | sora-testing-d4fd7e8d5f75f1ac7718aac6c1299c3ff740de75.tar.xz sora-testing-d4fd7e8d5f75f1ac7718aac6c1299c3ff740de75.zip | |
feat: Development commit
Diffstat (limited to 'Sora/Views')
| -rw-r--r-- | Sora/Views/Bookmarks/BookmarksListItemView.swift | 4 | ||||
| -rw-r--r-- | Sora/Views/Post/Grid/PostGridSearchHistoryItemView.swift | 39 | ||||
| -rw-r--r-- | Sora/Views/Post/Grid/PostGridSearchHistoryView.swift | 73 | ||||
| -rw-r--r-- | Sora/Views/Post/Grid/PostGridView.swift | 10 | ||||
| -rw-r--r-- | Sora/Views/Settings/Section/SettingsSearchView.swift | 7 |
5 files changed, 131 insertions, 2 deletions
diff --git a/Sora/Views/Bookmarks/BookmarksListItemView.swift b/Sora/Views/Bookmarks/BookmarksListItemView.swift index 6f1be95..e0973e6 100644 --- a/Sora/Views/Bookmarks/BookmarksListItemView.swift +++ b/Sora/Views/Bookmarks/BookmarksListItemView.swift @@ -8,7 +8,7 @@ struct BookmarksListItemView: View { #if os(macOS) HStack { VStack(alignment: .leading) { - Text(bookmark.tags.joined(separator: ", ")) + Text(bookmark.tags.joined(separator: ", ").lowercased()) Spacer() @@ -28,7 +28,7 @@ struct BookmarksListItemView: View { .padding() #else VStack(alignment: .leading) { - Text(bookmark.tags.joined(separator: ", ")) + Text(bookmark.tags.joined(separator: ", ").lowercased()) Text("On \(bookmark.createdAt.formatted()) from \(bookmark.provider.rawValue)") .font(.caption) diff --git a/Sora/Views/Post/Grid/PostGridSearchHistoryItemView.swift b/Sora/Views/Post/Grid/PostGridSearchHistoryItemView.swift new file mode 100644 index 0000000..5e0b7ce --- /dev/null +++ b/Sora/Views/Post/Grid/PostGridSearchHistoryItemView.swift @@ -0,0 +1,39 @@ +import SwiftUI + +struct PostGridSearchHistoryItemView: View { + @EnvironmentObject var settings: SettingsManager + var query: BooruSearchQuery + + var body: some View { + #if os(macOS) + HStack { + VStack(alignment: .leading) { + Text(query.tags.joined(separator: ", ").lowercased()) + + Spacer() + + Text("On \(query.searchedAt.formatted()) from \(query.provider.rawValue)") + .font(.caption) + .foregroundStyle(Color.secondary) + } + + Spacer() + + Button { + settings.removeSearchHistoryEntry(withID: query.id) + } label: { + Image(systemName: "trash") + } + } + .padding() + #else + VStack(alignment: .leading) { + Text(query.tags.joined(separator: ", ").lowercased()) + + Text("On \(query.searchedAt.formatted()) from \(query.provider.rawValue)") + .font(.caption) + .foregroundStyle(Color.secondary) + } + #endif + } +} diff --git a/Sora/Views/Post/Grid/PostGridSearchHistoryView.swift b/Sora/Views/Post/Grid/PostGridSearchHistoryView.swift new file mode 100644 index 0000000..be2d2ea --- /dev/null +++ b/Sora/Views/Post/Grid/PostGridSearchHistoryView.swift @@ -0,0 +1,73 @@ +import SwiftUI + +struct PostGridSearchHistoryView: View { + @EnvironmentObject private var manager: BooruManager + @EnvironmentObject private var settings: SettingsManager + @State private var searchText: String = "" + @Binding var selectedTab: Int + + var filteredHistory: [BooruSearchQuery] { + guard !searchText.isEmpty else { + return settings.searchHistory + } + + return settings.searchHistory + .filter { query in + query.tags + .joined(separator: " ") + .lowercased() + .contains(searchText.lowercased()) + } + } + + var body: some View { + NavigationStack { + VStack { + if settings.searchHistory.isEmpty { + ContentUnavailableView( + "No History", + systemImage: "magnifyingglass", + description: Text("Recent searches will appear here.") + ) + } else { + List { + if filteredHistory.isEmpty, !searchText.isEmpty { + Text("No matching history found") + } + + ForEach(filteredHistory, id: \.id) { query in + Button(action: { + let previousProvider = settings.preferredBooru + + settings.preferredBooru = query.provider + manager.searchText = query.tags.joined(separator: " ") + selectedTab = 0 + + if previousProvider == settings.preferredBooru { + manager.performSearch() + } + }) { + PostGridSearchHistoryItemView(query: query) + } + #if os(macOS) + .buttonStyle(.plain) + #endif + } + .onDelete(perform: settings.removeSearchHistoryEntry) + } + #if os(macOS) + .listStyle(.plain) + #endif + } + } + } + .navigationTitle("Search History") + .searchable(text: $searchText) + } +} + +#Preview { + PostGridSearchHistoryView(selectedTab: .constant(0)) + .environmentObject(SettingsManager()) + .environmentObject(BooruManager(.safebooru)) +} diff --git a/Sora/Views/Post/Grid/PostGridView.swift b/Sora/Views/Post/Grid/PostGridView.swift index a643391..0921c2e 100644 --- a/Sora/Views/Post/Grid/PostGridView.swift +++ b/Sora/Views/Post/Grid/PostGridView.swift @@ -4,6 +4,7 @@ import WaterfallGrid struct PostGridView: View { @EnvironmentObject var settings: SettingsManager @EnvironmentObject var manager: BooruManager + @State private var isSearchHistoryPresented = false @Environment(\.isSearching) private var isSearching @@ -84,6 +85,12 @@ struct PostGridView: View { .disabled(manager.isLoading) } + ToolbarItem(placement: .bottomBar) { + Button(action: { Task { isSearchHistoryPresented.toggle() } }) { + Label("Search History", systemImage: "clock.arrow.circlepath") + } + } + if manager.isLoading { ToolbarItem { ProgressView() @@ -104,6 +111,9 @@ struct PostGridView: View { await manager.fetchPosts(page: 1, tags: manager.tags, replace: true) } .scrollDisabled(manager.isLoading) + .sheet(isPresented: $isSearchHistoryPresented) { + PostGridSearchHistoryView(selectedTab: .constant(0)) + } } } diff --git a/Sora/Views/Settings/Section/SettingsSearchView.swift b/Sora/Views/Settings/Section/SettingsSearchView.swift index cb0d3c7..fbe1656 100644 --- a/Sora/Views/Settings/Section/SettingsSearchView.swift +++ b/Sora/Views/Settings/Section/SettingsSearchView.swift @@ -24,5 +24,12 @@ struct SettingsSearchView: View { #if os(macOS) .frame(maxWidth: .infinity, alignment: .trailing) #endif + + Button("Clear History") { + settings.searchHistory.removeAll() + } + #if os(macOS) + .frame(maxWidth: .infinity, alignment: .trailing) + #endif } } |