Skip to content

Commit

Permalink
Use selectedSite when mouting the URL
Browse files Browse the repository at this point in the history
  • Loading branch information
WBerredo committed Jul 5, 2023
1 parent 739d272 commit 2345522
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions client/my-sites/plugins/search-box-header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import Search from '@automattic/search';
import { useTranslate } from 'i18n-calypso';
import page from 'page';
import { useEffect, useCallback } from 'react';
import { useDispatch } from 'react-redux';
import { useDispatch, useSelector } from 'react-redux';
import { setQueryArgs } from 'calypso/lib/query-args';
import scrollTo from 'calypso/lib/scroll-to';
import { useLocalizedPlugins } from 'calypso/my-sites/plugins/utils';
import { recordGoogleEvent } from 'calypso/state/analytics/actions';
import { resetBreadcrumbs } from 'calypso/state/breadcrumb/actions';
import { getSelectedSite } from 'calypso/state/ui/selectors';
import { useTermsSuggestions } from './useTermsSuggestions';
import './style.scss';

Expand All @@ -20,6 +22,8 @@ const SearchBox = ( {
} ) => {
const dispatch = useDispatch();
const translate = useTranslate();
const selectedSite = useSelector( getSelectedSite );
const { localizePath } = useLocalizedPlugins();

const searchTermSuggestion = useTermsSuggestions( searchTerms ) || 'ecommerce';

Expand All @@ -30,7 +34,7 @@ const SearchBox = ( {
dispatch( resetBreadcrumbs() );
}

page.show( '/plugins' ); // Ensures location.href is on the main Plugins page before setQueryArgs uses it to construct the redirect.
page.show( localizePath( `/plugins/${ selectedSite?.slug || '' }` ) ); // Ensures location.href is on the main Plugins page before setQueryArgs uses it to construct the redirect.
setQueryArgs( '' !== s ? { s } : {} );
searchBoxRef.current.blur();
scrollTo( {
Expand All @@ -41,7 +45,7 @@ const SearchBox = ( {
duration: 300,
} );
},
[ searchBoxRef, categoriesRef, dispatch ]
[ searchBoxRef, categoriesRef, dispatch, selectedSite, localizePath ]
);

const recordSearchEvent = ( eventName ) =>
Expand Down

0 comments on commit 2345522

Please sign in to comment.