Skip to content

Commit b7f1d90

Browse files
Do not preserve searchquery (#107607)
1 parent 7ba532a commit b7f1d90

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

packages/help-center/src/components/help-center-footer.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
import { recordTracksEvent } from '@automattic/calypso-analytics';
2+
import { HelpCenterSelect } from '@automattic/data-stores';
23
import { Button, CardFooter } from '@wordpress/components';
4+
import { useDispatch, useSelect } from '@wordpress/data';
35
import { useI18n } from '@wordpress/react-i18n';
46
import { Route, Routes, useNavigate } from 'react-router-dom';
57
import { useHelpCenterContext } from '../contexts/HelpCenterContext';
68
import { useStillNeedHelpURL } from '../hooks';
9+
import { HELP_CENTER_STORE } from '../stores';
710

811
import './help-center-footer.scss';
912

1013
export const HelpCenterContactButton = () => {
1114
const { __ } = useI18n();
1215
const { url } = useStillNeedHelpURL();
1316
const { sectionName } = useHelpCenterContext();
14-
const redirectToWpcom = url === 'https://wordpress.com/help/contact';
1517
const navigate = useNavigate();
18+
const { setMessage } = useDispatch( HELP_CENTER_STORE );
19+
const searchQuery = useSelect(
20+
( select ) => ( select( HELP_CENTER_STORE ) as HelpCenterSelect ).getMessage(),
21+
[]
22+
);
1623

1724
const handleClick = () => {
1825
recordTracksEvent( 'calypso_inlinehelp_morehelp_click', {
@@ -22,7 +29,11 @@ export const HelpCenterContactButton = () => {
2229
button_type: 'Still need help?',
2330
} );
2431

25-
navigate( redirectToWpcom ? { pathname: url } : url );
32+
navigate(
33+
url === '/odie' && searchQuery ? `/odie?query=${ encodeURIComponent( searchQuery ) }` : url
34+
);
35+
36+
setMessage( '' );
2637
};
2738

2839
return (

packages/help-center/src/components/help-center-search-results.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,9 @@ function HelpSearchResults( {
383383
</p>
384384
<Button
385385
variant="secondary"
386-
onClick={ () => setNavigateToRoute( '/odie' ) }
386+
onClick={ () =>
387+
setNavigateToRoute( `/odie?query=${ encodeURIComponent( searchQuery ) }` )
388+
}
387389
className="show-more-button"
388390
>
389391
{ __( 'Ask AI assistant', __i18n_text_domain__ ) }

packages/odie-client/src/components/send-message-input/index.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import '@automattic/agenttic-ui/index.css';
22
import { useInput } from '@automattic/agenttic-ui';
3-
import { HelpCenterSelect } from '@automattic/data-stores';
43
import { EmailFallbackNotice } from '@automattic/help-center/src/components/notices';
5-
import { HELP_CENTER_STORE } from '@automattic/help-center/src/stores';
6-
import { useSelect } from '@wordpress/data';
74
import { useCallback, useEffect, useRef, useState } from '@wordpress/element';
85
import { __ } from '@wordpress/i18n';
6+
import { useSearchParams } from 'react-router-dom';
97
import Smooch from 'smooch';
108
import { useOdieAssistantContext } from '../../context';
119
import { useSendChatMessage } from '../../hooks';
@@ -37,11 +35,9 @@ export const OdieSendMessageButton = () => {
3735
const isChatBusy = chat.status === 'loading' || chat.status === 'sending';
3836
const isInitialLoading = chat.status === 'loading';
3937
const isLiveChat = chat.provider?.startsWith( 'zendesk' );
40-
const searchQuery = useSelect(
41-
( select ) => ( select( HELP_CENTER_STORE ) as HelpCenterSelect ).getMessage(),
42-
[]
43-
);
44-
const [ inputValue, setInputValue ] = useState( searchQuery || '' );
38+
const [ searchParams ] = useSearchParams();
39+
const initialQuery = searchParams.get( 'query' ) || '';
40+
const [ inputValue, setInputValue ] = useState( initialQuery );
4541
const messageSizeNotice = useMessageSizeErrorNotice( inputValue.trim().length );
4642
const connectionNotice = useConnectionStatusNotice( isLiveChat );
4743

0 commit comments

Comments
 (0)