Ferrite-backup/Ferrite/Views/BatchChoiceView.swift
kingbri 2f870b9410 Ferrite: Add bookmarks
Bookmarks are added through search results and can be accessed through
the library. These can be moved and deleted within the list.

Add a RealDebrid instant availability cache for bookmark IA status
to not overwhelm the API. Instant availability results are fresh on
every search results since the cache is cleared.

Also don't require a source API object to be present for the API parser
button in source settings. If a JSON parser exists for a source, allow
the option to be presented.

Signed-off-by: kingbri <bdashore3@proton.me>
2022-09-16 12:33:18 -04:00

64 lines
2.2 KiB
Swift

//
// BatchChoiceView.swift
// Ferrite
//
// Created by Brian Dashore on 7/24/22.
//
import SwiftUI
struct BatchChoiceView: View {
@Environment(\.presentationMode) var presentationMode
@EnvironmentObject var debridManager: DebridManager
@EnvironmentObject var scrapingModel: ScrapingViewModel
@EnvironmentObject var navModel: NavigationViewModel
var body: some View {
NavView {
List {
ForEach(debridManager.selectedRealDebridItem?.files ?? [], id: \.self) { file in
Button(file.name) {
debridManager.selectedRealDebridFile = file
if let searchResult = navModel.selectedSearchResult {
debridManager.currentDebridTask = Task {
await debridManager.fetchRdDownload(searchResult: searchResult, iaFile: file)
if !debridManager.realDebridDownloadUrl.isEmpty {
// The download may complete before this sheet dismisses
try? await Task.sleep(seconds: 1)
navModel.runDebridAction(action: nil, urlString: debridManager.realDebridDownloadUrl)
}
debridManager.selectedRealDebridFile = nil
debridManager.selectedRealDebridItem = nil
}
}
presentationMode.wrappedValue.dismiss()
}
.dynamicAccentColor(.primary)
}
}
.listStyle(.insetGrouped)
.navigationTitle("Select a file")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button("Done") {
debridManager.selectedRealDebridItem = nil
presentationMode.wrappedValue.dismiss()
}
}
}
}
}
}
struct BatchChoiceView_Previews: PreviewProvider {
static var previews: some View {
BatchChoiceView()
}
}