Skip to content

Commit

Permalink
check if eventEmitter exists
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanMiu committed Jul 25, 2024
1 parent b36b682 commit d2e244d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const AccordionFacetWrapper = (props) => {

const onChangeFilterType = (v) => {
setLocalFilterType(v);
if (!eventEmitter) return;
eventEmitter.emit('change:filterType', {
field,
type: v,
Expand All @@ -57,6 +58,8 @@ const AccordionFacetWrapper = (props) => {
}, [hasFilter, field, openFacets, updateOpenFacets]);

React.useEffect(() => {
if (!eventEmitter) return;

function changeFilterType(data) {
if (data.field === field) {
setLocalFilterType(data.type);
Expand All @@ -68,7 +71,7 @@ const AccordionFacetWrapper = (props) => {
return () => {
eventEmitter.off('change:filterType', changeFilterType);
};
}, []);
}, [eventEmitter]);

let isOpened = openFacets[field]?.opened || false;
const [counter, setCounter] = React.useState(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,16 @@ const DropdownFacetWrapper = (props) => {

const onChangeFilterType = (v) => {
setLocalFilterType(v);
if (!eventEmitter) return;
eventEmitter.emit('change:filterType', {
field,
type: v,
});
};

React.useEffect(() => {
if (!eventEmitter) return;

function changeFilterType(data) {
if (data.field === field) {
setLocalFilterType(data.type);
Expand All @@ -83,7 +86,7 @@ const DropdownFacetWrapper = (props) => {
return () => {
eventEmitter.off('change:filterType', changeFilterType);
};
}, []);
}, [eventEmitter]);

const { width } = useWindowDimensions();
const isSmallScreen = width < SMALL_SCREEN_SIZE;
Expand Down

0 comments on commit d2e244d

Please sign in to comment.