1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-14 06:10:32 +05:30
yattee/Shared/Documents/DocumentsView.swift

71 lines
2.1 KiB
Swift
Raw Normal View History

2022-11-13 04:31:04 +05:30
import SwiftUI
struct DocumentsView: View {
2022-12-17 20:48:14 +05:30
var directoryURL: URL?
2022-11-13 04:31:04 +05:30
@ObservedObject private var model = DocumentsModel.shared
var body: some View {
2022-12-11 03:07:14 +05:30
ScrollView(.vertical, showsIndicators: false) {
2022-12-17 20:48:14 +05:30
if let url, model.directoryContents(url).isEmpty {
2022-12-11 03:07:14 +05:30
NoDocumentsView()
2022-12-17 20:48:14 +05:30
} 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 18:38:33 +05:30
NavigationLink(destination: Self(directoryURL: url)) {
2022-12-17 20:48:14 +05:30
VideoBanner(video: video)
}
} else {
PlayerQueueRow(item: PlayerQueueItem(video))
}
}
2022-12-11 03:07:14 +05:30
.contextMenu {
VideoContextMenuView(video: video)
2022-11-13 04:31:04 +05:30
}
}
2022-12-11 03:07:14 +05:30
.id(model.refreshID)
.transition(.opacity)
2022-11-13 04:31:04 +05:30
}
2022-12-11 03:07:14 +05:30
Color.clear.padding(.bottom, 50)
}
2022-12-17 20:48:14 +05:30
.navigationTitle(directoryLabel)
2022-12-11 03:07:14 +05:30
.padding(.horizontal)
.navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode)
.backport
2022-12-11 03:07:14 +05:30
.refreshable {
DispatchQueue.main.async {
self.refresh()
2022-11-13 04:31:04 +05:30
}
}
}
2022-12-17 20:48:14 +05:30
var url: URL? {
directoryURL ?? model.documentsDirectory
}
var directoryLabel: String {
guard let directoryURL else { return "Documents" }
return model.displayLabelForDocument(directoryURL)
}
2022-11-13 04:31:04 +05:30
func refresh() {
withAnimation {
model.refresh()
}
}
}
struct DocumentsView_Previews: PreviewProvider {
static var previews: some View {
NavigationView {
DocumentsView()
}
.injectFixtureEnvironmentObjects()
.navigationViewStyle(.stack)
}
}