diff --git a/SwissTransferCore/Utils/PreviewHelper.swift b/SwissTransferCore/Utils/PreviewHelper.swift index c5b564d6..bc67719a 100644 --- a/SwissTransferCore/Utils/PreviewHelper.swift +++ b/SwissTransferCore/Utils/PreviewHelper.swift @@ -50,6 +50,17 @@ public enum PreviewHelper { files: [sampleFile] ) + public static let sampleNewUploadSession = NewUploadSession( + duration: "30", + authorEmail: "", + password: "", + message: "Coucou", + numberOfDownload: 250, + language: .english, + recipientsEmails: [], + files: [] + ) + private static func expireTimeStamp(expired: Bool) -> Int64 { let date = Date() let calendar = Calendar(identifier: .gregorian) diff --git a/SwissTransferFeatures/NewTransferView/NewTransferView.swift b/SwissTransferFeatures/NewTransferView/NewTransferView.swift index 12974cb4..57fae089 100644 --- a/SwissTransferFeatures/NewTransferView/NewTransferView.swift +++ b/SwissTransferFeatures/NewTransferView/NewTransferView.swift @@ -27,6 +27,7 @@ import SwissTransferCoreUI public struct NewTransferView: View { @Environment(\.dismiss) private var dismiss + @StateObject private var newTransferManager: NewTransferManager @State private var isLoadingFileToUpload = false @@ -59,9 +60,6 @@ public struct NewTransferView: View { } .padding(.vertical, value: .medium) } - .navigationDestination(for: NewUploadSession.self) { newUploadSession in - UploadProgressView(transferType: .qrcode, uploadSession: newUploadSession, dismiss: dismiss.callAsFunction) - } .floatingContainer { Button(action: startUpload) { Text(STResourcesStrings.Localizable.buttonNext) @@ -75,6 +73,9 @@ public struct NewTransferView: View { .scrollDismissesKeyboard(.immediately) .stNavigationBarNewTransfer(title: STResourcesStrings.Localizable.importFilesScreenTitle) .stNavigationBarStyle() + .navigationDestination(for: NewUploadSession.self) { newUploadSession in + RootUploadProgressView(transferType: .qrcode, uploadSession: newUploadSession, dismiss: dismiss.callAsFunction) + } .navigationDestination(for: DisplayableFile.self) { file in FileListView(parentFolder: file) .stNavigationBarNewTransfer(title: file.name) diff --git a/SwissTransferFeatures/UploadProgressView/RootUploadProgressView.swift b/SwissTransferFeatures/UploadProgressView/RootUploadProgressView.swift new file mode 100644 index 00000000..dcee074e --- /dev/null +++ b/SwissTransferFeatures/UploadProgressView/RootUploadProgressView.swift @@ -0,0 +1,76 @@ +/* + Infomaniak SwissTransfer - iOS App + Copyright (C) 2024 Infomaniak Network SA + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +import STCore +import SwiftUI +import SwissTransferCore +import SwissTransferCoreUI + +public struct RootUploadProgressView: View { + @State private var transferUUID: String? + @State private var uploadError: Error? + + private let transferType: TransferType + private let uploadSession: NewUploadSession + private let dismiss: () -> Void + + public init(transferType: TransferType, uploadSession: NewUploadSession, dismiss: @escaping () -> Void) { + self.transferType = transferType + self.uploadSession = uploadSession + self.dismiss = dismiss + } + + public var body: some View { + Group { + if let uploadError { + // TODO: Add Error View + Text("Error") + } else if let transferUUID { + SuccessfulTransferView( + type: transferType, + transferUUID: transferUUID, + recipientsEmails: uploadSession.recipientsEmails + ) + } else { + UploadProgressView( + transferUUID: $transferUUID, + error: $uploadError, + transferType: transferType, + uploadSession: uploadSession + ) + } + } + .environment(\.dismissModal, dismiss) + } +} + +#Preview { + RootUploadProgressView( + transferType: .qrcode, + uploadSession: NewUploadSession( + duration: "30", + authorEmail: "", + password: "", + message: "Coucou", + numberOfDownload: 250, + language: .english, + recipientsEmails: [], + files: [] + ) + ) {} +} diff --git a/SwissTransferFeatures/UploadProgressView/SuccessfulTransfer/SuccessfulLinkTransferView.swift b/SwissTransferFeatures/UploadProgressView/SuccessfulTransfer/SuccessfulLinkTransferView.swift index 51474139..1b435235 100644 --- a/SwissTransferFeatures/UploadProgressView/SuccessfulTransfer/SuccessfulLinkTransferView.swift +++ b/SwissTransferFeatures/UploadProgressView/SuccessfulTransfer/SuccessfulLinkTransferView.swift @@ -17,6 +17,8 @@ */ import InfomaniakCoreSwiftUI +import InfomaniakDI +import STCore import STResources import SwiftUI import SwissTransferCore @@ -25,9 +27,18 @@ import SwissTransferCoreUI struct SuccessfulLinkTransferView: View { private static let qrCodeSize: CGFloat = 160 + @Environment(\.dismissModal) private var dismissModal + + @LazyInjectService private var injection: SwissTransferInjection + let type: TransferType - let url: URL - let dismiss: () -> Void + let transferUUID: String + + private var transferURL: URL? { + let apiURLCreator = injection.sharedApiUrlCreator + let url = apiURLCreator.shareTransferUrl(transferUUID: transferUUID) + return URL(string: url) + } var body: some View { VStack(spacing: 32) { @@ -40,8 +51,10 @@ struct SuccessfulLinkTransferView: View { .font(.ST.title) .foregroundStyle(Color.ST.textPrimary) - QRCodeView(url: url) - .frame(width: Self.qrCodeSize, height: Self.qrCodeSize) + if let transferURL { + QRCodeView(url: transferURL) + .frame(width: Self.qrCodeSize, height: Self.qrCodeSize) + } if type != .qrcode { Text(STResourcesStrings.Localizable.uploadSuccessLinkDescription) @@ -55,22 +68,24 @@ struct SuccessfulLinkTransferView: View { .padding(.vertical, value: .large) .scrollableEmptyState() .safeAreaButtons { - HStack(spacing: IKPadding.medium) { - ShareLink(item: url) { - Label { - Text(STResourcesStrings.Localizable.buttonShare) - } icon: { - STResourcesAsset.Images.personBadgeShare.swiftUIImage + if let transferURL { + HStack(spacing: IKPadding.medium) { + ShareLink(item: transferURL) { + Label { + Text(STResourcesStrings.Localizable.buttonShare) + } icon: { + STResourcesAsset.Images.personBadgeShare.swiftUIImage + } + .labelStyle(.verticalButton) } - .labelStyle(.verticalButton) - } - CopyToClipboardButton(url: url) + CopyToClipboardButton(url: transferURL) + } + .buttonStyle(.ikBordered) + .frame(maxWidth: IKButtonConstants.maxWidth) } - .buttonStyle(.ikBordered) - .frame(maxWidth: IKButtonConstants.maxWidth) - Button(action: dismiss) { + Button(action: dismissModal) { Text(STResourcesStrings.Localizable.buttonFinished) } .buttonStyle(.ikBorderedProminent) @@ -78,14 +93,15 @@ struct SuccessfulLinkTransferView: View { } private func copyLinkToClipboard() { - UIPasteboard.general.string = url.absoluteString + guard let transferURL else { return } + UIPasteboard.general.string = transferURL.absoluteString } } #Preview("QR Code") { - SuccessfulLinkTransferView(type: .qrcode, url: URL(string: "https://www.infomaniak.com")!) {} + SuccessfulLinkTransferView(type: .qrcode, transferUUID: PreviewHelper.sampleTransfer.uuid) } #Preview("Link") { - SuccessfulLinkTransferView(type: .link, url: URL(string: "https://www.infomaniak.com")!) {} + SuccessfulLinkTransferView(type: .link, transferUUID: PreviewHelper.sampleTransfer.uuid) } diff --git a/SwissTransferFeatures/UploadProgressView/SuccessfulTransfer/SuccessfulMailTransferView.swift b/SwissTransferFeatures/UploadProgressView/SuccessfulTransfer/SuccessfulMailTransferView.swift index 334f76fd..52ab0c5d 100644 --- a/SwissTransferFeatures/UploadProgressView/SuccessfulTransfer/SuccessfulMailTransferView.swift +++ b/SwissTransferFeatures/UploadProgressView/SuccessfulTransfer/SuccessfulMailTransferView.swift @@ -23,8 +23,9 @@ import SwissTransferCore import SwissTransferCoreUI struct SuccessfulMailTransferView: View { + @Environment(\.dismissModal) private var dismissModal + let recipients: [String] - let dismiss: () -> Void var body: some View { VStack(spacing: IKPadding.medium) { @@ -45,7 +46,7 @@ struct SuccessfulMailTransferView: View { } .scrollableEmptyState() .safeAreaButtons { - Button(action: dismiss) { + Button(action: dismissModal) { Text(STResourcesStrings.Localizable.buttonFinished) } .buttonStyle(.ikBorderedProminent) @@ -54,12 +55,12 @@ struct SuccessfulMailTransferView: View { } #Preview("One Recipient") { - SuccessfulMailTransferView(recipients: ["john.smith@ik.me"]) {} + SuccessfulMailTransferView(recipients: ["john.smith@ik.me"]) } #Preview("Many Recipients") { let recipients = Array(repeating: "short@ik.me", count: 2) + Array(repeating: "long-email@infomaniak.com", count: 2) + Array(repeating: "middle@infomaniak.com", count: 3) - SuccessfulMailTransferView(recipients: recipients.shuffled()) {} + SuccessfulMailTransferView(recipients: recipients.shuffled()) } diff --git a/SwissTransferFeatures/UploadProgressView/SuccessfulTransfer/SuccessfulTransferView.swift b/SwissTransferFeatures/UploadProgressView/SuccessfulTransfer/SuccessfulTransferView.swift index 39426345..d50f215d 100644 --- a/SwissTransferFeatures/UploadProgressView/SuccessfulTransfer/SuccessfulTransferView.swift +++ b/SwissTransferFeatures/UploadProgressView/SuccessfulTransfer/SuccessfulTransferView.swift @@ -16,6 +16,7 @@ along with this program. If not, see . */ +import STCore import STResources import SwiftUI import SwissTransferCore @@ -35,23 +36,17 @@ extension TransferType { } public struct SuccessfulTransferView: View { - private let type: TransferType - private let recipientsEmails: [String] - private let dismiss: () -> Void - - public init(type: TransferType, recipientsEmails: [String], dismiss: @escaping () -> Void) { - self.type = type - self.recipientsEmails = recipientsEmails - self.dismiss = dismiss - } + let type: TransferType + let transferUUID: String + let recipientsEmails: [String] public var body: some View { Group { switch type { case .link, .qrcode, .proximity: - SuccessfulLinkTransferView(type: type, url: URL(string: "https://www.infomaniak.com")!, dismiss: dismiss) + SuccessfulLinkTransferView(type: type, transferUUID: transferUUID) case .mail: - SuccessfulMailTransferView(recipients: recipientsEmails, dismiss: dismiss) + SuccessfulMailTransferView(recipients: recipientsEmails) } } .stIconNavigationBar() @@ -61,13 +56,13 @@ public struct SuccessfulTransferView: View { } #Preview("Mail") { - SuccessfulTransferView(type: .mail, recipientsEmails: []) {} + SuccessfulTransferView(type: .mail, transferUUID: PreviewHelper.sampleTransfer.uuid, recipientsEmails: []) } #Preview("QR Code") { - SuccessfulTransferView(type: .qrcode, recipientsEmails: []) {} + SuccessfulTransferView(type: .qrcode, transferUUID: PreviewHelper.sampleTransfer.uuid, recipientsEmails: []) } #Preview("Link") { - SuccessfulTransferView(type: .link, recipientsEmails: []) {} + SuccessfulTransferView(type: .link, transferUUID: PreviewHelper.sampleTransfer.uuid, recipientsEmails: []) } diff --git a/SwissTransferFeatures/UploadProgressView/TransferSessionManager.swift b/SwissTransferFeatures/UploadProgressView/TransferSessionManager.swift index cbf61e5a..23e4468b 100644 --- a/SwissTransferFeatures/UploadProgressView/TransferSessionManager.swift +++ b/SwissTransferFeatures/UploadProgressView/TransferSessionManager.swift @@ -90,7 +90,7 @@ class TransferSessionManager: ObservableObject { let uploadManager = injection.uploadManager - let uploadSession = try await uploadManager.createAnGetUpload(newUploadSession: newUploadSession) + let uploadSession = try await uploadManager.createAndGetUpload(newUploadSession: newUploadSession) let uploadWithRemoteContainer = try await uploadManager.doInitUploadSession( uuid: uploadSession.uuid, diff --git a/SwissTransferFeatures/UploadProgressView/UploadProgress/UploadProgressView.swift b/SwissTransferFeatures/UploadProgressView/UploadProgress/UploadProgressView.swift index 13bbf3ac..26ba55b7 100644 --- a/SwissTransferFeatures/UploadProgressView/UploadProgress/UploadProgressView.swift +++ b/SwissTransferFeatures/UploadProgressView/UploadProgress/UploadProgressView.swift @@ -24,26 +24,21 @@ import SwiftUI import SwissTransferCore import SwissTransferCoreUI -public struct UploadProgressView: View { +struct UploadProgressView: View { + @Environment(\.dismissModal) private var dismissModal @EnvironmentObject private var transferManager: TransferManager @StateObject private var transferSessionManager = TransferSessionManager() @State private var uploadProgressAd = UploadProgressAd.getRandomElement() - @State private var successfulTransfer: TransferUi? - @State private var error: Error? - private let transferType: TransferType - private let uploadSession: NewUploadSession - private let dismiss: () -> Void + @Binding var transferUUID: String? + @Binding var error: Error? - public init(transferType: TransferType, uploadSession: NewUploadSession, dismiss: @escaping () -> Void) { - self.transferType = transferType - self.uploadSession = uploadSession - self.dismiss = dismiss - } + let transferType: TransferType + let uploadSession: NewUploadSession - public var body: some View { + var body: some View { VStack(spacing: IKPadding.medium) { UploadProgressHeaderView(subtitle: uploadProgressAd.description) .frame(maxWidth: LargeEmptyStateView.textMaxWidth) @@ -56,6 +51,7 @@ public struct UploadProgressView: View { .padding(.horizontal, value: .medium) .padding(.top, value: .large) .scrollableEmptyState() + .background(Color.ST.background) .safeAreaButtons(spacing: 32) { UploadProgressIndicationView( completedBytes: transferSessionManager.completedBytes, @@ -78,32 +74,27 @@ public struct UploadProgressView: View { try await Task.sleep(for: .seconds(2)) try await transferManager.addTransferByLinkUUID(linkUUID: transferUUID) - guard let transfer = transferManager.getTransferByUUID(transferUUID: transferUUID) else { - fatalError("Couldn't find transfer") + withAnimation { + self.transferUUID = transferUUID } - successfulTransfer = transfer } catch { - self.error = error + withAnimation { + self.error = error + } } } private func cancelTransfer() { // TODO: Cancel Transfer + dismissModal() } } #Preview { UploadProgressView( + transferUUID: .constant(nil), + error: .constant(nil), transferType: .qrcode, - uploadSession: NewUploadSession( - duration: "30", - authorEmail: "", - password: "", - message: "Coucou", - numberOfDownload: 250, - language: .english, - recipientsEmails: [], - files: [] - ) - ) {} + uploadSession: PreviewHelper.sampleNewUploadSession + ) } diff --git a/Tuist/Package.resolved b/Tuist/Package.resolved index bda42fe6..450293c2 100644 --- a/Tuist/Package.resolved +++ b/Tuist/Package.resolved @@ -77,8 +77,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/Infomaniak/multiplatform-SwissTransfer", "state" : { - "revision" : "026ce2192ddcf3174528d17a0989bc35fe67d92d", - "version" : "0.6.0" + "revision" : "bd4bf654bff4162b2832576ddc9fc9d652fcbf07", + "version" : "0.7.0" } }, {