2023-12-23 19:15:01 +00:00
|
|
|
//
|
2023-12-27 13:25:35 +00:00
|
|
|
// ItemMediaView.swift
|
2023-12-23 19:15:01 +00:00
|
|
|
// Jel
|
|
|
|
//
|
|
|
|
// Created by zerocool on 12/23/23.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
import JellyfinKit
|
|
|
|
|
2023-12-27 13:25:35 +00:00
|
|
|
struct ItemMediaView: View {
|
2023-12-23 19:15:01 +00:00
|
|
|
@EnvironmentObject var jellyfinClient: JellyfinClientController
|
|
|
|
@StateObject var authState: AuthStateController = AuthStateController.shared
|
|
|
|
|
|
|
|
@State var item: BaseItemDto
|
|
|
|
@State var loading: Bool = true
|
2023-12-24 04:47:21 +00:00
|
|
|
|
2023-12-24 07:36:14 +00:00
|
|
|
@State var navigationTitle: String = ""
|
|
|
|
|
2023-12-23 19:15:01 +00:00
|
|
|
var body: some View {
|
2023-12-27 18:37:21 +00:00
|
|
|
GeometryReader {geo in
|
2023-12-25 01:01:52 +00:00
|
|
|
if loading {
|
|
|
|
ProgressView()
|
|
|
|
.progressViewStyle(.circular)
|
|
|
|
} else {
|
|
|
|
ScrollView {
|
|
|
|
ItemHeaderView(item: item)
|
|
|
|
.padding(.bottom)
|
|
|
|
.background {
|
|
|
|
GeometryReader {geo in
|
|
|
|
EmptyView()
|
|
|
|
.onChange(of: geo.frame(in: .global).minY) {
|
|
|
|
let minY = geo.frame(in: .global).minY
|
|
|
|
if minY < 0 {
|
|
|
|
navigationTitle = item.name ?? ""
|
|
|
|
} else {
|
|
|
|
navigationTitle = ""
|
|
|
|
}
|
|
|
|
}
|
2023-12-24 07:36:14 +00:00
|
|
|
}
|
2023-12-25 01:01:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
Text(item.taglines?.count ?? 0 > 0 ? item.taglines?[0] ?? "" : "")
|
|
|
|
.font(.headline)
|
|
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
2023-12-25 06:02:38 +00:00
|
|
|
.padding(.bottom)
|
2023-12-25 01:01:52 +00:00
|
|
|
|
2023-12-27 18:07:20 +00:00
|
|
|
ForEach(item.overview?.components(separatedBy: "<br>") ?? [], id: \.self) {overview in
|
|
|
|
Text(overview)
|
|
|
|
}
|
2023-12-24 07:36:14 +00:00
|
|
|
}
|
2023-12-27 18:37:21 +00:00
|
|
|
.if(max(geo.safeAreaInsets.leading, geo.safeAreaInsets.trailing) > 0) {view in
|
|
|
|
view
|
|
|
|
.padding(max(geo.safeAreaInsets.leading, geo.safeAreaInsets.trailing))
|
|
|
|
}
|
|
|
|
.if(max(geo.safeAreaInsets.leading, geo.safeAreaInsets.trailing) <= 0) {view in
|
|
|
|
view
|
|
|
|
.padding()
|
|
|
|
}
|
2023-12-25 01:01:52 +00:00
|
|
|
}
|
2023-12-27 18:37:21 +00:00
|
|
|
.ignoresSafeArea()
|
2023-12-24 07:36:14 +00:00
|
|
|
}
|
2023-12-23 19:15:01 +00:00
|
|
|
}
|
2023-12-24 04:47:21 +00:00
|
|
|
.toolbarRole(.editor)
|
2023-12-23 19:15:01 +00:00
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
2023-12-25 01:01:52 +00:00
|
|
|
.navigationTitle(navigationTitle)
|
|
|
|
.scrollIndicators(.hidden)
|
2023-12-23 19:15:01 +00:00
|
|
|
.onAppear {
|
|
|
|
Task {
|
|
|
|
do {
|
|
|
|
let request = Paths.getItem(userID: authState.userId ?? "", itemID: item.id ?? "")
|
2023-12-25 01:01:52 +00:00
|
|
|
let response = try await jellyfinClient.send(request)
|
|
|
|
item = response.value
|
2023-12-23 19:15:01 +00:00
|
|
|
loading = false
|
|
|
|
} catch {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-25 01:01:52 +00:00
|
|
|
//#Preview {
|
|
|
|
// ItemMovieView(item: BaseItemDto())
|
|
|
|
//}
|