Skip to content

Commit

Permalink
WIP on splitting components
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed Dec 19, 2022
1 parent a890e6c commit 2173559
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 2 additions & 0 deletions searchlib/components/SearchApp/BasicSearchApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default function BasicSearchApp(props) {
paramOnSearch = bindOnSearch,
paramOnAutocomplete = bindOnAutocomplete,
searchViewComponent,
...rest
} = props;

const {
Expand All @@ -76,6 +77,7 @@ export default function BasicSearchApp(props) {
return driverInstance ? (
<SearchProvider config={elasticConfig} driver={driverInstance}>
<WrappedSearchView
{...rest}
appConfig={appConfig}
appConfigContext={appConfigContext}
appName={appName}
Expand Down
6 changes: 3 additions & 3 deletions searchlib/components/SearchApp/SearchInputApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ const SearchInputView = (props) => {
mode = 'view',
appConfigContext,
appConfig,
onSubmitSearch,
...searchContext
} = props;

const onSubmit = appConfig.url
? (searchTerm) => {
console.log('submit', searchTerm);
onSubmitSearch(searchTerm);
}
: undefined;

const onSelectAutocomplete = appConfig.url
? (selection, options) => {
console.log('onselect', selection, options, searchContext);
searchContext.setSearchTerm(selection.suggestion);
}
: undefined;
Expand Down Expand Up @@ -61,7 +61,7 @@ const SearchInputViewWrapper = (props) => {
);
};

export default function SearchApp(props) {
export default function SearchInputApp(props) {
return (
<BasicSearchApp {...props} searchViewComponent={SearchInputViewWrapper} />
);
Expand Down
4 changes: 2 additions & 2 deletions searchlib/components/SearchApp/useSearchApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ export default function useSearchApp({

const onSearch = React.useCallback(
async (state) => {
if (appConfig.url) return {}; // we don't do onSearch if we rely on another page to do the search

setIsLoading(true);
// console.log('searching', state);
const res = await paramOnSearch(appConfig)(state);
// console.log('search done', res);
setIsLoading(false);
return res;
},
Expand Down
19 changes: 17 additions & 2 deletions src/SearchBlock/templates/SearchInputView.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
import { SearchInputApp } from '@eeacms/search';
import React from 'react';

import { SearchInputApp } from '@eeacms/search';
import { useHistory } from 'react-router-dom';
import { flattenToAppURL } from '@plone/volto/helpers';

function SearchInputView(props) {
return <SearchInputApp {...props} />;
const { registry, appName } = props;
const history = useHistory();
const appConfig = registry.searchui[appName];
const url = flattenToAppURL(appConfig.url || '');

return (
<SearchInputApp
{...props}
onSubmitSearch={(searchTerm) => {
history.push(`${url}?q=${searchTerm}`);
}}
/>
);
}

SearchInputView.schemaEnhancer = ({ schema }) => {
Expand Down

0 comments on commit 2173559

Please sign in to comment.