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 0ff59f1 commit 4137380
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions searchlib/components/SearchApp/useSearchApp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';

import { useAtom, useAtomValue } from 'jotai';
import useDeepCompareEffect from 'use-deep-compare-effect';
// import { useResetAtom } from 'jotai/utils';

import {
getDefaultFilters,
Expand All @@ -15,14 +17,22 @@ import {
import { resetFilters, resetSearch } from './request';
import useFacetsWithAllOptions from './useFacetsWithAllOptions';
import { loadingFamily, driverFamily } from './state';
import { SearchDriver } from '@elastic/search-ui';
// import useWhyDidYouUpdate from '@eeacms/search/lib/hocs/useWhyDidYouUpdate';

export function useStoredSearchDriver({ elasticConfig, appName, uniqueId }) {
const driverAtom = driverFamily({ elasticConfig, appName, uniqueId });
const driver = useAtomValue(driverAtom);
// const driverAtom = driverFamily({ elasticConfig, appName, uniqueId });
// const driver = useAtomValue(driverAtom);

const [driver, setDriver] = React.useState(null);

useDeepCompareEffect(() => {
console.log('new searchdriver', appName);
setDriver(new SearchDriver(elasticConfig));
}, [elasticConfig, appName]);

React.useEffect(() => {
return () => driver.tearDown();
return () => driver && driver.tearDown();
}, [driver]);

return driver;
Expand Down Expand Up @@ -130,6 +140,17 @@ export default function useSearchApp({
// facetOptions,
// });

const { url } = appConfig;
React.useEffect(
() => () => {
if (!url) {
console.log('unmount useSearchApp', appName, driverInstance);
// driverInstance.reset();
}
},
[appName, driverInstance, url],
);

return {
facetOptions,
mapContextToProps,
Expand Down

0 comments on commit 4137380

Please sign in to comment.