import SwiftUI import FlixyDesign import MediaKit /// Die Detailseite eines Titels. /// /// Holt die Metadaten frisch, statt den Eintrag aus der Liste weiterzureichen: /// Einträge in Reihen und Rastern kommen ohne Dateiliste, ohne Besetzung und /// ohne Marker. Für das Abspielen braucht es aber genau diese Angaben. struct MediaDetailView: View { let route: MediaRoute @Environment(FlixySession.self) private var session @State private var state: LoadState = .loading var body: some View { Group { switch state { case .loading: ProgressView().frame(maxWidth: .infinity, maxHeight: .infinity) case .failed(let message): ContentUnavailableView { Label("error.title", systemImage: "exclamationmark.triangle") } description: { Text(message) } actions: { Button("action.retry") { Task { await load() } } } case .loaded(let item): switch item.kind { case .show, .season: SeriesDetailView(item: item) default: PlayableDetailView(item: item) } } } .background(Color.flixyCanvas) .navigationTitle(state.value?.title ?? route.title) .flixyInlineTitle() .toolbar { if let item = state.value { ToolbarItem(placement: .flixyTrailing) { ItemActionsMenu(item: item) { await load() } } } } .task(id: route.ratingKey) { await load() } } private func load() async { guard let server = session.backend else { return } state = await LoadState.load { try await server.item(id: route.ratingKey) } } }