diff --git a/Modules/Sources/Browse/Resources/en.lproj/Localizable.strings b/Modules/Sources/Browse/Resources/en.lproj/Localizable.strings index 6cef50f..91ca247 100644 --- a/Modules/Sources/Browse/Resources/en.lproj/Localizable.strings +++ b/Modules/Sources/Browse/Resources/en.lproj/Localizable.strings @@ -25,6 +25,16 @@ "message.type_not_supported.text.second" = "Please be patient while the support for this type of document is being built by our development team."; "message.type_not_supported.button.text" = "Go back to folder"; +// DeleteItemViewModifier + +"delete_item.action_sheet.title" = "Delete an item"; +"delete_item.action_sheet.message" = "You are about to delete an item named \"%@\" from this folder.\n\nAre you sure you wish to proceed?"; +"delete_item.action_sheet.button.ok" = "Yes, please delete it."; +"delete_item.action_sheet.button.cancel" = "No, I reconsidered."; +"delete_item.system_alert.title" = "..."; +"delete_item.system_alert.message" = "..."; +"delete_item.system_alert.button.dismiss" = "..."; + // BrowseView "browse.toolbar_item.menu.add_actions.text" = "Add file and/or folder"; diff --git a/Modules/Sources/Browse/UI/Extensions/View+ViewModifiers.swift b/Modules/Sources/Browse/UI/Extensions/View+ViewModifiers.swift index 7b199c9..d2f9003 100644 --- a/Modules/Sources/Browse/UI/Extensions/View+ViewModifiers.swift +++ b/Modules/Sources/Browse/UI/Extensions/View+ViewModifiers.swift @@ -20,4 +20,10 @@ extension View { destination: { destination } )) } + + func delete( + item: Binding<(any FileSystemItemIdentifiable)?> + ) -> some View { + modifier(DeleteItemViewModifier(item: item)) + } } diff --git a/Modules/Sources/Browse/UI/View Modifiers/DeleteItemViewModifier.swift b/Modules/Sources/Browse/UI/View Modifiers/DeleteItemViewModifier.swift new file mode 100644 index 0000000..d92ce12 --- /dev/null +++ b/Modules/Sources/Browse/UI/View Modifiers/DeleteItemViewModifier.swift @@ -0,0 +1,76 @@ +// +// DeleteItemViewModifier.swift +// Browse +// +// Created by Javier Cicchelli on 16/12/2022. +// + +import SwiftUI + +struct DeleteItemViewModifier: ViewModifier { + + // MARK: States + + @State private var showErrorAlert: Bool = false + + // MARK: Bindings + + @Binding var item: (any FileSystemItemIdentifiable)? + + // MARK: Body + + func body(content: Content) -> some View { + content + .actionSheet(isPresented: showDeletionConfirmation) { + ActionSheet( + title: Text( + "delete_item.action_sheet.title", + bundle: .module + ), + message: Text( + "delete_item.action_sheet.message", + bundle: .module + ), + buttons: [ + .destructive(Text( + "delete_item.action_sheet.button.ok", + bundle: .module + )) { + // TODO: implement the deletion of an item from the backend. + }, + .cancel(Text( + "delete_item.action_sheet.button.cancel", + bundle: .module + )) { + item = nil + }, + ] + ) + } + .alert(isPresented: $showErrorAlert) { + Alert( + title: Text( + "delete_item.system_alert.title", + bundle: .module + ), + message: Text( + "delete_item.system_alert.message", + bundle: .module + ), + dismissButton: .cancel(Text( + "delete_item.system_alert.button.dismiss", + bundle: .module + )) + ) + } + } + +} + +// MARK: - Helpers + +private extension DeleteItemViewModifier { + var showDeletionConfirmation: Binding { + .init { item != nil } set: { _ in } + } +}