Skip to content

Commit

Permalink
AI Chat storage notice is dismissed after first prompt sending or clo…
Browse files Browse the repository at this point in the history
…se button
  • Loading branch information
petemill committed Dec 12, 2024
1 parent f81e2a4 commit a843589
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 30 deletions.
4 changes: 4 additions & 0 deletions components/ai_chat/core/browser/ai_chat_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ AIChatService::AIChatService(
prefs::kUserDismissedPremiumPrompt,
base::BindRepeating(&AIChatService::OnStateChanged,
weak_ptr_factory_.GetWeakPtr()));
pref_change_registrar_.Add(
prefs::kUserDismissedStorageNotice,
base::BindRepeating(&AIChatService::OnStateChanged,
weak_ptr_factory_.GetWeakPtr()));

MaybeInitStorage();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,16 @@ import * as React from 'react'
import Button from '@brave/leo/react/button'
import Icon from '@brave/leo/react/icon'
import { getLocale } from '$web-common/locale'
import VisibilityTimer from '$web-common/visibilityTimer'
import { useAIChat } from '../../state/ai_chat_context'
import styles from './notices.module.scss'
import illustrationUrl from './conversation_storage.svg'

export default function NoticeConversationStorage() {
const aiChatContext = useAIChat()

const visibilityTimer = React.useRef<VisibilityTimer>()

const noticeElementRef = React.useCallback((el: HTMLDivElement | null) => {
// note: el will be null when we destroy it.
// note: In new versions of React (maybe newer than we're using) you can return a cleanup function instead
// https://react.dev/blog/2024/04/25/react-19#cleanup-functions-for-refs
if (visibilityTimer.current) {
visibilityTimer.current.stopTracking()
}

if (!el) {
return
}

visibilityTimer.current = new VisibilityTimer(
aiChatContext.markStorageNoticeViewed, 4000, el
)

visibilityTimer.current.startTracking()
}, [])

return (
<div
className={styles.notice}
ref={noticeElementRef}
>
<div className={styles.illustration}>
<img src={illustrationUrl} alt="illustration" />
Expand Down
8 changes: 1 addition & 7 deletions components/ai_chat/resources/page/state/ai_chat_context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,7 @@ export function AIChatContextProvider(props: React.PropsWithChildren) {
...props,
goPremium: () => uiHandler.goPremium(),
managePremium: () => uiHandler.managePremium(),
markStorageNoticeViewed: () => service.dismissStorageNotice(),
dismissStorageNotice: () => {
getAPI().setPartialState({
isStorageNoticeDismissed: true
})
service.dismissStorageNotice()
},
dismissStorageNotice: () => service.dismissStorageNotice(),
enableStoragePref: () => service.enableStoragePref(),
dismissPremiumPrompt: () => service.dismissPremiumPrompt(),
userRefreshPremiumSession: () => uiHandler.refreshPremiumSession(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,12 @@ export function ConversationContextProvider(props: React.PropsWithChildren) {
if (shouldDisableUserInput) return
if (handleFilterActivation()) return

if (!aiChatContext.isStorageNoticeDismissed) {
// Submitting a conversation entry manually means the storage notice can
// be dismissed.
aiChatContext.dismissStorageNotice()
}

if (context.selectedActionType) {
conversationHandler.submitHumanConversationEntryWithAction(
context.inputText,
Expand Down

0 comments on commit a843589

Please sign in to comment.