From 70b2160b4db31ec2ca2c82988e51187c89e6debc Mon Sep 17 00:00:00 2001 From: Valentin Perignon Date: Thu, 21 Nov 2024 16:33:31 +0100 Subject: [PATCH] refactor: Move logic into functions --- .../Components/AddFilesMenuView.swift | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/SwissTransferCoreUI/Components/AddFilesMenuView.swift b/SwissTransferCoreUI/Components/AddFilesMenuView.swift index 687fb6c0..f550f65f 100644 --- a/SwissTransferCoreUI/Components/AddFilesMenuView.swift +++ b/SwissTransferCoreUI/Components/AddFilesMenuView.swift @@ -74,23 +74,15 @@ public struct AddFilesMenuView: View { didSelectFromPhotoLibrary() } .fullScreenCover(isPresented: $isShowingCamera) { - CameraPickerView { image in - didTakePicture(uiImage: image) - } - .ignoresSafeArea() + CameraPickerView(onImagePicked: didTakePicture) + .ignoresSafeArea() } .fileImporter( isPresented: $isShowingImportFile, allowedContentTypes: [.item, .folder], - allowsMultipleSelection: true - ) { result in - switch result { - case .success(let urls): - completion(urls) - case .failure(let error): - Logger.general.error("An error occurred while importing files: \(error)") - } - } + allowsMultipleSelection: true, + onCompletion: didSelectFromFileSystem + ) } private func didTakePicture(uiImage: UIImage) { @@ -125,6 +117,15 @@ public struct AddFilesMenuView: View { completion(urls) } } + + private func didSelectFromFileSystem(_ result: Result<[URL], Error>) { + switch result { + case .success(let urls): + completion(urls) + case .failure(let error): + Logger.general.error("An error occurred while importing files: \(error)") + } + } } #Preview {