Skip to content

Commit

Permalink
refactor: Move logic into functions
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinperignon committed Nov 21, 2024
1 parent 8823a33 commit 70b2160
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions SwissTransferCoreUI/Components/AddFilesMenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,15 @@ public struct AddFilesMenuView<Content: View>: 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) {
Expand Down Expand Up @@ -125,6 +117,15 @@ public struct AddFilesMenuView<Content: View>: 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 {
Expand Down

0 comments on commit 70b2160

Please sign in to comment.