mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +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()
|
||||
|
@@ -56,7 +56,7 @@ struct FavoriteItemView: View {
|
||||
}
|
||||
|
||||
func loadCacheAndResource(force: Bool = false) {
|
||||
guard var resource else { return }
|
||||
guard let resource else { return }
|
||||
|
||||
var onSuccess: (Entity<Any>) -> Void = { _ in }
|
||||
var contentItems = [ContentItem]()
|
||||
|
@@ -92,7 +92,16 @@ struct HomeView: View {
|
||||
if homeRecentDocumentsItems > 0 {
|
||||
VStack {
|
||||
HStack {
|
||||
sectionLabel("Recent Documents")
|
||||
NavigationLink(destination: DocumentsView()) {
|
||||
HStack {
|
||||
Text("Documents")
|
||||
.font(.title3.bold())
|
||||
Image(systemName: "chevron.right")
|
||||
.imageScale(.small)
|
||||
}
|
||||
.lineLimit(1)
|
||||
}
|
||||
.padding(.leading, 15)
|
||||
|
||||
Spacer()
|
||||
|
||||
|
@@ -33,17 +33,6 @@ struct PlayerQueueRow: View {
|
||||
return
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
guard !video.localStreamIsDirectory else {
|
||||
if let url = video.localStream?.localURL {
|
||||
withAnimation {
|
||||
DocumentsModel.shared.goToURL(url)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
#endif
|
||||
|
||||
if video.localStreamIsFile, let url = video.localStream?.localURL {
|
||||
URLBookmarkModel.shared.saveBookmark(url)
|
||||
}
|
||||
|
Reference in New Issue
Block a user