Ferrite-backup/Ferrite/ViewModels/ToastViewModel.swift
kingbri e063b91f3f Ferrite: Format and cleanup
Also add swipe to delete support in source lists

Signed-off-by: kingbri <bdashore3@proton.me>
2022-11-19 11:58:02 -05:00

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 {
toastType = newToastType
}
toastDescription = description
}
// Default the toast type to error since the majority of toasts are errors
@Published var toastType: ToastType = .error
}