Skip to content

[iOS] - Uplift Leo QA Iteration 4 - 1.64.x #22812

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

Merged
merged 3 commits into from
Mar 28, 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
39 changes: 22 additions & 17 deletions ios/brave-ios/Sources/AIChat/Components/AIChatView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public struct AIChatView: View {
@ObservedObject
var model: AIChatViewModel

@ObservedObject
var speechRecognizer: SpeechRecognizer

@Environment(\.dismiss)
private var dismiss

Expand All @@ -42,8 +45,13 @@ public struct AIChatView: View {

var openURL: ((URL) -> Void)

public init(model: AIChatViewModel, openURL: @escaping (URL) -> Void) {
public init(
model: AIChatViewModel,
speechRecognizer: SpeechRecognizer,
openURL: @escaping (URL) -> Void
) {
self.model = model
self.speechRecognizer = speechRecognizer
self.openURL = openURL
}

Expand Down Expand Up @@ -236,7 +244,7 @@ public struct AIChatView: View {
}

if model.isAgreementAccepted || (!hasSeenIntro.value && !model.isAgreementAccepted) {
AIChatPromptInputView { prompt in
AIChatPromptInputView(speechRecognizer: speechRecognizer) { prompt in
hasSeenIntro.value = true
model.submitQuery(prompt)
hideKeyboard()
Expand All @@ -253,7 +261,7 @@ public struct AIChatView: View {
AIChatPaywallView(
premiumUpgrageSuccessful: { _ in
Task { @MainActor in
await model.refreshPremiumStatusOrderCredentials()
await model.refreshPremiumStatus()
}
})
}
Expand All @@ -265,7 +273,7 @@ public struct AIChatView: View {
}
.onAppear {
Task { @MainActor in
await model.refreshPremiumStatusOrderCredentials()
await model.refreshPremiumStatus()
}

if let query = model.querySubmited {
Expand Down Expand Up @@ -412,19 +420,14 @@ public struct AIChatView: View {
},
dismissAction: {
Task { @MainActor in
// This is needed to try to mitigate a bug in SkusSDK
// See: https://github.com/brave/brave-browser/issues/36824
// Also see the comment on the function
if model.premiumStatus == .active || model.premiumStatus == .activeDisconnected {
await model.refreshPremiumStatusOrderCredentials()
}
}
await model.refreshPremiumStatus()

if let basicModel = model.models.first(where: { $0.access == .basic }) {
model.changeModel(modelKey: basicModel.key)
model.retryLastRequest()
} else {
Logger.module.error("No basic models available")
if let basicModel = model.models.first(where: { $0.access == .basic }) {
model.changeModel(modelKey: basicModel.key)
model.retryLastRequest()
} else {
Logger.module.error("No basic models available")
}
}
}
)
Expand All @@ -441,6 +444,7 @@ public struct AIChatView: View {

private var feedbackView: some View {
AIChatFeedbackView(
speechRecognizer: speechRecognizer,
premiumStatus: model.premiumStatus,
shouldShowPremiumAd: shouldShowFeedbackPremiumAd.value,
onSubmit: { category, feedback in
Expand Down Expand Up @@ -537,6 +541,7 @@ struct AIChatView_Preview: PreviewProvider {
.background(Color(braveSystemName: .containerBackground))

AIChatFeedbackView(
speechRecognizer: SpeechRecognizer(),
premiumStatus: .inactive,
shouldShowPremiumAd: true,
onSubmit: {
Expand Down Expand Up @@ -572,7 +577,7 @@ struct AIChatView_Preview: PreviewProvider {
)
.padding()

AIChatPromptInputView {
AIChatPromptInputView(speechRecognizer: SpeechRecognizer()) {
print("Prompt Submitted: \($0)")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private struct AIChatDropdownView: View {
}

private struct AIChatFeedbackInputView: View {
private var speechRecognizer = SpeechRecognizer()
private var speechRecognizer: SpeechRecognizer

@State
private var isVoiceEntryPresented = false
Expand All @@ -196,7 +196,8 @@ private struct AIChatFeedbackInputView: View {
@Binding
var text: String

init(text: Binding<String>) {
init(speechRecognizer: SpeechRecognizer, text: Binding<String>) {
self.speechRecognizer = speechRecognizer
_text = text
}

Expand Down Expand Up @@ -337,6 +338,7 @@ struct AIChatFeedbackView: View {
@State
private var feedbackText: String = ""

var speechRecognizer: SpeechRecognizer
var premiumStatus: AiChat.PremiumStatus

var shouldShowPremiumAd: Bool
Expand All @@ -360,7 +362,7 @@ struct AIChatFeedbackView: View {
.frame(maxWidth: .infinity, alignment: .leading)
.padding([.horizontal, .top])

AIChatFeedbackInputView(text: $feedbackText)
AIChatFeedbackInputView(speechRecognizer: speechRecognizer, text: $feedbackText)
.padding([.horizontal, .bottom])

if premiumStatus != .active && premiumStatus != .activeDisconnected && shouldShowPremiumAd {
Expand Down Expand Up @@ -397,6 +399,7 @@ struct AIChatFeedbackView: View {
struct AIChatFeedbackView_Previews: PreviewProvider {
static var previews: some View {
AIChatFeedbackView(
speechRecognizer: SpeechRecognizer(),
premiumStatus: .inactive,
shouldShowPremiumAd: true,
onSubmit: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SpeechRecognition
import SwiftUI

struct AIChatPromptInputView: View {
private var speechRecognizer = SpeechRecognizer()
private var speechRecognizer: SpeechRecognizer

@State
private var isVoiceEntryPresented = false
Expand All @@ -22,7 +22,8 @@ struct AIChatPromptInputView: View {

var onSubmit: (String) -> Void

init(onSubmit: @escaping (String) -> Void) {
init(speechRecognizer: SpeechRecognizer, onSubmit: @escaping (String) -> Void) {
self.speechRecognizer = speechRecognizer
self.onSubmit = onSubmit
}

Expand Down Expand Up @@ -109,7 +110,7 @@ struct AIChatPromptInputView: View {
#if DEBUG
struct AIChatPromptInputView_Preview: PreviewProvider {
static var previews: some View {
AIChatPromptInputView {
AIChatPromptInputView(speechRecognizer: SpeechRecognizer()) {
print("Prompt Submitted: \($0)")
}
.previewLayout(.sizeThatFits)
Expand Down
Loading