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)
|
// MARK: - Universal IA enum (IA = InstantAvailability)
|
||||||
|
|
||||||
public enum IAStatus: Codable, Hashable, Sendable {
|
public enum IAStatus: String, Codable, Hashable, Sendable, CaseIterable {
|
||||||
case full
|
case full = "Cached"
|
||||||
case partial
|
case partial = "Batch"
|
||||||
case none
|
case none = "Uncached"
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Enum for debrid differentiation. 0 is nil
|
// 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 currentDebridTask: Task<Void, Never>?
|
||||||
var downloadUrl: String = ""
|
var downloadUrl: String = ""
|
||||||
var authUrl: URL?
|
var authUrl: URL?
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,26 @@ struct SearchFilterHeaderView: View {
|
||||||
FilterLabelView(name: debridManager.selectedDebridType?.toString() ?? "Debrid")
|
FilterLabelView(name: debridManager.selectedDebridType?.toString() ?? "Debrid")
|
||||||
}
|
}
|
||||||
.id(debridManager.selectedDebridType)
|
.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)
|
.padding(.horizontal, verticalSizeClass == .compact ? 65 : 18)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ struct SearchResultButtonView: View {
|
||||||
@EnvironmentObject var pluginManager: PluginManager
|
@EnvironmentObject var pluginManager: PluginManager
|
||||||
|
|
||||||
var result: SearchResult
|
var result: SearchResult
|
||||||
|
var debridIAStatus: IAStatus?
|
||||||
|
|
||||||
@State private var runOnce = false
|
@State private var runOnce = false
|
||||||
@State var existingBookmark: Bookmark? = nil
|
@State var existingBookmark: Bookmark? = nil
|
||||||
|
|
@ -27,7 +28,7 @@ struct SearchResultButtonView: View {
|
||||||
navModel.selectedTitle = result.title ?? ""
|
navModel.selectedTitle = result.title ?? ""
|
||||||
navModel.resultFromCloud = false
|
navModel.resultFromCloud = false
|
||||||
|
|
||||||
switch debridManager.matchMagnetHash(result.magnet) {
|
switch debridIAStatus ?? debridManager.matchMagnetHash(result.magnet) {
|
||||||
case .full:
|
case .full:
|
||||||
if debridManager.selectDebridResult(magnet: result.magnet) {
|
if debridManager.selectDebridResult(magnet: result.magnet) {
|
||||||
debridManager.currentDebridTask = Task {
|
debridManager.currentDebridTask = Task {
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ struct SearchResultsView: View {
|
||||||
@EnvironmentObject var scrapingModel: ScrapingViewModel
|
@EnvironmentObject var scrapingModel: ScrapingViewModel
|
||||||
@EnvironmentObject var navModel: NavigationViewModel
|
@EnvironmentObject var navModel: NavigationViewModel
|
||||||
@EnvironmentObject var pluginManager: PluginManager
|
@EnvironmentObject var pluginManager: PluginManager
|
||||||
|
@EnvironmentObject var debridManager: DebridManager
|
||||||
|
|
||||||
@AppStorage("Behavior.UsesRandomSearchText") var usesRandomSearchText: Bool = false
|
@AppStorage("Behavior.UsesRandomSearchText") var usesRandomSearchText: Bool = false
|
||||||
|
|
||||||
|
|
@ -21,7 +22,13 @@ struct SearchResultsView: View {
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ForEach(scrapingModel.searchResults, id: \.self) { result in
|
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)
|
SearchResultButtonView(result: result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue