When a search result is selected, there is usually a delay due to the debrid dance of API routes for grabbing a download link to stream. Add a loading indicator and prevent any other tasks from loading unless the user cancels it. iOS 14.5 was a huge update which added many QoL SwiftUI changes that are consistent to modern iOS versions. However, Ferrite supports iOS versions less than 14.5, mainly 14.3. More fixes had to be added to make sure UI is consistent across all OS versions. Signed-off-by: kingbri <bdashore3@gmail.com>
48 lines
1 KiB
Swift
48 lines
1 KiB
Swift
//
|
|
// ToastViewModel.swift
|
|
// Ferrite
|
|
//
|
|
// Created by Brian Dashore on 7/19/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
@MainActor
|
|
class ToastViewModel: ObservableObject {
|
|
enum ToastType: Identifiable {
|
|
var id: Int {
|
|
hashValue
|
|
}
|
|
|
|
case info
|
|
case error
|
|
}
|
|
|
|
// Toast variables
|
|
@Published var toastDescription: String? = nil {
|
|
didSet {
|
|
Task {
|
|
try? await Task.sleep(seconds: 0.1)
|
|
showToast = true
|
|
|
|
try? await Task.sleep(seconds: 5)
|
|
|
|
showToast = false
|
|
toastType = .error
|
|
}
|
|
}
|
|
}
|
|
|
|
@Published var showToast: Bool = false
|
|
|
|
public func updateToastDescription(_ description: String, newToastType: ToastType? = nil) {
|
|
if let newToastType = newToastType {
|
|
toastType = newToastType
|
|
}
|
|
|
|
toastDescription = description
|
|
}
|
|
|
|
// Default the toast type to error since the majority of toasts are errors
|
|
@Published var toastType: ToastType = .error
|
|
}
|