Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ios/Sources/GutenbergKit/Sources/EditorLocalization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public enum EditorLocalizableString {

// MARK: - Media
case failedToInsertMedia
case failedToLoadSelectedMedia
case failedToProcessCapturedMedia

// MARK: - Common
case ok

// MARK: - Patterns
case patterns
Expand Down Expand Up @@ -96,6 +101,9 @@ public final class EditorLocalization {
case .search: "Search"
case .insertBlock: "Insert Block"
case .failedToInsertMedia: "Failed to insert media"
case .failedToLoadSelectedMedia: "The selected media could not be loaded. It may not be fully downloaded to this device."
case .failedToProcessCapturedMedia: "The captured media could not be processed."
case .ok: "OK"
case .patterns: "Patterns"
case .noPatternsFound: "No Patterns Found"
case .insertPattern: "Insert Pattern"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ struct BlockInserterView: View {
}
.ignoresSafeArea()
}
.alert(item: $viewModel.error) { error in
Alert(
title: Text(EditorLocalization[.failedToInsertMedia]),
message: Text(error.message),
dismissButton: .default(Text(EditorLocalization[.ok]))
)
}
.animation(.smooth(duration: 2), value: viewModel.isProcessingMedia)
.animation(.snappy, value: inlineSelectedMediaItems.count)
.onDisappear {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import SwiftUI
import PhotosUI
import Combine
import OSLog

@MainActor
class BlockInserterViewModel: ObservableObject {
Expand Down Expand Up @@ -82,14 +83,15 @@ class BlockInserterViewModel: ObservableObject {
}
} catch {
anyError = error
Logger.media.error("Failed to import picker selection: \(error)")
}

guard !Task.isCancelled else {
return []
}

if results.isEmpty {
self.error = MediaError(message: anyError?.localizedDescription ?? EditorLocalization[.failedToInsertMedia])
if results.isEmpty, anyError != nil {
self.error = MediaError(message: EditorLocalization[.failedToLoadSelectedMedia])
}

return results
Expand All @@ -109,7 +111,7 @@ class BlockInserterViewModel: ObservableObject {
switch media {
case .photo(let image):
guard let imageData = image.jpegData(compressionQuality: 0.8) else {
throw MediaError(message: "Failed to convert image to JPEG")
throw MediaError(message: EditorLocalization[.failedToProcessCapturedMedia])
}

let fileURL = try await fileManager.writeData(imageData, withExtension: "jpg")
Expand All @@ -128,7 +130,8 @@ class BlockInserterViewModel: ObservableObject {

return [mediaInfo]
} catch {
self.error = MediaError(message: error.localizedDescription)
Logger.media.error("Failed to process captured media: \(error)")
self.error = MediaError(message: EditorLocalization[.failedToProcessCapturedMedia])
return []
}
}
Expand Down
Loading