Skip to content

Commit

Permalink
Checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed Jan 3, 2023
1 parent 3550b68 commit 5135d1a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
23 changes: 22 additions & 1 deletion searchlib/components/SearchApp/LandingPageApp.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
import React from 'react';
import BasicSearchApp from './BasicSearchApp';
import { useSearchDriver } from '@eeacms/search/lib/hocs';
import { stateToQueryString } from '@eeacms/search';

function BoostrapLandingPageView(props) {
const { appConfig, registry } = props;
const { appConfig, registry, onSubmitSearch } = props;

const InitialViewComponent =
appConfig.initialView?.factory &&
registry.resolve[appConfig.initialView.factory].component;

const driver = useSearchDriver();
const timerRef = React.useRef();

React.useEffect(() => {
function handler(state) {
timerRef.current && clearTimeout(timerRef.current);
timerRef.current = setTimeout(() => {
onSubmitSearch(stateToQueryString(state));
}, 200);
}

if (driver && onSubmitSearch) {
driver.subscriptions.push(handler);
}

return () => timerRef.current && clearTimeout(timerRef.current);
}, [driver, onSubmitSearch]);

return <InitialViewComponent {...props} />;
}

Expand Down
4 changes: 4 additions & 0 deletions searchlib/components/SearchApp/useSearchApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ export default function useSearchApp({
: {}),
...(initialState || {}),
},
// we don't want to track the URL if our search app is configured as
// a simple separate app (for ex. search input or landing page that
// trampolines to another instance)
trackUrlState: appConfig.url ? false : appConfig.trackUrlState,
}),
[appConfig, onAutocomplete, onSearch, locationSearchTerm, initialState],
);
Expand Down
1 change: 1 addition & 0 deletions searchlib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export * from './lib/utils';
export * from './lib/hocs';
export * from './lib/search';
export * from './lib/models';
export * from './lib/serialize';
export * from './state';
export * from './constants';

Expand Down
19 changes: 18 additions & 1 deletion src/SearchBlock/templates/LandingPageView.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import React from 'react';
import { LandingPageApp } from '@eeacms/search';
import { useHistory } from 'react-router-dom';
import { flattenToAppURL } from '@plone/volto/helpers';

function LandingPageView(props) {
const history = useHistory();
const { registry, appName } = props;
const appConfig = registry.searchui[appName];
const url = flattenToAppURL(appConfig.url || '');

return (
<>
<LandingPageApp {...props} />
<LandingPageApp
{...props}
onSubmitSearch={
url
? (qs) => {
history.push(`${url}?${qs}`);
}
: null
}
/>
{props.children}
</>
);
Expand All @@ -15,6 +31,7 @@ LandingPageView.schemaEnhancer = ({ schema }) => {
schema.properties.url = {
title: 'Results page',
widget: 'url',
configPath: 'url',
};

return schema;
Expand Down

0 comments on commit 5135d1a

Please sign in to comment.