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
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Foundation
import UniformTypeIdentifiers

/// Public boundary payload that app-target external pickers (Stock Photos)
/// construct and pass through `ExternalMediaPickerDelegate`. The
/// module's view model converts this to `UploadSource.remoteURL(_)` before
/// enqueueing — keeps the internal `UploadSource` enum out of the public API.
public struct ExternalRemoteMedia: Sendable {
public let url: URL
public let suggestedName: String
public let contentType: UTType
public let caption: String?

public init(url: URL, suggestedName: String, contentType: UTType, caption: String?) {
self.url = url
self.suggestedName = suggestedName
self.contentType = contentType
self.caption = caption
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ struct FailedUpload: Identifiable, Sendable {
/// True when the actor can retry a staged upload or repeat preparation
/// after a recognized temporary failure. Other failures are remove-only.
let isRetryable: Bool
/// A staged file is available only after preparation succeeds.
let localFileURL: URL?
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ struct PendingUpload: Identifiable, Sendable {
let displayName: String // basename of the temp file
let kind: MediaKind // for icon + Uploads-row rendering
let progress: Progress // bound to ProgressView directly
/// Materialized temp file on disk; nil until materialization completes.
/// Drives the Uploads-row thumbnail.
let localFileURL: URL?
}
33 changes: 20 additions & 13 deletions Modules/Sources/WordPressMediaLibrary/Strings/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,16 @@ enum Strings {
value: "Uploads",
comment: "Navigation title for the Uploads queue screen."
)
static let uploadsScreenAllDone = NSLocalizedString(
"mediaLibrary.uploads.allDone",
static let uploadsScreenEmpty = NSLocalizedString(
"mediaLibrary.uploads.empty",
value: "No Uploads",
comment: "Empty-state label shown on the Uploads screen when the queue has no items."
)
static let uploadsScreenAllUploaded = NSLocalizedString(
"mediaLibrary.uploads.allUploaded",
value: "All uploaded",
comment: "Empty-state label shown on the Uploads screen after the last item resolves."
comment:
"Label shown on the Uploads screen when the last upload in the queue finished while the screen was open."
)
static let uploadsScreenClose = NSLocalizedString(
"mediaLibrary.uploads.close",
Expand All @@ -273,24 +279,24 @@ enum Strings {
value: "Retry",
comment: "Per-row action: retry a failed upload."
)
static let uploadActionDismiss = NSLocalizedString(
"mediaLibrary.uploads.dismiss",
value: "Dismiss",
static let uploadActionRemove = NSLocalizedString(
"mediaLibrary.uploads.remove",
value: "Remove",
comment: "Per-row action: remove a failed upload from the queue."
)
static let uploadBulkRetryAll = NSLocalizedString(
"mediaLibrary.uploads.bulk.retryAll",
value: "Retry all failed",
comment: "Bulk action: retry every failed upload."
)
static let uploadBulkDismissAll = NSLocalizedString(
"mediaLibrary.uploads.bulk.dismissAll",
value: "Dismiss all failed",
comment: "Bulk action: dismiss every failed upload."
static let uploadBulkRemoveAll = NSLocalizedString(
"mediaLibrary.uploads.bulk.removeAll",
value: "Remove all failed",
comment: "Bulk action: remove every failed upload from the queue."
)
static let uploadBulkCancelAll = NSLocalizedString(
"mediaLibrary.uploads.bulk.cancelAll",
value: "Cancel all uploading",
"mediaLibrary.uploads.bulk.cancelAllUploads",
value: "Cancel all uploads",
comment: "Bulk action: cancel every in-flight upload."
)

Expand All @@ -299,7 +305,8 @@ enum Strings {
static let addMenuTitle = NSLocalizedString(
"mediaLibrary.addMenu.title",
value: "Add",
comment: "Accessibility label for the toolbar + button that opens the Add menu."
comment:
"Title of the toolbar + button that opens the Add menu. Read by VoiceOver and shown when the toolbar moves into its overflow menu."
)
static let addMenuPhotoLibrary = NSLocalizedString(
"mediaLibrary.addMenu.photoLibrary",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,8 @@ private struct InternalPending {
id: id,
displayName: materialized?.displayName ?? displayName,
kind: materialized?.kind ?? kind,
progress: overallProgress
progress: overallProgress,
localFileURL: materialized?.tempFileURL
)
}
}
Expand All @@ -494,7 +495,8 @@ private struct InternalFailed {
displayName: materialized?.displayName ?? displayName,
kind: materialized?.kind ?? kind,
errorMessage: errorMessage,
isRetryable: retryPayload != nil
isRetryable: retryPayload != nil,
localFileURL: materialized?.tempFileURL
)
}
}
Expand Down
44 changes: 44 additions & 0 deletions Modules/Sources/WordPressMediaLibrary/Views/BannerView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import SwiftUI

struct BannerView: View {
let summary: MediaLibraryViewModel.BannerSummary
let onTap: () -> Void

var body: some View {
Button(action: onTap) {
HStack(spacing: 12) {
if summary.pendingCount > 0 {
ProgressView()
.progressViewStyle(.circular)
.controlSize(.small)
}
Text(label)
.font(.subheadline)
Spacer()
Image(systemName: "chevron.right")
.foregroundStyle(.tertiary)
}
.padding(.horizontal, 16)
.padding(.vertical, 10)
.background(.thinMaterial, in: .rect(cornerRadius: 12))
}
.buttonStyle(.plain)
.padding(.horizontal, 16)
.padding(.vertical, 8)
}

private var label: String {
switch (summary.pendingCount, summary.failedCount) {
case (let p, 0) where p > 0:
let template = p == 1 ? Strings.uploadBannerUploadingOnlySingle : Strings.uploadBannerUploadingOnly
return String.localizedStringWithFormat(template, p)
case (let p, let f) where p > 0 && f > 0:
return String.localizedStringWithFormat(Strings.uploadBannerMixed, p, f)
case (0, let f) where f > 0:
let template = f == 1 ? Strings.uploadBannerFailedOnlySingle : Strings.uploadBannerFailedOnly
return String.localizedStringWithFormat(template, f)
default:
return ""
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import SwiftUI
import UIKit
import UniformTypeIdentifiers

struct CameraPickerRepresentable: UIViewControllerRepresentable {
enum Mode { case photo, video }
let mode: Mode
let onPicked: (UploadSource) -> Void
let onCancel: () -> Void

func makeUIViewController(context: Context) -> UIImagePickerController {
let controller = UIImagePickerController()
controller.sourceType = .camera
controller.mediaTypes = [
mode == .photo ? UTType.image.identifier : UTType.movie.identifier
]
if mode == .video {
controller.videoQuality = .typeHigh
}
controller.delegate = context.coordinator
return controller
}

func updateUIViewController(_ uiViewController: UIImagePickerController, context: Context) {}

func makeCoordinator() -> Coordinator { Coordinator(parent: self) }

final class Coordinator: NSObject, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
let parent: CameraPickerRepresentable

init(parent: CameraPickerRepresentable) {
self.parent = parent
}

func imagePickerController(
_ picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]
) {
picker.dismiss(animated: true)
switch parent.mode {
case .photo:
if let image = info[.originalImage] as? UIImage {
parent.onPicked(.cameraImage(image, capturedAt: Date()))
} else {
parent.onCancel()
}
case .video:
if let url = info[.mediaURL] as? URL {
parent.onPicked(.cameraVideo(url, capturedAt: Date()))
} else {
parent.onCancel()
}
}
}

func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
picker.dismiss(animated: true)
parent.onCancel()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import SwiftUI

/// Public delegate protocol the app-target picker sheets call into.
/// `MediaLibraryViewModel` conforms internally; the app target only sees
/// this protocol existential via `ExternalMediaPickerOption.sheetContent`.
@MainActor
public protocol ExternalMediaPickerDelegate: AnyObject {
func didPick(remoteMedia: [ExternalRemoteMedia])
func didPick(imagePlaygroundFile url: URL, suggestedName: String)
func didCancel()
}

/// Public extension point that `MediaLibraryView`'s add-menu iterates.
/// `MediaLibraryRouting` constructs one of these per external source the
/// app target wants to offer (Stock Photos, Image Playground).
public struct ExternalMediaPickerOption: Identifiable {
public let id: String
public let label: String
public let systemImage: String
public let sheetContent: @MainActor (_ delegate: any ExternalMediaPickerDelegate) -> AnyView

public init(
id: String,
label: String,
systemImage: String,
sheetContent: @escaping @MainActor (_ delegate: any ExternalMediaPickerDelegate) -> AnyView
) {
self.id = id
self.label = label
self.systemImage = systemImage
self.sheetContent = sheetContent
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ public enum MediaLibraryHostingController {
@MainActor
public static func make(
client: WordPressClient,
tracker: any MediaTracker
tracker: any MediaTracker,
uploader: MediaUploader,
externalPickerOptions: [ExternalMediaPickerOption] = []
) -> UIViewController {
let view = MediaLibraryContainerView(client: client, tracker: tracker)
let view = MediaLibraryContainerView(
client: client,
tracker: tracker,
uploader: uploader,
externalPickerOptions: externalPickerOptions
)
let host = UIHostingController(rootView: view)
host.navigationItem.largeTitleDisplayMode = .never
return host
Expand All @@ -30,6 +37,8 @@ public enum MediaLibraryHostingController {
private struct MediaLibraryContainerView: View {
let client: WordPressClient
let tracker: any MediaTracker
let uploader: MediaUploader
let externalPickerOptions: [ExternalMediaPickerOption]

@State private var resolved: Resolved?
@State private var error: Error?
Expand All @@ -48,7 +57,8 @@ private struct MediaLibraryContainerView: View {
viewModel: resolved.viewModel,
service: resolved.service,
client: client,
tracker: tracker
tracker: tracker,
externalPickerOptions: externalPickerOptions
)
} else if let error {
EmptyStateView.failure(error: error) {
Expand All @@ -66,7 +76,8 @@ private struct MediaLibraryContainerView: View {
viewModel: MediaLibraryViewModel(
service: service,
client: client,
tracker: tracker
tracker: tracker,
uploader: uploader
),
service: service
)
Expand Down
Loading