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 17119db commit c1805c7
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 @@ -80,13 +80,7 @@ export function AIChatContextProvider(props: React.PropsWithChildren<AIChatConte
...context,
goPremium: () => api.uiHandler.goPremium(),
managePremium: () => api.uiHandler.managePremium(),
markStorageNoticeViewed: () => api.service.dismissStorageNotice(),
dismissStorageNotice: () => {
api.setPartialState({
isStorageNoticeDismissed: true
})
api.service.dismissStorageNotice()
},
dismissStorageNotice: () => api.service.dismissStorageNotice(),
enableStoragePref: () => api.service.enableStoragePref(),
dismissPremiumPrompt: () => api.service.dismissPremiumPrompt(),
userRefreshPremiumSession: () => api.uiHandler.refreshPremiumSession(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,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 c1805c7

Please sign in to comment.