Filters: Add debrid cache status option
Items can now be filtered based if they're present in the debrid cache, are a batch file, or not present at all. Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
parent
75be076e0b
commit
8123fd8d0c
5 changed files with 36 additions and 6 deletions
|
|
@ -10,10 +10,10 @@ import Foundation
|
|||
|
||||
// MARK: - Universal IA enum (IA = InstantAvailability)
|
||||
|
||||
public enum IAStatus: Codable, Hashable, Sendable {
|
||||
case full
|
||||
case partial
|
||||
case none
|
||||
public enum IAStatus: String, Codable, Hashable, Sendable, CaseIterable {
|
||||
case full = "Cached"
|
||||
case partial = "Batch"
|
||||
case none = "Uncached"
|
||||
}
|
||||
|
||||
// MARK: - Enum for debrid differentiation. 0 is nil
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ public class DebridManager: ObservableObject {
|
|||
}
|
||||
}
|
||||
|
||||
@Published var filteredIAStatus: [IAStatus] = []
|
||||
|
||||
var currentDebridTask: Task<Void, Never>?
|
||||
var downloadUrl: String = ""
|
||||
var authUrl: URL?
|
||||
|
|
|
|||
|
|
@ -45,6 +45,26 @@ struct SearchFilterHeaderView: View {
|
|||
FilterLabelView(name: debridManager.selectedDebridType?.toString() ?? "Debrid")
|
||||
}
|
||||
.id(debridManager.selectedDebridType)
|
||||
|
||||
// MARK: - Cache status picker
|
||||
|
||||
// TODO: Make this use multiple selections
|
||||
if !debridManager.enabledDebrids.isEmpty {
|
||||
Menu {
|
||||
Picker("", selection: $debridManager.filteredIAStatus) {
|
||||
Text("All").tag([] as [IAStatus])
|
||||
|
||||
ForEach(IAStatus.allCases, id: \.self) { status in
|
||||
Text(status.rawValue).tag([status])
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
FilterLabelView(
|
||||
name: debridManager.filteredIAStatus.first?.rawValue ?? "Cache Status"
|
||||
)
|
||||
}
|
||||
.id(debridManager.filteredIAStatus)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, verticalSizeClass == .compact ? 65 : 18)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ struct SearchResultButtonView: View {
|
|||
@EnvironmentObject var pluginManager: PluginManager
|
||||
|
||||
var result: SearchResult
|
||||
var debridIAStatus: IAStatus?
|
||||
|
||||
@State private var runOnce = false
|
||||
@State var existingBookmark: Bookmark? = nil
|
||||
|
|
@ -27,7 +28,7 @@ struct SearchResultButtonView: View {
|
|||
navModel.selectedTitle = result.title ?? ""
|
||||
navModel.resultFromCloud = false
|
||||
|
||||
switch debridManager.matchMagnetHash(result.magnet) {
|
||||
switch debridIAStatus ?? debridManager.matchMagnetHash(result.magnet) {
|
||||
case .full:
|
||||
if debridManager.selectDebridResult(magnet: result.magnet) {
|
||||
debridManager.currentDebridTask = Task {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ struct SearchResultsView: View {
|
|||
@EnvironmentObject var scrapingModel: ScrapingViewModel
|
||||
@EnvironmentObject var navModel: NavigationViewModel
|
||||
@EnvironmentObject var pluginManager: PluginManager
|
||||
@EnvironmentObject var debridManager: DebridManager
|
||||
|
||||
@AppStorage("Behavior.UsesRandomSearchText") var usesRandomSearchText: Bool = false
|
||||
|
||||
|
|
@ -21,7 +22,13 @@ struct SearchResultsView: View {
|
|||
|
||||
var body: some View {
|
||||
ForEach(scrapingModel.searchResults, id: \.self) { result in
|
||||
if pluginManager.filteredInstalledSources.isEmpty || pluginManager.filteredInstalledSources.contains(where: { result.source == $0.name }) {
|
||||
let debridIAStatus = debridManager.matchMagnetHash(result.magnet)
|
||||
if
|
||||
(pluginManager.filteredInstalledSources.isEmpty ||
|
||||
pluginManager.filteredInstalledSources.contains(where: { result.source == $0.name })) &&
|
||||
(debridManager.filteredIAStatus.isEmpty ||
|
||||
debridManager.filteredIAStatus.contains(debridIAStatus))
|
||||
{
|
||||
SearchResultButtonView(result: result)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue