Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Show Success Transfer view #38

Merged
merged 3 commits into from
Nov 12, 2024
Merged
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
11 changes: 11 additions & 0 deletions SwissTransferCore/Utils/PreviewHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions SwissTransferFeatures/NewTransferView/NewTransferView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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
valentinperignon marked this conversation as resolved.
Show resolved Hide resolved
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: []
)
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/

import InfomaniakCoreSwiftUI
import InfomaniakDI
import STCore
import STResources
import SwiftUI
import SwissTransferCore
Expand All @@ -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) {
Expand All @@ -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)
Expand All @@ -55,37 +68,40 @@ 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)
}
}

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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -45,7 +46,7 @@ struct SuccessfulMailTransferView: View {
}
.scrollableEmptyState()
.safeAreaButtons {
Button(action: dismiss) {
Button(action: dismissModal) {
Text(STResourcesStrings.Localizable.buttonFinished)
}
.buttonStyle(.ikBorderedProminent)
Expand All @@ -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())
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import STCore
import STResources
import SwiftUI
import SwissTransferCore
Expand All @@ -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()
Expand All @@ -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: [])
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading
Loading