Skip to content

Commit

Permalink
refactor: Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinperignon committed Oct 9, 2023
1 parent d3f071a commit f62ca87
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Mail/Views/AI Writer/AIPromptView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct AIPromptView: View {
aiModel.resetConversation()
}
.onDisappear {
if !aiModel.isShowingProposition {
if aiModel.conversation.isEmpty {
matomo.track(eventWithCategory: .aiWriter, name: "dismissPromptWithoutGenerating")
}
}
Expand Down
6 changes: 3 additions & 3 deletions Mail/Views/AI Writer/AIPropositionMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ struct AIPropositionMenu: View {
Text(MailResourcesStrings.Localizable.aiButtonRefine)
}
.frame(height: UIConstants.buttonMediumHeight)
.simultaneousGesture(TapGesture().onEnded {
matomo.track(eventWithCategory: .aiWriter, name: "refine")
})
}
.simultaneousGesture(TapGesture().onEnded {
matomo.track(eventWithCategory: .aiWriter, name: "refine")
})
.tint(MailResourcesAsset.textSecondaryColor.swiftUIColor)
.modifier(FixedMenuOrderModifier())
}
Expand Down
10 changes: 4 additions & 6 deletions Mail/Views/AI Writer/AIPropositionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,11 @@ struct AIPropositionView: View {
} else {
MailButton(icon: MailResourcesAsset.plus, label: MailResourcesStrings.Localizable.aiButtonInsert) {
let shouldReplaceContent = !draft.isBodyEmpty
guard !shouldReplaceContent || shouldReplaceContent && UserDefaults.shared
.doNotShowAIReplaceMessageAgain else {
matomo.track(eventWithCategory: .aiWriter, name: "replacePropositionDialog")
guard !shouldReplaceContent || UserDefaults.shared.doNotShowAIReplaceMessageAgain else {
isShowingReplaceContentAlert = true
return
}
insertResult(shouldReplaceContent)
insertResult(shouldReplaceContent: shouldReplaceContent)
}
}
}
Expand All @@ -118,7 +116,7 @@ struct AIPropositionView: View {
}
.customAlert(isPresented: $isShowingReplaceContentAlert) {
ReplaceMessageContentView {
insertResult(true)
insertResult(shouldReplaceContent: true)
}
}
.mailButtonPrimaryColor(MailResourcesAsset.aiColor.swiftUIColor)
Expand All @@ -128,7 +126,7 @@ struct AIPropositionView: View {
}
}

private func insertResult(_ shouldReplaceContent: Bool) {
private func insertResult(shouldReplaceContent: Bool) {
guard !aiModel.isLoading, let content = aiModel.conversation.last?.content else { return }
matomo.track(
eventWithCategory: .aiWriter,
Expand Down
8 changes: 6 additions & 2 deletions Mail/Views/Alerts/ReplaceMessageContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import MailResources
import SwiftUI

struct ReplaceMessageContentView: View {
@LazyInjectService private var matomo: MatomoUtils

@State private var doNotShowAIReplaceMessageAgain = UserDefaults.shared.doNotShowAIReplaceMessageAgain

let action: () -> Void
Expand All @@ -43,8 +45,7 @@ struct ReplaceMessageContentView: View {
.padding(.bottom, UIPadding.alertDescriptionBottom)

ModalButtonsView(primaryButtonTitle: MailResourcesStrings.Localizable.aiReplacementDialogPositiveButton) {
@LazyInjectService var matomo: MatomoUtils
matomo.track(eventWithCategory: .aiWriter, name: "replacePropositionDialog")
matomo.track(eventWithCategory: .aiWriter, name: "replacePropositionConfirm")
if doNotShowAIReplaceMessageAgain {
matomo.track(eventWithCategory: .aiWriter, action: .data, name: "doNotShowAgain")
}
Expand All @@ -53,6 +54,9 @@ struct ReplaceMessageContentView: View {
action()
}
}
.onAppear {
matomo.track(eventWithCategory: .aiWriter, name: "replacePropositionDialog")
}
}
}

Expand Down

0 comments on commit f62ca87

Please sign in to comment.