Ferrite-backup/Ferrite/Views/LibraryViews/HistoryButtonView.swift
kingbri 4d3a16f77e Library: Add history functionality
Action history is logged and displayed to the user's library.
These are triggered whenever the magnet choice sheet is displayed.

Also redo alerts and action sheets to avoid deprecation notices
for >iOS 14. These will be removed when iOS 14 support is dropped.

There was also a problem with sheet presentation not working after
a sheet was dismissed. Disable the appropriate view when a sheet
is being presented.

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

76 lines
2.6 KiB
Swift

//
// HistoryButtonView.swift
// Ferrite
//
// Created by Brian Dashore on 9/9/22.
//
import SwiftUI
struct HistoryButtonView: View {
@EnvironmentObject var toastModel: ToastViewModel
@EnvironmentObject var navModel: NavigationViewModel
@EnvironmentObject var debridManager: DebridManager
let entry: HistoryEntry
var body: some View {
Button {
if let url = entry.url {
if url.starts(with: "https://") {
Task {
debridManager.realDebridDownloadUrl = url
navModel.runDebridAction(urlString: url)
if navModel.currentChoiceSheet != .magnet {
debridManager.realDebridDownloadUrl = ""
}
}
} else {
navModel.runMagnetAction(magnetString: url)
}
} else {
toastModel.updateToastDescription("URL invalid. Cannot load this history entry. Please delete it.")
}
} label: {
VStack(alignment: .leading) {
VStack(alignment: .leading, spacing: 3) {
Text(entry.name ?? "Unknown title")
.font(entry.subName == nil ? .body : .subheadline)
if let subName = entry.subName {
Text(subName)
.foregroundColor(.gray)
.font(.subheadline)
}
}
HStack {
Text(entry.source ?? "Unknown source")
Spacer()
Text("DEBRID")
.fontWeight(.bold)
.padding(3)
.background {
Group {
if let url = entry.url, url.starts(with: "https://") {
Color.green
} else {
Color.red
}
}
.cornerRadius(4)
.opacity(0.5)
}
}
.font(.caption)
}
.lineLimit(1)
.disabledAppearance(navModel.currentChoiceSheet != nil, dimmedOpacity: 0.7, animation: .easeOut(duration: 0.2))
}
.dynamicAccentColor(.white)
.disableInteraction(navModel.currentChoiceSheet != nil)
}
}