97 lines
2.9 KiB
Swift
97 lines
2.9 KiB
Swift
//
|
|
// ItemGrid.swift
|
|
//
|
|
// Copyright 2026 Brendan Szymanski <hello@bscubed.dev>
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
//
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
//
|
|
|
|
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 }
|
|
}
|
|
}
|
|
}
|
|
}
|