Implement library searching
This commit is contained in:
parent
69bed77458
commit
8e73b094ba
@ -114,5 +114,16 @@ extension JellyfinClientController {
|
||||
self.setToken(token: self.authState.authToken ?? "")
|
||||
}
|
||||
}
|
||||
|
||||
func search(parameters: Paths.GetParameters) async -> SearchHintResult? {
|
||||
let request = Paths.get(parameters: parameters)
|
||||
do {
|
||||
let res = try await self.api.send(request)
|
||||
return res.value
|
||||
} catch {
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ struct DashboardLibraryView: View {
|
||||
|
||||
@State var libraries: [BaseItemDto] = []
|
||||
@State var loading: Bool = true
|
||||
|
||||
var body: some View {
|
||||
if loading {
|
||||
ProgressView()
|
||||
|
@ -54,7 +54,7 @@ struct ItemMovieView: View {
|
||||
.toolbarRole(.editor)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationTitle(navigationTitle)
|
||||
.ignoresSafeArea(edges: .bottom)
|
||||
.ignoresSafeArea()
|
||||
.scrollIndicators(.hidden)
|
||||
.onAppear {
|
||||
Task {
|
||||
|
@ -13,10 +13,15 @@ struct LibraryDetailView: View {
|
||||
@StateObject var authState: AuthStateController = AuthStateController.shared
|
||||
|
||||
@State var library: BaseItemDto
|
||||
|
||||
@State var items: [BaseItemDto]? = []
|
||||
|
||||
@State var loading: Bool = true
|
||||
|
||||
|
||||
@State var searchText: String = ""
|
||||
@State var searchResultHints: SearchHintResult?
|
||||
@State var searchResultItems: [BaseItemDto]?
|
||||
let columns = [
|
||||
GridItem(.adaptive(minimum: 150))
|
||||
]
|
||||
@ -24,9 +29,22 @@ struct LibraryDetailView: View {
|
||||
if loading {
|
||||
ProgressView()
|
||||
.progressViewStyle(.circular)
|
||||
} else {
|
||||
EmptyView()
|
||||
}
|
||||
ScrollView {
|
||||
LazyVGrid(columns: columns) {
|
||||
if !searchText.isEmpty {
|
||||
ForEach(searchResultItems ?? []) {item in
|
||||
NavigationLink {
|
||||
ItemView(item: item)
|
||||
} label: {
|
||||
LibraryIconView(library: item, imageType: "Primary", width: 170)
|
||||
.padding()
|
||||
}
|
||||
.buttonStyle(PlainButtonStyle())
|
||||
}
|
||||
} else {
|
||||
ForEach(items ?? []) {item in
|
||||
NavigationLink {
|
||||
ItemView(item: item)
|
||||
@ -38,6 +56,27 @@ struct LibraryDetailView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.searchable(text: $searchText)
|
||||
.onChange(of: searchText) {
|
||||
Task {
|
||||
let parameters = Paths.GetParameters(
|
||||
userID: AuthStateController.shared.userId,
|
||||
searchTerm: searchText.lowercased(),
|
||||
parentID: library.id
|
||||
)
|
||||
searchResultHints = await jellyfinClient.search(parameters: parameters)
|
||||
|
||||
searchResultItems = items?.filter { item in
|
||||
for hint in searchResultHints?.searchHints ?? [] {
|
||||
if hint.name == item.name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationTitle(library.name ?? "Unknown")
|
||||
.onAppear {
|
||||
Task {
|
||||
|
Loading…
Reference in New Issue
Block a user