summaryrefslogtreecommitdiff
path: root/Jel/Views/Item/Series/ItemSeriesSelectableEpisodesView.swift
diff options
context:
space:
mode:
authorShav Kinderlehrer <[email protected]>2024-02-27 14:22:42 -0500
committerShav Kinderlehrer <[email protected]>2024-02-27 14:22:42 -0500
commitaaf02071642a59ae375906bd9b9bcff1e8c33e92 (patch)
tree9084cdf9cab4054a6e3108b2f3db50a9343bd874 /Jel/Views/Item/Series/ItemSeriesSelectableEpisodesView.swift
parentbe11eed89ded59949a790aa09f20908779155443 (diff)
downloadjel-main.tar.gz
jel-main.zip
Implement ItemSeriesSelectableEpisodesViewHEADmain
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()
+//}