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: SelectComposeMailboxView #1288

Merged
merged 59 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
bd7eb36
feat: Add images
Lnamw Feb 6, 2024
c752dfc
feat: Create MailToView
Lnamw Feb 12, 2024
c64c96e
feat: Add dark images
Lnamw Feb 12, 2024
d46e4ad
feat: Remove hardcoded var
Lnamw Feb 15, 2024
6a207df
feat: SelectMailbox for mailTo
Lnamw Feb 19, 2024
16c1347
feat: Create selectMailbox function
Lnamw Feb 19, 2024
efae9a1
feat: Create AccountMailboxesListView
Lnamw Feb 19, 2024
5626385
feat: Not show SelectMailboxView when only one account with one mailbox
Lnamw Feb 20, 2024
c3bd492
fix: Order accounts
valentinperignon Feb 20, 2024
98e2fbc
feat: Load all signatures
valentinperignon Feb 20, 2024
1d445ee
feat: Dismiss SelectMailboxView
Lnamw Feb 20, 2024
d44d4d4
feat: Create SelectMailboxViewModel
Lnamw Feb 20, 2024
f77198e
fix: Compare Mailbox ids
valentinperignon Feb 20, 2024
6916e7a
fix: Rename SelectComposeMailboxView
Lnamw Feb 20, 2024
0c566f0
refactor: Clean ComposeMessageIntentView
valentinperignon Feb 20, 2024
9895608
refactor: Update SelectComposeMailboxView
valentinperignon Feb 20, 2024
3d64b24
feat: Update Loco
Lnamw Feb 20, 2024
afae66f
feat: Display snackbars
Lnamw Feb 20, 2024
7f27a59
fix: Merge
Lnamw Feb 20, 2024
ab4ab2f
fix: Rename images
Lnamw Feb 20, 2024
8e03e64
feat: Add Matomo
Lnamw Feb 20, 2024
8397930
fix: Color mistake
Lnamw Feb 20, 2024
b055cc7
fix: Bug wrong signatures
Lnamw Feb 21, 2024
c81786c
fix: Update UI following changes on figma
Lnamw Feb 27, 2024
15f915c
fix: Update padding
Lnamw Feb 28, 2024
a0563cc
feat: Create SelectedMailboxView
Lnamw Feb 28, 2024
837337e
fix: Update title
Lnamw Feb 28, 2024
4d39f45
fix: Use @EnvironmentObject mailboxManager
Lnamw Feb 29, 2024
586b2da
fix: Remove unused trad
Lnamw Feb 29, 2024
8c36fd3
fix: Remove Spacer()
Lnamw Mar 5, 2024
e39f43a
fix: Update UI SelectComposeMailboxView
Lnamw Mar 5, 2024
b36a333
feat: Create CurrentComposeMailboxView
Lnamw Mar 5, 2024
a7633a7
fix: Update Navigation
Lnamw Mar 5, 2024
fb6c9b3
fix: Remove Spacer()
Lnamw Mar 6, 2024
c56680f
fix: Import Loco
Lnamw Mar 6, 2024
f2a82f7
fix: Update cornerRadius
Lnamw Mar 6, 2024
3c9b43f
fix: Update padding following changes on Figma
Lnamw Mar 6, 2024
3d51137
fix: Bug when selecting mail
Lnamw Mar 6, 2024
9c47559
fix: Make the variable private
Lnamw Mar 11, 2024
fc4ab0a
fix: Add missing trad
Lnamw Mar 11, 2024
b17d378
fix: Add padding
Lnamw Mar 11, 2024
7b68ddf
fix: Reuse AccountCellView
Lnamw Mar 12, 2024
37f681f
fix: Update radius
Lnamw Mar 12, 2024
8edda75
fix: Move stroke and background to AccountHeaderCell
Lnamw Mar 12, 2024
8c080fb
fix: Border stroke bug
Lnamw Mar 13, 2024
8a94d60
fix: Feedbacks
Lnamw Mar 14, 2024
2626dc1
fix: Show chevron on AccountHeaderCell
Lnamw Mar 19, 2024
5ba4459
fix: Padding
Lnamw Mar 19, 2024
b4aa46b
fix: Navigation back animation
Lnamw Mar 21, 2024
3fa5eba
fix: Feedbacks
Lnamw Mar 25, 2024
4a686dd
fix: Disable continueButton
Lnamw Mar 25, 2024
4650103
fix: Remove checkmark
Lnamw Mar 25, 2024
37d92a8
Merge branch 'master' into mailto
Lnamw Mar 25, 2024
8a36080
fix: After merge
Lnamw Mar 25, 2024
6cfbe0b
refactor: Remove check mark
Lnamw Mar 25, 2024
d5d6102
Merge branch 'master' into mailto
Lnamw Mar 26, 2024
d59e8c4
Merge branch 'master' into mailto
Lnamw Apr 2, 2024
4b28a0e
fix: After rebase
Lnamw Apr 2, 2024
8b2d14a
Merge branch 'master' into mailto
Lnamw Apr 2, 2024
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
1 change: 1 addition & 0 deletions Mail/Views/New Message/ComposeMessageHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct ComposeMessageHeaderView: View {
VStack(spacing: 0) {
ComposeMessageSenderMenu(
currentSignature: $currentSignature,
mailboxManager: mailboxManager,
autocompletionType: autocompletionType,
type: .from,
text: mailboxManager.mailbox.email
Expand Down
34 changes: 21 additions & 13 deletions Mail/Views/New Message/ComposeMessageIntentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,31 @@ import SwiftUI
struct ComposeMessageIntentView: View, IntentViewable {
typealias Intent = ResolvedIntent

struct ResolvedIntent {
let mailboxManager: MailboxManager
let draft: Draft
let messageReply: MessageReply?
}

@LazyInjectService private var accountManager: AccountManager
@LazyInjectService private var snackbarPresenter: SnackBarPresentable

@Environment(\.dismiss) private var dismiss

@State private var composeMessageIntent: ComposeMessageIntent
let resolvedIntent = State<ResolvedIntent?>()

struct ResolvedIntent {
let mailboxManager: MailboxManager
let draft: Draft
let messageReply: MessageReply?
}
private var attachments: [Attachable]

let composeMessageIntent: ComposeMessageIntent
var attachments: [Attachable] = []
init(composeMessageIntent: ComposeMessageIntent, attachments: [Attachable] = []) {
_composeMessageIntent = State(wrappedValue: composeMessageIntent)
self.attachments = attachments
}

var body: some View {
NBNavigationStack {
if composeMessageIntent.shouldSelectMailbox {
CurrentComposeMailboxView(composeMessageIntent: $composeMessageIntent)
} else {
if let resolvedIntent = resolvedIntent.wrappedValue {
valentinperignon marked this conversation as resolved.
Show resolved Hide resolved
ComposeMessageView(
draft: resolvedIntent.draft,
Expand All @@ -59,14 +66,11 @@ struct ComposeMessageIntentView: View, IntentViewable {
}
}
}
.interactiveDismissDisabled()
}

func initFromIntent() async {
guard let mailboxManager = accountManager.getMailboxManager(
for: composeMessageIntent.mailboxId,
userId: composeMessageIntent.userId
) else {
guard let mailboxId = composeMessageIntent.mailboxId, let userId = composeMessageIntent.userId,
let mailboxManager = accountManager.getMailboxManager(for: mailboxId, userId: userId) else {
dismiss()
snackbarPresenter.show(message: MailError.unknownError.errorDescription ?? "")
return
Expand Down Expand Up @@ -96,6 +100,10 @@ struct ComposeMessageIntentView: View, IntentViewable {
}
}

if composeMessageIntent.isFromOutsideOfApp {
try? await mailboxManager.refreshAllSignatures()
}

if let draftToWrite {
let draftLocalUUID = draftToWrite.localUUID
writeDraftToRealm(mailboxManager.getRealm(), draft: draftToWrite)
Expand Down
72 changes: 38 additions & 34 deletions Mail/Views/New Message/ComposeMessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,26 +137,46 @@ struct ComposeMessageView: View {
// MARK: - View

var body: some View {
ScrollView {
VStack(spacing: 0) {
ComposeMessageHeaderView(
draft: draft,
focusedField: _focusedField,
autocompletionType: $autocompletionType,
currentSignature: $currentSignature
)

if autocompletionType == nil && !isLoadingContent {
ComposeMessageBodyView(
NavigationView {
ScrollView {
VStack(spacing: 0) {
ComposeMessageHeaderView(
draft: draft,
editorModel: $editorModel,
editorFocus: $editorFocus,
currentSignature: $currentSignature,
isShowingAIPrompt: $aiModel.isShowingPrompt,
attachmentsManager: attachmentsManager,
alert: alert,
messageReply: messageReply
focusedField: _focusedField,
autocompletionType: $autocompletionType,
currentSignature: $currentSignature
)

if autocompletionType == nil && !isLoadingContent {
ComposeMessageBodyView(
draft: draft,
editorModel: $editorModel,
editorFocus: $editorFocus,
currentSignature: $currentSignature,
isShowingAIPrompt: $aiModel.isShowingPrompt,
attachmentsManager: attachmentsManager,
alert: alert,
messageReply: messageReply
)
}
}
}
.navigationTitle(MailResourcesStrings.Localizable.buttonNewMessage)
.navigationBarTitleDisplayMode(.inline)
.interactiveDismissDisabled()
.navigationViewStyle(.stack)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
if !platformDetector.isMac {
CloseButton(dismissHandler: didTouchDismiss)
}
}

ToolbarItem(placement: .navigationBarTrailing) {
Button(action: didTouchSend) {
Label(MailResourcesStrings.Localizable.send, image: MailResourcesAsset.send.name)
}
.disabled(isSendButtonDisabled)
}
}
}
Expand Down Expand Up @@ -187,22 +207,6 @@ struct ComposeMessageView: View {
let rectTop = CGRect(x: 0, y: 0, width: 1, height: 1)
scrollView?.scrollRectToVisible(rectTop, animated: true)
}
.navigationTitle(MailResourcesStrings.Localizable.buttonNewMessage)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
if !platformDetector.isMac {
CloseButton(dismissHandler: didTouchDismiss)
}
}

ToolbarItem(placement: .navigationBarTrailing) {
Button(action: didTouchSend) {
Label(MailResourcesStrings.Localizable.send, image: MailResourcesAsset.send.name)
}
.disabled(isSendButtonDisabled)
}
}
.safeAreaInset(edge: .bottom) {
ExternalTagBottomView(externalTag: draft.displayExternalTag(mailboxManager: mailboxManager))
}
Expand Down
35 changes: 22 additions & 13 deletions Mail/Views/New Message/Header Cells/ComposeMessageSenderMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,7 @@ import SwiftUI
struct ComposeMessageSenderMenu: View {
@EnvironmentObject private var draftContentManager: DraftContentManager

/// Note:
/// ObservedResults will invoke a `default.realm` store, and break (no migration block) while a migration is needed in share
/// extension.
///
/// Therefore, I have to pass the correct realm configuration for `Signature.self`, so it can function correctly.
@ObservedResults(Signature.self, configuration: {
@InjectService var accountManager: AccountManager
guard let currentMailboxManager = accountManager.currentMailboxManager else {
return nil
}
return currentMailboxManager.realmConfiguration
}()) private var signatures
@ObservedResults(Signature.self) private var signatures

@Binding var currentSignature: Signature?

Expand All @@ -48,6 +37,20 @@ struct ComposeMessageSenderMenu: View {
signatures.count > 1
}

init(
currentSignature: Binding<Signature?>,
mailboxManager: MailboxManager,
autocompletionType: ComposeViewFieldType?,
type: ComposeViewFieldType,
text: String
) {
_currentSignature = currentSignature
_signatures = ObservedResults(Signature.self, configuration: mailboxManager.realmConfiguration)
self.autocompletionType = autocompletionType
self.type = type
self.text = text
}

var body: some View {
if autocompletionType == nil {
VStack(spacing: 0) {
Expand Down Expand Up @@ -83,5 +86,11 @@ struct ComposeMessageSenderMenu: View {
}

#Preview {
ComposeMessageSenderMenu(currentSignature: .constant(nil), autocompletionType: nil, type: .from, text: "email@email.com")
ComposeMessageSenderMenu(
currentSignature: .constant(nil),
mailboxManager: PreviewHelper.sampleMailboxManager,
autocompletionType: nil,
type: .from,
text: "email@email.com"
)
}
48 changes: 48 additions & 0 deletions Mail/Views/New Message/Select Mailbox/AccountMailboxCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Infomaniak Mail - 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 MailCore
import MailResources
import SwiftUI

struct AccountMailboxCell: View {
let mailbox: Mailbox
var selectedMailbox: Mailbox?
let selectMailbox: (Mailbox) -> Void

var body: some View {
Button {
withAnimation {
selectMailbox(mailbox)
}
} label: {
Label {
Text(mailbox.email)
} icon: {
if selectedMailbox?.mailboxId == mailbox.mailboxId {
MailResourcesAsset.check.swiftUIImage
}
}
.accessibilityHint(MailResourcesStrings.Localizable.contentDescriptionButtonSelectSignature)
}
}
}

#Preview {
AccountMailboxCell(mailbox: PreviewHelper.sampleMailbox) { _ in }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
Infomaniak Mail - 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 InfomaniakCore
import InfomaniakDI
import MailCore
import MailResources
import SwiftUI

struct AccountMailboxesListView: View {
@LazyInjectService private var accountManager: AccountManager

@EnvironmentObject private var mailboxManager: MailboxManager

let account: Account
var selectedMailbox: Mailbox?

let selectMailbox: (Mailbox) -> Void

private var currentMailbox: Mailbox? {
return accountManager.currentMailboxManager?.mailbox
}

var body: some View {
Menu {
ForEachMailboxView(userId: account.userId) { mailbox in
AccountMailboxCell(mailbox: mailbox, selectedMailbox: selectedMailbox, selectMailbox: selectMailbox)
}
} label: {
AccountHeaderCell(
account: account,
mailboxManager: mailboxManager,
isSelected: .constant(false),
type: .selectComposeMailbox
)
}
}
}

#Preview {
AccountMailboxesListView(
account: PreviewHelper.sampleAccount,
selectedMailbox: PreviewHelper.sampleMailbox
) { _ in }
}
Loading
Loading