summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Localizable.xcstrings6
-rw-r--r--Sora/Views/Generic/GenericListView.swift38
2 files changed, 34 insertions, 10 deletions
diff --git a/Localizable.xcstrings b/Localizable.xcstrings
index 9adcf67..fc4854c 100644
--- a/Localizable.xcstrings
+++ b/Localizable.xcstrings
@@ -22,6 +22,9 @@
"Add to Search" : {
},
+ "All" : {
+
+ },
"Are you sure you want to remove all bookmarks? This action cannot be undone." : {
},
@@ -69,6 +72,9 @@
"Clear History" : {
},
+ "Collection" : {
+
+ },
"Collection Name" : {
},
diff --git a/Sora/Views/Generic/GenericListView.swift b/Sora/Views/Generic/GenericListView.swift
index 93b141b..fe8cf0e 100644
--- a/Sora/Views/Generic/GenericListView.swift
+++ b/Sora/Views/Generic/GenericListView.swift
@@ -11,6 +11,7 @@ struct GenericListView<T: Identifiable & Hashable & GenericItem>: View {
@State private var newCollectionName = ""
@State private var itemPendingCollectionAssignment: UUID?
@State private var isCollectionErrorAlertPresented = false
+ @State private var selectedFolder: SettingsFolder?
let allowBookmarking: Bool
let title: String
let emptyMessage: String
@@ -23,15 +24,16 @@ struct GenericListView<T: Identifiable & Hashable & GenericItem>: View {
let removeActionUUID: (UUID) -> Void
let removeAllAction: () -> Void
var filteredItems: [T] {
- guard !searchText.isEmpty else {
- return items
- }
-
- return items.filter { item in
- item.tags
- .joined(separator: " ")
- .lowercased()
- .contains(searchText.lowercased())
+ items.filter { item in
+ let matchesFolder = selectedFolder == nil || item.folder?.id == selectedFolder?.id
+ let matchesSearch =
+ searchText.isEmpty
+ || item.tags
+ .joined(separator: " ")
+ .lowercased()
+ .contains(searchText.lowercased())
+
+ return matchesFolder && matchesSearch
}
}
@@ -45,8 +47,24 @@ struct GenericListView<T: Identifiable & Hashable & GenericItem>: View {
description: Text(emptyDescription)
)
} else {
+ if !settings.folders.isEmpty {
+ Picker("Collection", selection: $selectedFolder) {
+ Text("All").tag(nil as SettingsFolder?)
+
+ ForEach(settings.folders, id: \.id) { folder in
+ Text(folder.name).tag(folder)
+ }
+ }
+ .pickerStyle(.menu)
+ #if os(macOS)
+ .padding()
+ #else
+ .padding(.horizontal)
+ #endif
+ }
+
List {
- if filteredItems.isEmpty, !searchText.isEmpty {
+ if filteredItems.isEmpty && (!searchText.isEmpty || !(selectedFolder == nil)) {
Text("No matching items found")
}