Skip to content

Commit

Permalink
Refs #253324; fix edge case when displaying search block with un-init…
Browse files Browse the repository at this point in the history
…ialized search state
  • Loading branch information
tiberiuichim committed Jun 6, 2023
1 parent 2953502 commit 5262b39
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions searchlib/components/SearchApp/SearchApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import qs from 'querystring';

import BasicSearchApp from './BasicSearchApp';

const getParams = (s) => (s ? (s.startsWith('?') ? s.slice(1) : s) : '');

export default function SearchApp(props) {
const locationSearch = __CLIENT__
? qs.parse(window.location.search || '')?.['q']
? qs.parse(getParams(window.location.search))?.['q']
: null;
const defaultSort = locationSearch !== null ? '' : props.defaultSort || '';
const defaultSort = locationSearch ? '' : props.defaultSort || '';
const [sortField, sortDirection] = defaultSort.split('|');

const appConfig = props.registry.searchui[props.appName];
const appDefaultFilters = getDefaultFilters(appConfig);
const [initialState] = React.useState({
Expand All @@ -22,6 +25,17 @@ export default function SearchApp(props) {
...(defaultSort ? { sortField, sortDirection } : {}),
}); // this makes the prop stable

// console.log({
// appConfig,
// props,
// sortField,
// sortDirection,
// locationSearch,
// search: __CLIENT__ ? window.location.search : null,
// parsed: __CLIENT__ ? qs.parse(getParams(window.location.search)) : null,
// initialState,
// });

return (
<BasicSearchApp
{...props}
Expand Down

0 comments on commit 5262b39

Please sign in to comment.