Skip to content

Commit

Permalink
fix: removed dispatch, left old implementation together with new ones…
Browse files Browse the repository at this point in the history
… for custom paths
  • Loading branch information
pnicolli committed Nov 14, 2023
1 parent afb473f commit ad09ea1
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/components/ItaliaTheme/View/Commons/SearchSectionForm.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { defineMessages, useIntl } from 'react-intl';
import { useSelector, useDispatch } from 'react-redux';
import React, { useState, useEffect } from 'react';
import { useSelector } from 'react-redux';
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { Button } from 'design-react-kit';
import { getSearchFilters } from 'design-comuni-plone-theme/actions';
import { flattenToAppURL } from '@plone/volto/helpers';
import { SearchUtils } from 'design-comuni-plone-theme/components';
import { Icon } from 'design-comuni-plone-theme/components/ItaliaTheme';

Expand All @@ -27,18 +27,12 @@ const messages = defineMessages({
});

const SearchSectionForm = ({ content }) => {
const dispatch = useDispatch();
const intl = useIntl();
const path = content['@id'];
const searchFilters = useSelector(
(state) => state?.searchFilters?.result?.sections,
);

useEffect(() => {
if (!searchFilters || Object.keys(searchFilters).length === 0)
dispatch(getSearchFilters());
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const customPath = [];

const sections = searchFilters?.[0]?.items ?? [];
Expand All @@ -48,13 +42,13 @@ const SearchSectionForm = ({ content }) => {
return;
} else {
if (path === section['@id']) {
customPath.push(section.items.map((item) => item['@id']));
customPath.push(
section.items.map((item) => flattenToAppURL(item['@id'])),
);
}
}
});

const intl = useIntl();

const subsite = useSelector((state) => state.subsite?.data);
const [searchableText, setSearchableText] = useState('');
const doSearch = (e) => {
Expand All @@ -74,7 +68,10 @@ const SearchSectionForm = ({ content }) => {
subsite,
intl.locale,
false,
);
) +
(customPath.length === 0
? `&custom_path=${flattenToAppURL(path)}`
: '');
}
};
return (
Expand Down

0 comments on commit ad09ea1

Please sign in to comment.