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

76 lines
2.4 KiB
Swift
Raw Normal View History

2022-11-13 04:31:04 +05:30
import SwiftUI
struct DocumentsView: View {
@ObservedObject private var model = DocumentsModel.shared
var body: some View {
BrowserPlayerControls {
ScrollView(.vertical, showsIndicators: false) {
if model.directoryContents.isEmpty {
2022-11-19 04:09:52 +05:30
NoDocumentsView()
2022-11-13 04:31:04 +05:30
} else {
ForEach(model.sortedDirectoryContents, id: \.absoluteString) { url in
2022-12-04 17:51:50 +05:30
let video = Video.local(model.standardizedURL(url) ?? url)
2022-11-13 04:31:04 +05:30
PlayerQueueRow(
item: PlayerQueueItem(video)
)
.contextMenu {
VideoContextMenuView(video: video)
}
}
.id(model.refreshID)
.transition(.opacity)
}
Color.clear.padding(.bottom, 50)
}
.onAppear {
if model.directoryURL.isNil {
model.goToTop()
}
}
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
2022-11-13 04:37:23 +05:30
if model.canGoBack {
Button {
withAnimation {
model.goBack()
}
} label: {
HStack(spacing: 6) {
Label("Go back", systemImage: "chevron.left")
}
2022-11-13 04:31:04 +05:30
}
2022-11-13 04:37:23 +05:30
.transaction { t in t.animation = .none }
.disabled(!model.canGoBack)
2022-11-13 04:31:04 +05:30
}
}
}
.navigationTitle(model.directoryLabel)
2022-11-13 04:37:23 +05:30
.padding(.horizontal)
2022-11-13 04:31:04 +05:30
.navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode)
.backport
.refreshable {
DispatchQueue.main.async {
self.refresh()
}
}
}
}
func refresh() {
withAnimation {
model.refresh()
}
}
}
struct DocumentsView_Previews: PreviewProvider {
static var previews: some View {
NavigationView {
DocumentsView()
}
.injectFixtureEnvironmentObjects()
.navigationViewStyle(.stack)
}
}