Created
April 3, 2024 20:31
-
-
Save mrhanlon/807d16b964f511b84f3f16e6a215d3d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct PackageRemoveDialog: ViewModifier { | |
@Binding var isShowingPackageRemovalConfirmationDialog: Bool | |
@EnvironmentObject var brewData: BrewDataStorage | |
@EnvironmentObject var appState: AppState | |
@EnvironmentObject var outdatedPackageTracker: OutdatedPackageTracker | |
let shouldPurge: Bool | |
let isCalledFromSidebar: Bool | |
let package: BrewPackage | |
func body(content: Content) -> some View { | |
content.confirmationDialog(shouldPurge ? "action.purge.confirm.title.\(package.name)" : "action.uninstall.confirm.title.\(package.name)", isPresented: $isShowingPackageRemovalConfirmationDialog) { | |
Button(role: .destructive) | |
{ | |
Task | |
{ | |
try await uninstallSelectedPackage( | |
package: package, | |
brewData: brewData, | |
appState: appState, | |
outdatedPackageTracker: outdatedPackageTracker, | |
shouldRemoveAllAssociatedFiles: shouldPurge, | |
shouldApplyUninstallSpinnerToRelevantItemInSidebar: isCalledFromSidebar | |
) | |
} | |
} label: { | |
Text(shouldPurge ? "action.purge-\(package.name)" : "action.uninstall-\(package.name)") | |
} | |
.keyboardShortcut(.defaultAction) | |
Button(role: .cancel) | |
{ | |
isShowingPackageRemovalConfirmationDialog = false | |
} label: { | |
Text("action.cancel") | |
} | |
.keyboardShortcut(.cancelAction) | |
} message: { | |
Text("action.warning.cannot-be-undone") | |
} | |
} | |
} | |
extension View { | |
func packageRemoveDialog(package: BrewPackage, isCalledFromSidebar: Bool, shouldPurge: Bool, showDialog: Binding<Bool>) -> some View { | |
self.modifier(PackageRemoveDialog(isShowingPackageRemovalConfirmationDialog: showDialog, shouldPurge: shouldPurge, isCalledFromSidebar: isCalledFromSidebar, package: package)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment