diff --git a/frontend/src/components/map-view/MapContainer.js b/frontend/src/components/map-view/MapContainer.js index 67b8f27..feffe00 100644 --- a/frontend/src/components/map-view/MapContainer.js +++ b/frontend/src/components/map-view/MapContainer.js @@ -141,52 +141,59 @@ const MapContainer = (props) => { }; const facetSearch = (name, value, checked) => { - let facet = name + ":" + '"' + value + '"'; - let isKeyContained = false; - let queryResult = ""; + try { + let facet = name + ":" + '"' + value + '"'; + let isKeyContained = false; + let queryResult = ""; - if (checked) { - if (facetQuery) { + if (checked) { + if (facetQuery) { + const pairs = facetQuery.split(" AND "); + pairs.forEach((p) => { + if (p.includes(name)) { + isKeyContained = true; + let temp = + "(" + + [p.replace(/^\(|\)$/g, ""), facet] + .filter((e) => e) + .join(" OR ") + + ")"; + queryResult = [queryResult, temp].filter((e) => e).join(" AND "); + } else { + queryResult = [queryResult, p].filter((e) => e).join(" AND "); + } + }); + if (!isKeyContained) + queryResult = [queryResult, "(" + facet + ")"] + .filter((e) => e) + .join(" AND "); + } else { + queryResult = + "(" + [queryResult, facet].filter((e) => e).join(" OR ") + ")"; + } + } else { const pairs = facetQuery.split(" AND "); pairs.forEach((p) => { if (p.includes(name)) { - isKeyContained = true; - let temp = - "(" + - [p.replace(/^\(|\)$/g, ""), facet].filter((e) => e).join(" OR ") + - ")"; - queryResult = [queryResult, temp].filter((e) => e).join(" AND "); + const temp = p + .replace(/^\(|\)$/g, "") + .split(" OR ") + .filter((f) => f !== facet) + .join(" OR "); + + queryResult = [queryResult, temp === "" ? temp : "(" + temp + ")"] + .filter((e) => e) + .join(" AND "); } else { queryResult = [queryResult, p].filter((e) => e).join(" AND "); } }); - if (!isKeyContained) - queryResult = [queryResult, "(" + facet + ")"] - .filter((e) => e) - .join(" AND "); - } else { - queryResult = - "(" + [queryResult, facet].filter((e) => e).join(" OR ") + ")"; } - } else { - const pairs = facetQuery.split(" AND "); - pairs.forEach((p) => { - if (p.includes(name)) { - const temp = p - .replace(/^\(|\)$/g, "") - .split(" OR ") - .filter((f) => f !== facet) - .join(" OR "); - - queryResult = [queryResult, temp === "" ? temp : "(" + temp + ")"] - .filter((e) => e) - .join(" AND "); - } else { - queryResult = [queryResult, p].filter((e) => e).join(" AND "); - } - }); + setFacetQuery(queryResult); + } catch (error) { + } - setFacetQuery(queryResult); + }; const getGeoJSON = (bounds) => { diff --git a/frontend/src/components/map-view/components/desktop/ToolbarDesktopMapView.js b/frontend/src/components/map-view/components/desktop/ToolbarDesktopMapView.js index 7e87234..2c045ad 100644 --- a/frontend/src/components/map-view/components/desktop/ToolbarDesktopMapView.js +++ b/frontend/src/components/map-view/components/desktop/ToolbarDesktopMapView.js @@ -72,26 +72,31 @@ const ToolbarDesktopMapView = (props) => { }; useEffect(() => { - if (facetQuery) { - const pairs = facetQuery.split(" AND "); - const extractedPairs = []; + try { + if (facetQuery) { + const pairs = facetQuery.split(" AND "); + const extractedPairs = []; - pairs.forEach((p) => { - const temp = p.replace(/^\(|\)$/g, ""); - const tempPairs = temp.split(" OR "); - tempPairs.forEach((t) => { - let index = t.indexOf(":"); - let facetType = t.substring(0, index); - let facetName = t.substring(index + 1).slice(1, -1); - /* const splitted = t.split(":"); + pairs.forEach((p) => { + const temp = p.replace(/^\(|\)$/g, ""); + const tempPairs = temp.split(" OR "); + tempPairs.forEach((t) => { + let index = t.indexOf(":"); + let facetType = t.substring(0, index); + let facetName = t.substring(index + 1).slice(1, -1); + /* const splitted = t.split(":"); const facetType = splitted[0]; const facetName = splitted[1].replace(/"/g, ""); */ - extractedPairs.push({ name: facetType, value: facetName }); - }); - }); + extractedPairs.push({ name: facetType, value: facetName }); + }); + }); - setSelectedFacets(extractedPairs); + setSelectedFacets(extractedPairs); + } + } catch (error) { + console.log(error) } + }, [facetQuery, setSelectedFacets]); const handleInputChange = (value, name) => { diff --git a/frontend/src/components/search-hub/Results.js b/frontend/src/components/search-hub/Results.js index 225cfb7..014512c 100644 --- a/frontend/src/components/search-hub/Results.js +++ b/frontend/src/components/search-hub/Results.js @@ -92,9 +92,16 @@ export default function Results() { let counterResult = 0; useEffect(() => { - const category = CATEGORIES.find((category) => category.id === searchType); + try { + const category = CATEGORIES.find( + (category) => category.id === searchType + ); - setMobileAppliedFilters([{ type: "searchType", text: category.text }]); + setMobileAppliedFilters([{ type: "searchType", text: category.text }]); + } catch (error) { + + } + }, [searchType]); useEffect(() => {