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

74 lines
2.2 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 {
2022-12-11 03:07:14 +05:30
ScrollView(.vertical, showsIndicators: false) {
if model.directoryContents.isEmpty {
NoDocumentsView()
} else {
ForEach(model.sortedDirectoryContents, id: \.absoluteString) { url in
let video = Video.local(model.standardizedURL(url) ?? url)
PlayerQueueRow(
item: PlayerQueueItem(video)
)
.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)
}
.onAppear {
if model.directoryURL.isNil {
model.goToTop()
2022-11-13 04:31:04 +05:30
}
2022-12-11 03:07:14 +05:30
}
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
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-12-11 03:07:14 +05:30
.transaction { t in t.animation = .none }
.disabled(!model.canGoBack)
2022-11-13 04:31:04 +05:30
}
}
2022-12-11 03:07:14 +05:30
}
.navigationTitle(model.directoryLabel)
.padding(.horizontal)
.navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode)
.backport
.refreshable {
DispatchQueue.main.async {
self.refresh()
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)
}
}