mirror of
https://github.com/yattee/yattee.git
synced 2025-08-05 02:04:07 +00:00
Documents navigation
This commit is contained in:
@@ -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()
|
||||
|
Reference in New Issue
Block a user