Ferrite-backup/Ferrite/Views/ComponentViews/Debrid/DebridLabelView.swift
kingbri 4ae1966934 Debrid: Fix UI updates for IA
Hook to the published variable to push updates.

Signed-off-by: kingbri <bdashore3@proton.me>
2024-06-16 15:00:35 -05:00

41 lines
967 B
Swift

//
// DebridLabelView.swift
// Ferrite
//
// Created by Brian Dashore on 11/27/22.
//
import SwiftUI
struct DebridLabelView: View {
@Store var debridSource: DebridSource
@State var cloudLinks: [String] = []
@State var tagColor: Color = .red
var magnet: Magnet?
var body: some View {
Tag(
name: debridSource.abbreviation,
color: getTagColor(),
horizontalPadding: 5,
verticalPadding: 3
)
}
func getTagColor() -> Color {
if let magnet, cloudLinks.isEmpty {
guard let match = debridSource.IAValues.first(where: { magnet.hash == $0.magnet.hash }) else {
return .red
}
return match.files.count > 1 ? .orange : .green
} else if cloudLinks.count == 1 {
return .green
} else if cloudLinks.count > 1 {
return .orange
} else {
return .red
}
}
}