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)
|
2023-07-01 16:38:11 +00:00
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
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)
|
|
|
|
}
|
|
|
|
}
|