76 lines
2.1 KiB
Swift
76 lines
2.1 KiB
Swift
import Adwaita
|
|
import LuminateCore
|
|
|
|
public struct ItemGrid: View {
|
|
|
|
var client: JellyfinClient
|
|
var userId: String
|
|
var parentId: String?
|
|
var includeItemTypes: [Components.Schemas.BaseItemKind]?
|
|
var title: String?
|
|
@State private var items: [Components.Schemas.BaseItemDto] = []
|
|
@State private var isLoading = false
|
|
private let pageSize: Int32 = 50
|
|
|
|
public init(
|
|
client: JellyfinClient,
|
|
userId: String,
|
|
parentId: String? = nil,
|
|
includeItemTypes: [Components.Schemas.BaseItemKind]? = nil,
|
|
title: String? = nil
|
|
) {
|
|
self.client = client
|
|
self.userId = userId
|
|
self.parentId = parentId
|
|
self.includeItemTypes = includeItemTypes
|
|
self.title = title
|
|
}
|
|
|
|
public var view: Body {
|
|
VStack {
|
|
if let title {
|
|
Text(title)
|
|
.title2()
|
|
.halign(.start)
|
|
.padding()
|
|
}
|
|
if isLoading {
|
|
Spinner()
|
|
} else {
|
|
ScrollView {
|
|
FlowBox(items) { item in
|
|
PosterCell(item: item, client: client)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.onAppear {
|
|
loadItems()
|
|
}
|
|
}
|
|
|
|
private func loadItems() {
|
|
isLoading = true
|
|
Task {
|
|
do {
|
|
let result = try await client.getItems(
|
|
userId: userId,
|
|
parentId: parentId,
|
|
includeItemTypes: includeItemTypes,
|
|
fields: [.overview, .genres, .people, .mediaSources],
|
|
sortBy: [.sortName],
|
|
sortOrder: [.ascending],
|
|
startIndex: 0,
|
|
limit: pageSize,
|
|
recursive: true
|
|
)
|
|
await MainActor.run {
|
|
items = result.items ?? []
|
|
isLoading = false
|
|
}
|
|
} catch {
|
|
await MainActor.run { isLoading = false }
|
|
}
|
|
}
|
|
}
|
|
}
|