yattee/Shared/Documents/DocumentsView.swift

71 lines
2.1 KiB
Swift
Raw Normal View History

2022-11-12 23:01:04 +00:00
import SwiftUI
struct DocumentsView: View {
2022-12-17 15:18:14 +00:00
var directoryURL: URL?
2022-11-12 23:01:04 +00:00
@ObservedObject private var model = DocumentsModel.shared
var body: some View {
2022-12-10 21:37:14 +00:00
ScrollView(.vertical, showsIndicators: false) {
2022-12-17 15:18:14 +00:00
if let url, model.directoryContents(url).isEmpty {
2022-12-10 21:37:14 +00:00
NoDocumentsView()
2022-12-17 15:18:14 +00:00
} else if let url {
ForEach(model.sortedDirectoryContents(url), id: \.absoluteString) { url in
let standardizedURL = model.standardizedURL(url) ?? url
let video = Video.local(standardizedURL)
Group {
if model.isDirectory(standardizedURL) {
2023-04-22 13:08:33 +00:00
NavigationLink(destination: Self(directoryURL: url)) {
2022-12-17 15:18:14 +00:00
VideoBanner(video: video)
}
} else {
PlayerQueueRow(item: PlayerQueueItem(video))
}
}
2022-12-10 21:37:14 +00:00
.contextMenu {
VideoContextMenuView(video: video)
2022-11-12 23:01:04 +00:00
}
}
2022-12-10 21:37:14 +00:00
.id(model.refreshID)
.transition(.opacity)
2022-11-12 23:01:04 +00:00
}
2022-12-10 21:37:14 +00:00
Color.clear.padding(.bottom, 50)
}
2022-12-17 15:18:14 +00:00
.navigationTitle(directoryLabel)
2022-12-10 21:37:14 +00:00
.padding(.horizontal)
.navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode)
.backport
2022-12-10 21:37:14 +00:00
.refreshable {
DispatchQueue.main.async {
self.refresh()
2022-11-12 23:01:04 +00:00
}
}
}
2022-12-17 15:18:14 +00:00
var url: URL? {
directoryURL ?? model.documentsDirectory
}
var directoryLabel: String {
guard let directoryURL else { return "Documents" }
return model.displayLabelForDocument(directoryURL)
}
2022-11-12 23:01:04 +00:00
func refresh() {
withAnimation {
model.refresh()
}
}
}
struct DocumentsView_Previews: PreviewProvider {
static var previews: some View {
NavigationView {
DocumentsView()
}
.injectFixtureEnvironmentObjects()
.navigationViewStyle(.stack)
}
}