Consolidate ItemPage and rename LibraryGrid to ItemGrid
This commit is contained in:
parent
b52ea45d69
commit
2a50394264
6 changed files with 70 additions and 183 deletions
|
|
@ -131,12 +131,11 @@ struct ContentView: View {
|
||||||
}
|
}
|
||||||
.navigationTitle(title)
|
.navigationTitle(title)
|
||||||
case .collectionPage(let item):
|
case .collectionPage(let item):
|
||||||
let title = item.name ?? "Library"
|
ItemPage(item: item, navigation: $stack)
|
||||||
CollectionView(item: item, navigation: $stack)
|
|
||||||
.topToolbar {
|
.topToolbar {
|
||||||
ToolbarView()
|
ToolbarView()
|
||||||
}
|
}
|
||||||
.navigationTitle(title)
|
.navigationTitle(item.name ?? "Library")
|
||||||
}
|
}
|
||||||
} initialView: {
|
} initialView: {
|
||||||
HomeView(navigation: $stack)
|
HomeView(navigation: $stack)
|
||||||
|
|
|
||||||
|
|
@ -1,56 +0,0 @@
|
||||||
//
|
|
||||||
// CollectionView.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
|
|
||||||
import LuminateUI
|
|
||||||
|
|
||||||
public struct CollectionView: View {
|
|
||||||
|
|
||||||
nonisolated public init(
|
|
||||||
item: Components.Schemas.BaseItemDto,
|
|
||||||
navigation: Binding<NavigationStack<Page>>
|
|
||||||
) {
|
|
||||||
self.item = item
|
|
||||||
_navigation = navigation
|
|
||||||
}
|
|
||||||
|
|
||||||
private var item: Components.Schemas.BaseItemDto
|
|
||||||
@Binding var navigation: NavigationStack<Page>
|
|
||||||
|
|
||||||
public var view: Body {
|
|
||||||
ScrollView {
|
|
||||||
Clamp()
|
|
||||||
.maximumSize(1550)
|
|
||||||
.tighteningThreshold(550)
|
|
||||||
.child {
|
|
||||||
ItemGrid(
|
|
||||||
parentId: item.id,
|
|
||||||
title: item.name,
|
|
||||||
navigation: $navigation
|
|
||||||
)
|
|
||||||
.padding(32, .vertical)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.hscrollbarPolicy(.never)
|
|
||||||
.propagateNaturalHeight()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -91,8 +91,8 @@ public struct HomeView: View {
|
||||||
)
|
)
|
||||||
.padding(32, .bottom)
|
.padding(32, .bottom)
|
||||||
}
|
}
|
||||||
LibraryGrid(
|
ItemGrid(
|
||||||
libraries: libraries,
|
items: libraries,
|
||||||
navigation: $navigation
|
navigation: $navigation
|
||||||
)
|
)
|
||||||
.padding(32, .bottom)
|
.padding(32, .bottom)
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
import Adwaita
|
import Adwaita
|
||||||
import LuminateCore
|
import LuminateCore
|
||||||
|
import LuminateDI
|
||||||
import LuminateUI
|
import LuminateUI
|
||||||
|
|
||||||
public struct ItemPage: View {
|
public struct ItemPage: View {
|
||||||
|
|
@ -33,13 +34,28 @@ public struct ItemPage: View {
|
||||||
navigation: Binding<NavigationStack<Page>>
|
navigation: Binding<NavigationStack<Page>>
|
||||||
) {
|
) {
|
||||||
self.title = title
|
self.title = title
|
||||||
self.items = items
|
self._items = .init(wrappedValue: items)
|
||||||
|
self.parentId = nil
|
||||||
_navigation = navigation
|
_navigation = navigation
|
||||||
}
|
}
|
||||||
|
|
||||||
private var items: [Components.Schemas.BaseItemDto]
|
nonisolated public init(
|
||||||
private var title: String
|
item: Components.Schemas.BaseItemDto,
|
||||||
|
navigation: Binding<NavigationStack<Page>>
|
||||||
|
) {
|
||||||
|
self.title = item.name
|
||||||
|
self.parentId = item.id
|
||||||
|
_isLoading = .init(wrappedValue: item.id != nil)
|
||||||
|
_navigation = navigation
|
||||||
|
}
|
||||||
|
|
||||||
|
private var title: String?
|
||||||
|
private var parentId: String?
|
||||||
@Binding var navigation: NavigationStack<Page>
|
@Binding var navigation: NavigationStack<Page>
|
||||||
|
@State private var items: [Components.Schemas.BaseItemDto] = []
|
||||||
|
@State private var isLoading = false
|
||||||
|
@Injected(\.client) var client
|
||||||
|
@Injected(\.userId) var userId
|
||||||
|
|
||||||
public var view: Body {
|
public var view: Body {
|
||||||
ScrollView {
|
ScrollView {
|
||||||
|
|
@ -47,15 +63,36 @@ public struct ItemPage: View {
|
||||||
.maximumSize(1550)
|
.maximumSize(1550)
|
||||||
.tighteningThreshold(550)
|
.tighteningThreshold(550)
|
||||||
.child {
|
.child {
|
||||||
LibraryGrid(
|
if isLoading, parentId != nil {
|
||||||
libraries: items,
|
Spinner()
|
||||||
navigation: $navigation,
|
} else {
|
||||||
title: title
|
ItemGrid(
|
||||||
)
|
items: items,
|
||||||
.padding(32, .vertical)
|
navigation: $navigation,
|
||||||
|
title: title
|
||||||
|
)
|
||||||
|
.padding(32, .vertical)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.hscrollbarPolicy(.never)
|
.hscrollbarPolicy(.never)
|
||||||
.propagateNaturalHeight()
|
.propagateNaturalHeight()
|
||||||
|
.onAppear {
|
||||||
|
loadIfNeeded()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func loadIfNeeded() {
|
||||||
|
guard let parentId else { return }
|
||||||
|
Task {
|
||||||
|
let result = try? await client.getItems(
|
||||||
|
userId: userId,
|
||||||
|
parentId: parentId,
|
||||||
|
sortBy: [.sortName],
|
||||||
|
sortOrder: [.ascending]
|
||||||
|
)
|
||||||
|
items = result?.items ?? []
|
||||||
|
isLoading = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,74 +20,38 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
import Adwaita
|
import Adwaita
|
||||||
|
import Foundation
|
||||||
import LuminateCore
|
import LuminateCore
|
||||||
import LuminateDI
|
|
||||||
|
|
||||||
public struct ItemGrid: View {
|
public struct ItemGrid: View {
|
||||||
|
|
||||||
var parentId: String?
|
public var items: [Components.Schemas.BaseItemDto]
|
||||||
var includeItemTypes: [Components.Schemas.BaseItemKind]?
|
@Binding public var navigation: NavigationStack<Page>
|
||||||
var title: String?
|
public var title: String?
|
||||||
@Binding var navigation: NavigationStack<Page>
|
|
||||||
@Injected(\.client) var client
|
|
||||||
@Injected(\.userId) var userId
|
|
||||||
@State private var items: [Components.Schemas.BaseItemDto] = []
|
|
||||||
@State private var isLoading = true
|
|
||||||
private let pageSize: Int32 = 50
|
|
||||||
|
|
||||||
public init(
|
public init(
|
||||||
parentId: String? = nil,
|
items: [Components.Schemas.BaseItemDto],
|
||||||
includeItemTypes: [Components.Schemas.BaseItemKind]? = nil,
|
navigation: Binding<NavigationStack<Page>>,
|
||||||
title: String? = nil,
|
title: String? = nil
|
||||||
navigation: Binding<NavigationStack<Page>>
|
|
||||||
) {
|
) {
|
||||||
self.parentId = parentId
|
self.items = items
|
||||||
self.includeItemTypes = includeItemTypes
|
|
||||||
self.title = title
|
|
||||||
_navigation = navigation
|
_navigation = navigation
|
||||||
|
self.title = title
|
||||||
}
|
}
|
||||||
|
|
||||||
public var view: Body {
|
public var view: Body {
|
||||||
VStack {
|
VStack(spacing: 16) {
|
||||||
if let title {
|
Text(title ?? "Libraries")
|
||||||
Text(title)
|
.title3()
|
||||||
.title2()
|
.halign(.start)
|
||||||
.halign(.start)
|
.padding(10, .horizontal)
|
||||||
.padding()
|
FlowGrid(items, id: \.id) { item in
|
||||||
}
|
HomePosterCell(item: item, navigation: $navigation)
|
||||||
if isLoading {
|
|
||||||
Spinner()
|
|
||||||
.transition(.crossfade)
|
|
||||||
} else {
|
|
||||||
FlowGrid(items, id: \.id) { item in
|
|
||||||
HomePosterCell(item: item, navigation: $navigation)
|
|
||||||
}
|
|
||||||
.columnSpacing(16)
|
|
||||||
.rowSpacing(16)
|
|
||||||
.minimumSize(216)
|
|
||||||
.halign(.fill)
|
|
||||||
.transition(.crossfade)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.onAppear {
|
|
||||||
loadItems()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private func loadItems() {
|
|
||||||
Task {
|
|
||||||
do {
|
|
||||||
let result = try await client.getItems(
|
|
||||||
userId: userId,
|
|
||||||
parentId: parentId,
|
|
||||||
sortBy: [.sortName],
|
|
||||||
sortOrder: [.ascending]
|
|
||||||
)
|
|
||||||
items = result.items ?? []
|
|
||||||
isLoading = false
|
|
||||||
} catch {
|
|
||||||
isLoading = false
|
|
||||||
}
|
}
|
||||||
|
.columnSpacing(16)
|
||||||
|
.rowSpacing(16)
|
||||||
|
.minimumSize(216)
|
||||||
|
.halign(.fill)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
||||||
//
|
|
||||||
// LibraryGrid.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 Foundation
|
|
||||||
import LuminateCore
|
|
||||||
|
|
||||||
public struct LibraryGrid: View {
|
|
||||||
|
|
||||||
public var libraries: [Components.Schemas.BaseItemDto]
|
|
||||||
@Binding public var navigation: NavigationStack<Page>
|
|
||||||
public var title: String?
|
|
||||||
|
|
||||||
public init(
|
|
||||||
libraries: [Components.Schemas.BaseItemDto],
|
|
||||||
navigation: Binding<NavigationStack<Page>>,
|
|
||||||
title: String? = nil
|
|
||||||
) {
|
|
||||||
self.libraries = libraries
|
|
||||||
_navigation = navigation
|
|
||||||
self.title = title
|
|
||||||
}
|
|
||||||
|
|
||||||
public var view: Body {
|
|
||||||
VStack(spacing: 16) {
|
|
||||||
Text(title ?? "Libraries")
|
|
||||||
.title3()
|
|
||||||
.halign(.start)
|
|
||||||
.padding(10, .horizontal)
|
|
||||||
FlowGrid(libraries, id: \.id) { item in
|
|
||||||
HomePosterCell(item: item, navigation: $navigation)
|
|
||||||
}
|
|
||||||
.columnSpacing(16)
|
|
||||||
.rowSpacing(16)
|
|
||||||
.minimumSize(216)
|
|
||||||
.halign(.fill)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue