Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed Mar 6, 2023
1 parent 37269f2 commit 2a88bf2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
27 changes: 17 additions & 10 deletions searchlib/components/SearchView/BackToHome.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Link, useLocation } from 'react-router-dom';
import React from 'react';
import { SearchContext as SUISearchContext } from '@elastic/react-search-ui';
import { Link, useHistory } from 'react-router-dom';
import { Icon } from 'semantic-ui-react';

export default function BackToHome({
Expand All @@ -17,12 +19,13 @@ export default function BackToHome({
backToHome = url.pathname;
}
}
const location = useLocation();
const history = useHistory();

const isLocal = backToHome && location.pathname === backToHome;
const isLocal = backToHome && history.location.pathname === backToHome;
const { driver } = React.useContext(SUISearchContext);

const resetSearch = (e) => {
e.preventDefault();
driver.URLManager.history.replace(history.location.pathname);
resetInteracted();
searchContext.resetSearch({});
};
Expand All @@ -36,8 +39,7 @@ export default function BackToHome({
className="back-link"
onClick={() => {
if (isLocal) {
searchContext.resetSearch({});
resetInteracted();
resetSearch();
}
}}
>
Expand All @@ -50,8 +52,7 @@ export default function BackToHome({
className="back-link"
onClick={() => {
if (isLocal) {
searchContext.resetSearch({});
resetInteracted();
resetSearch();
}
}}
>
Expand All @@ -63,8 +64,14 @@ export default function BackToHome({
<a
className="back-link"
as="a"
onClick={resetSearch}
onKeyDown={resetSearch}
onClick={(e) => {
resetSearch();
e.preventDefault();
}}
onKeyDown={(e) => {
resetSearch();
e.preventDefault();
}}
role="button"
href="./"
>
Expand Down
28 changes: 27 additions & 1 deletion searchlib/components/SearchView/SearchView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,32 @@ const useWasInteracted = ({ searchedTerm, searchContext, appConfig }) => {
);

React.useEffect(() => {
if (wasInteracted && !cached) setCached(true);
if (wasInteracted && !cached) {
setCached(true);
}
// else if (!wasInteracted && cached === true) {
// setCached(false);
// }
}, [wasInteracted, cached]);

const resetInteracted = React.useCallback(() => {
console.log('reset');
setCached(false);
}, []);

// console.log('wasInteracted', {
// wasInteracted,
// searchedTerm,
//
// check: checkInteracted({
// searchContext,
// appConfig,
// }),
// cached,
// });

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

return {
wasInteracted: cached || wasInteracted,
resetInteracted,
Expand All @@ -51,6 +70,7 @@ const useWasInteracted = ({ searchedTerm, searchContext, appConfig }) => {

export const SearchView = (props) => {
const { appConfig, appName, mode = 'view' } = props;
// React.useEffect(() => () => console.log('unmount searchview'), []);

const searchContext = useSearchContext();
const { driver } = React.useContext(SUISearchContext);
Expand All @@ -68,6 +88,12 @@ export const SearchView = (props) => {
appConfig,
});

// console.log(
// 'searchedTerm',
// `-[${searchedTerm}]-[${searchContext.searchTerm}]-`,
// wasInteracted,
// );

React.useEffect(() => {
window.searchContext = searchContext;
}, [searchContext]);
Expand Down

0 comments on commit 2a88bf2

Please sign in to comment.