Skip to content

Commit

Permalink
Checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed Dec 29, 2022
1 parent 65f8ee8 commit c185304
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 57 deletions.
16 changes: 8 additions & 8 deletions searchlib/components/SearchApp/BasicSearchApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import useDeepCompareEffect from 'use-deep-compare-effect';
import { AppConfigContext, SearchContext } from '@eeacms/search/lib/hocs';
import { bindOnAutocomplete, bindOnSearch } from '@eeacms/search/lib/request';
import useSearchApp from './useSearchApp';
import useWhyDidYouUpdate from '@eeacms/search/lib/hocs/useWhyDidYouUpdate';
// import useWhyDidYouUpdate from '@eeacms/search/lib/hocs/useWhyDidYouUpdate';

function applySearchWrappers(SearchViewComponent) {
function SearchWrapper(props) {
Expand All @@ -27,7 +27,7 @@ function applySearchWrappers(SearchViewComponent) {
} = props;

const [payload, update] = React.useState(appConfigContext);
React.useEffect(() => () => console.log('unmount SearchWrappers'), []);
// React.useEffect(() => () => console.log('unmount SearchWrappers'), []);

return (
<AppConfigContext.Provider value={{ payload, update }}>
Expand Down Expand Up @@ -91,12 +91,12 @@ export default function BasicSearchApp(props) {
return mappedWithSearch(applySearchWrappers(searchViewComponent));
}, [mappedWithSearch, searchViewComponent]);

useWhyDidYouUpdate('BasicSearchApp', {
mapContextToProps,
searchViewComponent,
WrappedSearchView,
registry,
});
// useWhyDidYouUpdate('BasicSearchApp', {
// mapContextToProps,
// searchViewComponent,
// WrappedSearchView,
// registry,
// });

return driverInstance ? (
<SearchProvider config={elasticConfig} driver={driverInstance}>
Expand Down
12 changes: 6 additions & 6 deletions searchlib/components/SearchApp/useSearchApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { resetFilters, resetSearch } from './request';
import useFacetsWithAllOptions from './useFacetsWithAllOptions';
import { loadingFamily, driverFamily } from './state';
import useWhyDidYouUpdate from '@eeacms/search/lib/hocs/useWhyDidYouUpdate';
// import useWhyDidYouUpdate from '@eeacms/search/lib/hocs/useWhyDidYouUpdate';

export function useSearchDriver({ elasticConfig, appName }) {
const driverAtom = driverFamily({ elasticConfig, appName });
Expand Down Expand Up @@ -115,11 +115,11 @@ export default function useSearchApp({
[appConfig, driverInstance, facetOptions],
);

useWhyDidYouUpdate('useSearchApp', {
appConfig,
driverInstance,
facetOptions,
});
// useWhyDidYouUpdate('useSearchApp', {
// appConfig,
// driverInstance,
// facetOptions,
// });

return {
facetOptions,
Expand Down
2 changes: 1 addition & 1 deletion searchlib/components/SearchView/SearchView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const SearchView = (props) => {

const customClassName = !wasInteracted ? 'landing-page' : 'simple-page';

React.useEffect(() => () => console.log('unmount SearchView'), []);
// React.useEffect(() => () => console.log('unmount SearchView'), []);
return (
<div className={`searchapp searchapp-${appName} ${customClassName}`}>
<Layout
Expand Down
1 change: 1 addition & 0 deletions src/SearchBlock/BlockContainer/BlockContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default function BlockContainer(props) {
onChangeBlock={onChangeSlotfill}
onSelectBlock={() => {}}
index={index}
disableNewBlocks={true}
/>
</>
) : (
Expand Down
10 changes: 6 additions & 4 deletions src/SearchBlock/SearchBlockEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { BlockDataForm, SidebarPortal } from '@plone/volto/components';
import SearchBlockView from './SearchBlockView';
import config from '@plone/volto/registry';
import { useDebouncedStableData } from './hocs';
import useWhyDidYouUpdate from '@eeacms/search/lib/hocs/useWhyDidYouUpdate';
// import useWhyDidYouUpdate from '@eeacms/search/lib/hocs/useWhyDidYouUpdate';

const SearchBlockEdit = (props) => {
const { onChangeBlock, block, data } = props;
const [selectedSlotFill, onSelectSlotfill] = React.useState();

const stableData = useDebouncedStableData(
Object.assign(
Expand Down Expand Up @@ -53,8 +54,6 @@ const SearchBlockEdit = (props) => {
[block, data, onChangeBlock],
);

React.useEffect(() => () => console.log('unmount SearchBlockEdit'), []);

const onDeleteSlotfill = React.useCallback(
(slotId) => {
onChangeBlock(block, {
Expand All @@ -68,7 +67,8 @@ const SearchBlockEdit = (props) => {
[block, onChangeBlock, data],
);

useWhyDidYouUpdate('SearchBlockEdit', { schema });
// React.useEffect(() => () => console.log('unmount SearchBlockEdit'), []);
// useWhyDidYouUpdate('SearchBlockEdit', { schema });

return (
<div>
Expand All @@ -77,6 +77,8 @@ const SearchBlockEdit = (props) => {
mode="edit"
onChangeSlotfill={onChangeSlotfill}
onDeleteSlotfill={onDeleteSlotfill}
onSelectSlotfill={onSelectSlotfill}
selectedSlotFill={selectedSlotFill}
>
<SidebarPortal selected={props.selected}>
<BlockDataForm
Expand Down
2 changes: 1 addition & 1 deletion src/SearchBlock/SearchBlockView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function SearchBlockView(props) {
}, [appName, stableData, schema, mode]);

const Variation = variation.view;
React.useEffect(() => () => console.log('unmount SearchBlockView'), []);
// React.useEffect(() => () => console.log('unmount SearchBlockView'), []);

return (
<div>
Expand Down
99 changes: 63 additions & 36 deletions src/SearchBlock/templates/FullView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,59 @@ const overlayStyle = {
zIndex: '100',
};

const slots = [
'aboveSearchInput',
'belowSearchInput',
'aboveResults',
'belowResults',
];

// aboveSearchInput={
// <BlockContainer
// block="aboveSearchInput"
// data={slotFills?.['aboveSearchInput']}
// mode={mode}
// onChangeSlotfill={onChangeSlotfill}
// onDeleteSlotfill={onDeleteSlotfill}
// />
// }
// belowSearchInput={
// <BlockContainer
// block="belowSearchInput"
// data={slotFills?.['belowSearchInput']}
// mode={mode}
// onChangeSlotfill={onChangeSlotfill}
// onDeleteSlotfill={onDeleteSlotfill}
// />
// }
// aboveResults={
// <BlockContainer
// block="aboveResults"
// data={slotFills?.['aboveResults']}
// mode={mode}
// onChangeSlotfill={onChangeSlotfill}
// onDeleteSlotfill={onDeleteSlotfill}
// />
// }
// belowResults={
// <BlockContainer
// block="belowResults"
// data={slotFills?.['belowResults']}
// mode={mode}
// onChangeSlotfill={onChangeSlotfill}
// onDeleteSlotfill={onDeleteSlotfill}
// />
// }

function FullView(props) {
const {
appName,
mode,
slotFills,
onChangeSlotfill,
onDeleteSlotfill,
onSelectSlotfill,
selectedSlotFill,
} = props;

// TODO: (about bodyclass) this is a hack, please solve it properly
Expand All @@ -29,42 +75,23 @@ function FullView(props) {
)}
<SearchApp
{...props}
aboveSearchInput={
<BlockContainer
block="aboveSearchInput"
data={slotFills?.['aboveSearchInput']}
mode={mode}
onChangeSlotfill={onChangeSlotfill}
onDeleteSlotfill={onDeleteSlotfill}
/>
}
belowSearchInput={
<BlockContainer
block="belowSearchInput"
data={slotFills?.['belowSearchInput']}
mode={mode}
onChangeSlotfill={onChangeSlotfill}
onDeleteSlotfill={onDeleteSlotfill}
/>
}
aboveResults={
<BlockContainer
block="aboveResults"
data={slotFills?.['aboveResults']}
mode={mode}
onChangeSlotfill={onChangeSlotfill}
onDeleteSlotfill={onDeleteSlotfill}
/>
}
belowResults={
<BlockContainer
block="belowResults"
data={slotFills?.['belowResults']}
mode={mode}
onChangeSlotfill={onChangeSlotfill}
onDeleteSlotfill={onDeleteSlotfill}
/>
}
{...Object.assign(
{},
...slots.map((name) => ({
[name]: (
<BlockContainer
key={name}
block={name}
data={slotFills?.[name]}
mode={mode}
onChangeSlotfill={onChangeSlotfill}
onDeleteSlotfill={onDeleteSlotfill}
onSelectSlotfill={onSelectSlotfill}
selected={selectedSlotFill === name}
/>
),
})),
)}
/>
{props.children}
</div>
Expand Down
5 changes: 4 additions & 1 deletion src/SearchBlock/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@ const _applyBlockSettings = (config, appName, data, schema) => {
let _params, _cachedResult;

const cacheOnce = (func) => (config, appName, data, schema) => {
// Because React uses object identity to recreate components, we try to
// create a stable version of the "registry" by only producing it again if
// the data has changed
if (!_params || !isEqual(_params, { appName, data })) {
_cachedResult = _applyBlockSettings(config, appName, data, schema);
_params = { appName, data };
console.log('recomputed');
// console.log('recomputed');
}
return _cachedResult;
};
Expand Down

0 comments on commit c185304

Please sign in to comment.