diff options
| author | Fuwn <[email protected]> | 2025-03-02 06:11:03 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-03-02 06:11:03 -0800 |
| commit | aeb074b5f308172ba50ac9ae0f5ac6e3159cacb7 (patch) | |
| tree | 59502ad26db905dbf4c1003b6ec2c3b1e961ac0d /Sora/Views/Post | |
| parent | feat: Development commit (diff) | |
| download | sora-testing-aeb074b5f308172ba50ac9ae0f5ac6e3159cacb7.tar.xz sora-testing-aeb074b5f308172ba50ac9ae0f5ac6e3159cacb7.zip | |
feat: Development commit
Diffstat (limited to 'Sora/Views/Post')
| -rw-r--r-- | Sora/Views/Post/Grid/PostGridSearchHistoryView.swift | 97 |
1 files changed, 15 insertions, 82 deletions
diff --git a/Sora/Views/Post/Grid/PostGridSearchHistoryView.swift b/Sora/Views/Post/Grid/PostGridSearchHistoryView.swift index 30f7808..ae33c53 100644 --- a/Sora/Views/Post/Grid/PostGridSearchHistoryView.swift +++ b/Sora/Views/Post/Grid/PostGridSearchHistoryView.swift @@ -1,92 +1,25 @@ import SwiftUI struct PostGridSearchHistoryView: View { - @EnvironmentObject private var manager: BooruManager - @EnvironmentObject private var settings: SettingsManager - @State private var searchText: String = "" + @EnvironmentObject var settings: SettingsManager @Binding var selectedTab: Int @Binding var isPresented: Bool - @State private var isShowingRemoveAllConfirmation = false - - 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.sorted { $0.date > $1.date }, - id: \.id - ) { query in - Button(action: { - let previousProvider = settings.preferredBooru - - settings.preferredBooru = query.provider - manager.searchText = query.tags.joined(separator: " ") - selectedTab = 0 - - isPresented.toggle() - - if previousProvider == settings.preferredBooru { - manager.performSearch() - } - }) { - GenericItemView( - item: query, - removeAction: settings.removeSearchHistoryEntry - ) - } - #if os(macOS) - .buttonStyle(.plain) - #endif - } - .onDelete(perform: settings.removeSearchHistoryEntry) - } - } - } - } - .navigationTitle("Search History") - .searchable(text: $searchText) - .toolbar { - ToolbarItem { - Button(action: { - isShowingRemoveAllConfirmation = true - }) { - Label("Remove All Search History", systemImage: "trash") - } - } - } - .confirmationDialog( - "Are you sure you want to remove all searches? This action cannot be undone.", - isPresented: $isShowingRemoveAllConfirmation - ) { - Button("Remove All Searches") { - settings.bookmarks.removeAll() - } - } + GenericListView( + selectedTab: $selectedTab, + isPresented: $isPresented, + title: "Search History", + emptyMessage: "No History", + emptyIcon: "magnifyingglass", + emptyDescription: "Recent searches will appear here.", + removeAllMessage: + "Are you sure you want to remove all searches? This action cannot be undone.", + removeAllButtonText: "Remove All Searches", + items: settings.searchHistory, + removeAction: settings.removeSearchHistoryEntry, + removeActionUUID: settings.removeSearchHistoryEntry + ) { settings.searchHistory.removeAll() } } } |