Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed Jan 3, 2023
1 parent 4137380 commit fb99ebc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 28 deletions.
10 changes: 0 additions & 10 deletions searchlib/components/SearchApp/state.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import { atom } from 'jotai';
import { atomFamily } from 'jotai/utils';
import { SearchDriver } from '@elastic/search-ui';

export const loadingFamily = atomFamily(
() => atom(),
(a, b) => a.appName === b.appName,
);

export const driverFamily = atomFamily(
({ elasticConfig, appName, uniqueId }) => {
const driver = __CLIENT__ ? new SearchDriver(elasticConfig) : null;
// console.log('new driver', elasticConfig, appName, uniqueId);
return atom(driver);
},
(a, b) => `${a.appName}-${a.uniqueId}` === `${b.appName}-${b.uniqueId}`,
);
22 changes: 5 additions & 17 deletions searchlib/components/SearchApp/useSearchApp.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from 'react';

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

import {
getDefaultFilters,
Expand All @@ -16,18 +15,14 @@ import {

import { resetFilters, resetSearch } from './request';
import useFacetsWithAllOptions from './useFacetsWithAllOptions';
import { loadingFamily, driverFamily } from './state';
import { loadingFamily } 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 [driver, setDriver] = React.useState(null);

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

Expand Down Expand Up @@ -140,16 +135,9 @@ export default function useSearchApp({
// facetOptions,
// });

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

return {
facetOptions,
Expand Down
1 change: 0 additions & 1 deletion src/SearchBlock/templates/LandingPageView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ function LandingPageView(props) {
onSubmitSearch={
url
? (qs) => {
// window.location = `${url}?${qs}`;
history.push(`${url}?${qs}`);
}
: null
Expand Down

0 comments on commit fb99ebc

Please sign in to comment.