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(NewTransfer): Use real settings #40

Merged
merged 4 commits into from
Nov 22, 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
52 changes: 0 additions & 52 deletions SwissTransferCoreUI/Modifiers/FloatingContainerModifier.swift

This file was deleted.

37 changes: 25 additions & 12 deletions SwissTransferFeatures/NewTransferView/NewTransferDetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,36 @@
*/

import InfomaniakCoreSwiftUI
import InfomaniakDI
import STCore
import STResources
import SwiftUI
import SwissTransferCore
import SwissTransferCoreUI

struct NewTransferDetailsView: View {
@EnvironmentObject private var newTransferManager: NewTransferManager
@FocusState private var isMessageFieldFocused

@State private var sender = ""
@State private var recipient = ""
@State private var message = ""
@Binding var authorEmail: String
@Binding var recipientEmail: String
@Binding var message: String

@FocusState private var isMessageFieldFocused
let transferType: TransferType

var body: some View {
VStack(spacing: IKPadding.medium) {
if newTransferManager.transferType == .mail {
TextField(STResourcesStrings.Localizable.senderMailAddressPlaceholder, text: $sender)
.textFieldStyle(NewTransferTextFieldStyle())
.keyboardType(.emailAddress)
TextField(STResourcesStrings.Localizable.recipientMailAddressPlaceholder, text: $recipient)
if transferType == .mail {
TextField(STResourcesStrings.Localizable.senderMailAddressPlaceholder, text: $authorEmail) { _ in
saveAuthorMailAddress()
}
.textFieldStyle(NewTransferTextFieldStyle())
.keyboardType(.emailAddress)

TextField(STResourcesStrings.Localizable.recipientMailAddressPlaceholder, text: $recipientEmail)
.textFieldStyle(NewTransferTextFieldStyle())
.keyboardType(.emailAddress)
}

TextEditor(text: $message)
.focused($isMessageFieldFocused)
.frame(minHeight: 88, alignment: .top)
Expand All @@ -50,9 +57,15 @@ struct NewTransferDetailsView: View {
)
}
}

private func saveAuthorMailAddress() {
Task {
@InjectService var settingsManager: AppSettingsManager
try? await settingsManager.setLastAuthorEmail(authorEmail: authorEmail)
}
}
}

#Preview {
NewTransferDetailsView()
.environmentObject(NewTransferManager())
NewTransferDetailsView(authorEmail: .constant(""), recipientEmail: .constant(""), message: .constant(""), transferType: .link)
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ enum TmpDirType: String {

@MainActor
class NewTransferManager: ObservableObject {
@Published var transferType: TransferType = .qrCode

init() {
cleanTmpDir(type: .upload)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ import SwissTransferCore
import SwissTransferCoreUI

struct NewTransferSettingsView: View {
@State private var duration = ValidityPeriod.thirty
@State private var limit = DownloadLimit.twoHundredFifty
@State private var language = EmailLanguage.french

@State private var showPasswordSetting = false
@State private var isShowingValiditySetting = false
@State private var isShowingDownloadLimitSetting = false
@State private var isShowingLanguageSetting = false

@Binding var duration: ValidityPeriod
@Binding var limit: DownloadLimit
@Binding var language: EmailLanguage
@Binding var password: String

var body: some View {
VStack(alignment: .leading, spacing: IKPadding.medium) {
Text(STResourcesStrings.Localizable.advancedSettingsTitle)
Expand Down Expand Up @@ -105,12 +106,17 @@ struct NewTransferSettingsView: View {
.clipShape(.rect(cornerRadius: IKRadius.large))
)
.sheet(isPresented: $showPasswordSetting) {
PasswordSettingView()
PasswordSettingView(password: $password)
}
}
}
}

#Preview {
NewTransferSettingsView()
NewTransferSettingsView(
duration: .constant(.one),
limit: .constant(.oneHundred),
language: .constant(.french),
password: .constant("")
)
}
23 changes: 16 additions & 7 deletions SwissTransferFeatures/NewTransferView/NewTransferTypeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
*/

import InfomaniakCoreSwiftUI
import InfomaniakDI
import STCore
import STResources
import SwiftUI

struct NewTransferTypeView: View {
@EnvironmentObject private var newTransferManager: NewTransferManager
@Binding var transferType: TransferType

var body: some View {
VStack(alignment: .leading, spacing: IKPadding.medium) {
Expand All @@ -35,11 +36,9 @@ struct NewTransferTypeView: View {
HStack {
ForEach(TransferType.allCases, id: \.name) { type in
Button {
withAnimation(.easeIn(duration: 0.1)) {
newTransferManager.transferType = type
}
selectType(type)
} label: {
TransferTypeCell(type: type, isSelected: newTransferManager.transferType == type)
TransferTypeCell(type: type, isSelected: transferType == type)
}
}
}
Expand All @@ -48,9 +47,19 @@ struct NewTransferTypeView: View {
.scrollIndicators(.hidden)
}
}

private func selectType(_ type: TransferType) {
adrien-coye marked this conversation as resolved.
Show resolved Hide resolved
withAnimation {
transferType = type
}

Task {
@InjectService var settingsManager: AppSettingsManager
try? await settingsManager.setLastTransferType(transferType: type)
}
}
}

#Preview {
NewTransferTypeView()
.environmentObject(NewTransferManager())
NewTransferTypeView(transferType: .constant(.qrCode))
}
87 changes: 62 additions & 25 deletions SwissTransferFeatures/NewTransferView/NewTransferView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

import InfomaniakCoreSwiftUI
import InfomaniakDI
import OSLog
import STCore
import STResources
Expand All @@ -33,6 +34,15 @@ public struct NewTransferView: View {
@State private var isLoadingFileToUpload = false
@State private var navigationPath = NavigationPath()

@State private var transferType = TransferType.qrCode
@State private var authorEmail = ""
@State private var recipientEmail = ""
@State private var message = ""
@State private var password = ""
@State private var validityPeriod = ValidityPeriod.thirty
@State private var downloadLimit = DownloadLimit.twoHundredFifty
@State private var emailLanguage = EmailLanguage.french

public init(urls: [URL]) {
let transferManager = NewTransferManager()
_ = transferManager.addFiles(urls: urls)
Expand All @@ -43,38 +53,41 @@ public struct NewTransferView: View {
NavigationStack(path: $navigationPath) {
ScrollView {
VStack(spacing: IKPadding.medium) {
// FilesCell
NewTransferFilesCellView()
.padding(.horizontal, value: .medium)

// Title and message
NewTransferDetailsView()
.padding(.horizontal, value: .medium)

// Type
NewTransferTypeView()

// Settings
NewTransferSettingsView()
.padding(.horizontal, value: .medium)
NewTransferDetailsView(
authorEmail: $authorEmail,
recipientEmail: $recipientEmail,
message: $message,
transferType: transferType
)
.padding(.horizontal, value: .medium)

NewTransferTypeView(transferType: $transferType)

NewTransferSettingsView(
duration: $validityPeriod,
limit: $downloadLimit,
language: $emailLanguage,
password: $password
)
.padding(.horizontal, value: .medium)
}
.padding(.vertical, value: .medium)
}
.floatingContainer {
.safeAreaButtons {
Button(action: startUpload) {
Text(STResourcesStrings.Localizable.buttonNext)
.frame(maxWidth: .infinity)
}
.buttonStyle(.ikBorderedProminent)
.ikButtonFullWidth(true)
.ikButtonLoading(isLoadingFileToUpload)
.controlSize(.large)
}
.scrollDismissesKeyboard(.immediately)
.stNavigationBarNewTransfer(title: STResourcesStrings.Localizable.importFilesScreenTitle)
.stNavigationBarStyle()
.navigationDestination(for: NewUploadSession.self) { newUploadSession in
RootUploadProgressView(transferType: .qrCode, uploadSession: newUploadSession, dismiss: dismiss.callAsFunction)
.navigationDestination(for: NewUploadSession.self) { uploadSession in
RootUploadProgressView(transferType: transferType, uploadSession: uploadSession, dismiss: dismiss.callAsFunction)
}
.navigationDestination(for: DisplayableFile.self) { file in
FileListView(parentFolder: file)
Expand All @@ -87,26 +100,50 @@ public struct NewTransferView: View {
.stNavigationBarStyle()
}
}
.onAppear(perform: initializeValuesFromSettings)
.environment(\.dismissModal) {
dismiss()
}
.environmentObject(newTransferManager)
}

func startUpload() {
private func initializeValuesFromSettings() {
@InjectService var settingsManager: AppSettingsManager
guard let appSettings = settingsManager.getAppSettings() else { return }

transferType = appSettings.lastTransferType
authorEmail = appSettings.lastAuthorEmail ?? ""

validityPeriod = appSettings.validityPeriod
downloadLimit = appSettings.downloadLimit
emailLanguage = appSettings.emailLanguage
}

private func startUpload() {
Task {
isLoadingFileToUpload = true

let recipientsEmail = [String]()
if transferType == .mail,
recipientEmail.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == false {
recipientEmail.append(recipientEmail.trimmingCharacters(in: .whitespacesAndNewlines))
}

var authorTrimmedEmail = ""
if transferType == .mail {
authorTrimmedEmail = authorEmail.trimmingCharacters(in: .whitespacesAndNewlines)
}

do {
let filesToUpload = try newTransferManager.filesToUpload()
let newUploadSession = NewUploadSession(
duration: ValidityPeriod.thirty,
authorEmail: "",
password: "",
message: "",
numberOfDownload: DownloadLimit.twoHundredFifty,
language: .english,
recipientsEmails: [],
duration: validityPeriod,
authorEmail: authorTrimmedEmail,
password: password,
message: message.trimmingCharacters(in: .whitespacesAndNewlines),
numberOfDownload: downloadLimit,
language: emailLanguage,
recipientsEmails: recipientsEmail,
files: filesToUpload
)
navigationPath.append(newUploadSession)
Expand Down
Loading
Loading