Implement library searching

This commit is contained in:
Shav Kinderlehrer 2023-12-25 00:41:45 -05:00
parent 69bed77458
commit 8e73b094ba
4 changed files with 59 additions and 8 deletions

View File

@ -114,5 +114,16 @@ extension JellyfinClientController {
self.setToken(token: self.authState.authToken ?? "") 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
}
} }

View File

@ -15,6 +15,7 @@ struct DashboardLibraryView: View {
@State var libraries: [BaseItemDto] = [] @State var libraries: [BaseItemDto] = []
@State var loading: Bool = true @State var loading: Bool = true
var body: some View { var body: some View {
if loading { if loading {
ProgressView() ProgressView()

View File

@ -54,7 +54,7 @@ struct ItemMovieView: View {
.toolbarRole(.editor) .toolbarRole(.editor)
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)
.navigationTitle(navigationTitle) .navigationTitle(navigationTitle)
.ignoresSafeArea(edges: .bottom) .ignoresSafeArea()
.scrollIndicators(.hidden) .scrollIndicators(.hidden)
.onAppear { .onAppear {
Task { Task {

View File

@ -13,10 +13,15 @@ struct LibraryDetailView: View {
@StateObject var authState: AuthStateController = AuthStateController.shared @StateObject var authState: AuthStateController = AuthStateController.shared
@State var library: BaseItemDto @State var library: BaseItemDto
@State var items: [BaseItemDto]? = [] @State var items: [BaseItemDto]? = []
@State var loading: Bool = true @State var loading: Bool = true
@State var searchText: String = ""
@State var searchResultHints: SearchHintResult?
@State var searchResultItems: [BaseItemDto]?
let columns = [ let columns = [
GridItem(.adaptive(minimum: 150)) GridItem(.adaptive(minimum: 150))
] ]
@ -24,17 +29,51 @@ struct LibraryDetailView: View {
if loading { if loading {
ProgressView() ProgressView()
.progressViewStyle(.circular) .progressViewStyle(.circular)
} else {
EmptyView()
} }
ScrollView { ScrollView {
LazyVGrid(columns: columns) { LazyVGrid(columns: columns) {
ForEach(items ?? []) {item in if !searchText.isEmpty {
NavigationLink { ForEach(searchResultItems ?? []) {item in
ItemView(item: item) NavigationLink {
} label: { ItemView(item: item)
LibraryIconView(library: item, imageType: "Primary", width: 170) } label: {
.padding() LibraryIconView(library: item, imageType: "Primary", width: 170)
.padding()
}
.buttonStyle(PlainButtonStyle())
} }
.buttonStyle(PlainButtonStyle()) } else {
ForEach(items ?? []) {item in
NavigationLink {
ItemView(item: item)
} label: {
LibraryIconView(library: item, imageType: "Primary", width: 170)
.padding()
}
.buttonStyle(PlainButtonStyle())
}
}
}
}
.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
} }
} }
} }