summaryrefslogtreecommitdiff
path: root/Jel/Views/Item/Series/ItemSeriesSelectableEpisodesView.swift
diff options
context:
space:
mode:
Diffstat (limited to 'Jel/Views/Item/Series/ItemSeriesSelectableEpisodesView.swift')
-rw-r--r--Jel/Views/Item/Series/ItemSeriesSelectableEpisodesView.swift84
1 files changed, 84 insertions, 0 deletions
diff --git a/Jel/Views/Item/Series/ItemSeriesSelectableEpisodesView.swift b/Jel/Views/Item/Series/ItemSeriesSelectableEpisodesView.swift
new file mode 100644
index 0000000..30cb97d
--- /dev/null
+++ b/Jel/Views/Item/Series/ItemSeriesSelectableEpisodesView.swift
@@ -0,0 +1,84 @@
+//
+// ItemSeriesSelectableEpisodesView.swift
+// Jel
+//
+// Created by zerocool on 2/24/24.
+//
+
+import SwiftUI
+import JellyfinKit
+
+struct Season: Identifiable, Hashable {
+ var name: String
+ var id: String
+ var season: BaseItemDto
+}
+
+extension Season {
+ static let emptySelection = Season(name: "", id: "", season: BaseItemDto())
+}
+
+struct ItemSeriesSelectableEpisodesView: View {
+ @EnvironmentObject var jellyfinClient: JellyfinClientController
+ @StateObject var authState: AuthStateController = AuthStateController.shared
+
+ var item: BaseItemDto // series
+
+ @State var seasons: [Season] = []
+ @State var currentSeason: Season = .emptySelection
+ @State var currentSeasonCopy: Season = .emptySelection
+
+ @State var loading: Bool = true
+ var body: some View {
+ VStack(alignment: .leading) {
+ HStack {
+ Text("Episodes")
+ .font(.title2)
+ .padding(.horizontal)
+
+ Picker("Season", selection: $currentSeason) {
+ ForEach(seasons, id: \.self) {season in
+ Text(season.name).tag(season)
+ }
+ }
+ }
+
+ ItemSeriesEpisodesView(item: currentSeasonCopy.season)
+ .padding(.horizontal)
+ }
+ .if(loading) {view in
+ view.redacted(reason: .placeholder)
+ }
+ .onChange(of: currentSeason) {
+ currentSeasonCopy = currentSeason
+ }
+ .onAppear {
+ Task {
+ let parameters = Paths.GetItemsParameters(
+ userID: authState.userId ?? "",
+ parentID: item.id ?? ""
+ )
+ let req = Paths.getItems(parameters: parameters)
+
+ do {
+ let res = try await jellyfinClient.send(req)
+ seasons = []
+ for season in res.value.items ?? [] {
+ let newSeason = Season(
+ name: season.name ?? "---",
+ id: season.id ?? "",
+ season: season
+ )
+ seasons.append(newSeason)
+ currentSeason = seasons.first ?? .emptySelection
+ loading = false
+ }
+ } catch {}
+ }
+ }
+ }
+}
+
+//#Preview {
+// ItemSeriesSelectableEpisodesView()
+//}