mirror of
https://github.com/cranci1/Sora.git
synced 2026-04-19 23:52:09 +00:00
SearchView fixes
This commit is contained in:
parent
8aaa7111bf
commit
0926b5b9d2
3 changed files with 48 additions and 17 deletions
|
|
@ -9,6 +9,7 @@ import Foundation
|
|||
|
||||
class ModuleManager: ObservableObject {
|
||||
@Published var modules: [ScrapingModule] = []
|
||||
@Published var selectedModuleChanged = false
|
||||
|
||||
private let fileManager = FileManager.default
|
||||
private let modulesFileName = "modules.json"
|
||||
|
|
@ -180,6 +181,7 @@ class ModuleManager: ObservableObject {
|
|||
DispatchQueue.main.async {
|
||||
self.modules.append(module)
|
||||
self.saveModules()
|
||||
self.selectedModuleChanged = true
|
||||
Logger.shared.log("Added module: \(module.metadata.sourceName)")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -158,22 +158,43 @@ struct SearchView: View {
|
|||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
Menu {
|
||||
ForEach(getModuleLanguageGroups(), id: \.self) { language in
|
||||
Menu(language) {
|
||||
ForEach(getModulesForLanguage(language), id: \.id) { module in
|
||||
Button {
|
||||
selectedModuleId = module.id.uuidString
|
||||
} label: {
|
||||
HStack {
|
||||
KFImage(URL(string: module.metadata.iconUrl))
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 20, height: 20)
|
||||
.cornerRadius(4)
|
||||
Text(module.metadata.sourceName)
|
||||
if module.id.uuidString == selectedModuleId {
|
||||
Image(systemName: "checkmark")
|
||||
.foregroundColor(.accentColor)
|
||||
if getModuleLanguageGroups().count == 1 {
|
||||
ForEach(moduleManager.modules, id: \.id) { module in
|
||||
Button {
|
||||
selectedModuleId = module.id.uuidString
|
||||
} label: {
|
||||
HStack {
|
||||
KFImage(URL(string: module.metadata.iconUrl))
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 20, height: 20)
|
||||
.cornerRadius(4)
|
||||
Text(module.metadata.sourceName)
|
||||
if module.id.uuidString == selectedModuleId {
|
||||
Image(systemName: "checkmark")
|
||||
.foregroundColor(.accentColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ForEach(getModuleLanguageGroups(), id: \.self) { language in
|
||||
Menu(language) {
|
||||
ForEach(getModulesForLanguage(language), id: \.id) { module in
|
||||
Button {
|
||||
selectedModuleId = module.id.uuidString
|
||||
} label: {
|
||||
HStack {
|
||||
KFImage(URL(string: module.metadata.iconUrl))
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 20, height: 20)
|
||||
.cornerRadius(4)
|
||||
Text(module.metadata.sourceName)
|
||||
if module.id.uuidString == selectedModuleId {
|
||||
Image(systemName: "checkmark")
|
||||
.foregroundColor(.accentColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -205,6 +226,14 @@ struct SearchView: View {
|
|||
performSearch()
|
||||
}
|
||||
}
|
||||
.onChange(of: moduleManager.selectedModuleChanged) { _ in
|
||||
if moduleManager.selectedModuleChanged {
|
||||
if selectedModuleId == nil && !moduleManager.modules.isEmpty {
|
||||
selectedModuleId = moduleManager.modules[0].id.uuidString
|
||||
}
|
||||
moduleManager.selectedModuleChanged = false
|
||||
}
|
||||
}
|
||||
.onChange(of: searchText) { newValue in
|
||||
if newValue.isEmpty {
|
||||
searchItems = []
|
||||
|
|
|
|||
|
|
@ -302,9 +302,9 @@
|
|||
133D7C882D2BE2640075467E /* Modules */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
1EF5C3A82DB988D70032BF07 /* CommunityLib.swift */,
|
||||
13D99CF62D4E73C300250A86 /* ModuleAdditionSettingsView.swift */,
|
||||
139935652D468C450065CEFF /* ModuleManager.swift */,
|
||||
1EF5C3A82DB988D70032BF07 /* CommunityLib.swift */,
|
||||
133D7C892D2BE2640075467E /* Modules.swift */,
|
||||
);
|
||||
path = Modules;
|
||||
|
|
|
|||
Loading…
Reference in a new issue