Documents navigation

This commit is contained in:
Arkadiusz Fal
2022-12-17 16:18:14 +01:00
parent cf0572a94b
commit 8e5bafba58
5 changed files with 43 additions and 80 deletions

View File

@@ -1,18 +1,28 @@
import SwiftUI
struct DocumentsView: View {
var directoryURL: URL?
@ObservedObject private var model = DocumentsModel.shared
var body: some View {
ScrollView(.vertical, showsIndicators: false) {
if model.directoryContents.isEmpty {
if let url, model.directoryContents(url).isEmpty {
NoDocumentsView()
} else {
ForEach(model.sortedDirectoryContents, id: \.absoluteString) { url in
let video = Video.local(model.standardizedURL(url) ?? url)
PlayerQueueRow(
item: PlayerQueueItem(video)
)
} 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) {
NavigationLink(destination: DocumentsView(directoryURL: url)) {
VideoBanner(video: video)
}
} else {
PlayerQueueRow(item: PlayerQueueItem(video))
}
}
.contextMenu {
VideoContextMenuView(video: video)
}
@@ -22,29 +32,7 @@ struct DocumentsView: View {
}
Color.clear.padding(.bottom, 50)
}
.onAppear {
if model.directoryURL.isNil {
model.goToTop()
}
}
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
if model.canGoBack {
Button {
withAnimation {
model.goBack()
}
} label: {
HStack(spacing: 6) {
Label("Go back", systemImage: "chevron.left")
}
}
.transaction { t in t.animation = .none }
.disabled(!model.canGoBack)
}
}
}
.navigationTitle(model.directoryLabel)
.navigationTitle(directoryLabel)
.padding(.horizontal)
.navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode)
.backport
@@ -55,6 +43,15 @@ struct DocumentsView: View {
}
}
var url: URL? {
directoryURL ?? model.documentsDirectory
}
var directoryLabel: String {
guard let directoryURL else { return "Documents" }
return model.displayLabelForDocument(directoryURL)
}
func refresh() {
withAnimation {
model.refresh()