From c1805c7aa2e8b6ae5922497b6476033636d1d944 Mon Sep 17 00:00:00 2001 From: Pete Miller Date: Wed, 11 Dec 2024 21:54:24 -0800 Subject: [PATCH] AI Chat storage notice is dismissed after first prompt sending or close button --- .../ai_chat/core/browser/ai_chat_service.cc | 4 ++++ .../notices/notice_conversation_storage.tsx | 23 ------------------- .../resources/page/state/ai_chat_context.tsx | 8 +------ .../page/state/conversation_context.tsx | 6 +++++ 4 files changed, 11 insertions(+), 30 deletions(-) diff --git a/components/ai_chat/core/browser/ai_chat_service.cc b/components/ai_chat/core/browser/ai_chat_service.cc index 58a3226d90f6..ee47809581b1 100644 --- a/components/ai_chat/core/browser/ai_chat_service.cc +++ b/components/ai_chat/core/browser/ai_chat_service.cc @@ -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(); } diff --git a/components/ai_chat/resources/page/components/notices/notice_conversation_storage.tsx b/components/ai_chat/resources/page/components/notices/notice_conversation_storage.tsx index d5b5738d2e91..12cd279ae158 100644 --- a/components/ai_chat/resources/page/components/notices/notice_conversation_storage.tsx +++ b/components/ai_chat/resources/page/components/notices/notice_conversation_storage.tsx @@ -7,7 +7,6 @@ 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' @@ -15,31 +14,9 @@ import illustrationUrl from './conversation_storage.svg' export default function NoticeConversationStorage() { const aiChatContext = useAIChat() - const visibilityTimer = React.useRef() - - 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 (
illustration diff --git a/components/ai_chat/resources/page/state/ai_chat_context.tsx b/components/ai_chat/resources/page/state/ai_chat_context.tsx index 7547cb421114..13b4ab893789 100644 --- a/components/ai_chat/resources/page/state/ai_chat_context.tsx +++ b/components/ai_chat/resources/page/state/ai_chat_context.tsx @@ -80,13 +80,7 @@ export function AIChatContextProvider(props: React.PropsWithChildren 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(), diff --git a/components/ai_chat/resources/page/state/conversation_context.tsx b/components/ai_chat/resources/page/state/conversation_context.tsx index 891fac0f1f6e..c2552a7ed824 100644 --- a/components/ai_chat/resources/page/state/conversation_context.tsx +++ b/components/ai_chat/resources/page/state/conversation_context.tsx @@ -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,