Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 0 additions & 97 deletions frontend/src/components/Categories/CategoriesContext.jsx

This file was deleted.

24 changes: 10 additions & 14 deletions frontend/src/components/FiltersForm/FiltersForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React from 'react';
import styled, { keyframes } from 'styled-components';
import { useTranslation } from 'react-i18next';
import { Tooltip } from '@mui/material';
import { useCategories } from '../Categories/CategoriesContext';
import { useDeploymentData } from '../../context/DeploymentDataContext';
import { useFilters } from '../../context/FiltersContext';
import FiltersTooltip from './FiltersTooltip';

const shimmer = keyframes`
Expand Down Expand Up @@ -241,20 +242,15 @@ const LoadingSkeleton = () => (

const FiltersForm = () => {
const { t } = useTranslation();
const {
categories: selectedFilters,
setCategories,
categoriesData,
isLoading,
hasError,
refetchCategories,
} = useCategories();
const { categoriesData, categoriesLoading, categoriesError, refetchCategories } =
useDeploymentData();
const { selectedFilters, setSelectedFilters } = useFilters();

const handleCheckboxChange = event => {
const { value, checked } = event.target;
const { category } = event.target.dataset;

setCategories(prevSelectedFilters => {
setSelectedFilters(prevSelectedFilters => {
const newSelectedFilters = { ...prevSelectedFilters };

if (checked) {
Expand All @@ -275,14 +271,14 @@ const FiltersForm = () => {
const { value } = event.target;
const { category } = event.target.dataset;

setCategories(prevSelectedFilters => ({
setSelectedFilters(prevSelectedFilters => ({
...prevSelectedFilters,
[category]: [value],
}));
};

const handleClearFilters = () => {
setCategories({});
setSelectedFilters({});
};

const renderModeBadge = mode => {
Expand Down Expand Up @@ -423,15 +419,15 @@ const FiltersForm = () => {
);
}

if (isLoading) {
if (categoriesLoading) {
return (
<form>
<LoadingSkeleton />
</form>
);
}

if (hasError) {
if (categoriesError) {
return (
<form>
<ErrorMessage>{t('loadFiltersError')}</ErrorMessage>
Expand Down
19 changes: 12 additions & 7 deletions frontend/src/components/Map/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import { createPortal } from 'react-dom';
import FiltersForm from '../FiltersForm/FiltersForm';
import MapComponent from './MapComponent';
import { CategoriesProvider } from '../Categories/CategoriesContext';
import { DeploymentDataProvider } from '../../context/DeploymentDataContext';
import { FiltersProvider } from '../../context/FiltersContext';
import AppToaster from '../common/AppToaster';

/**
* Wrapper component that renders the map and filters form into their respective DOM placeholders.
* Uses React portals to render components into pre-existing DOM elements outside the React tree.
* Wraps both components with CategoriesProvider for shared filter state management.
* Wraps both components with DeploymentDataProvider, which fetches this deployment's
* fixed data (category definitions and the new-point schema) once for every consumer,
* and with FiltersProvider, which owns the one thing that changes as the app runs.
*
* @returns {React.ReactElement|null} Portals for FiltersForm and MapComponent, or null if placeholders not found
*/
Expand All @@ -18,16 +21,18 @@
const filtersPlaceholder = document.getElementById('filter-form');

if (!filtersPlaceholder || !mapPlaceholder) {
console.error('Did not find any DOM elements to render the map or filters form');

Check warning on line 24 in frontend/src/components/Map/Map.jsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
return null;
}

return (
<CategoriesProvider>
<AppToaster />
{createPortal(<FiltersForm />, filtersPlaceholder)}
{createPortal(<MapComponent />, mapPlaceholder)}
</CategoriesProvider>
<DeploymentDataProvider>
<FiltersProvider>
<AppToaster />
{createPortal(<FiltersForm />, filtersPlaceholder)}
{createPortal(<MapComponent />, mapPlaceholder)}
</FiltersProvider>
</DeploymentDataProvider>
);
};

Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/Map/components/AccessibilityTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import PropTypes from 'prop-types';
import httpService from '../../../services/http/httpService';
import FieldRenderer from '../../MarkerPopup/FieldRenderer';
import { useCategories } from '../../Categories/CategoriesContext';
import { useFilters } from '../../../context/FiltersContext';

/**
* Accessibility table component that displays location data in a tabular format.
Expand All @@ -28,7 +28,7 @@
* @returns {React.ReactElement} Table container with location data and back button
*/
const AccessibilityTable = ({ userPosition, setIsAccessibilityTableOpen }) => {
const { categories } = useCategories();
const { selectedFilters } = useFilters();
const { t } = useTranslation();

const [data, setData] = useState(null);
Expand All @@ -37,11 +37,11 @@

useEffect(() => {
httpService
.getLocationsData(userPosition.lat, userPosition.lng, categories)
.getLocationsData(userPosition.lat, userPosition.lng, selectedFilters)
.then(places => {
setData(places);
});
}, [categories, userPosition]);
}, [selectedFilters, userPosition]);

useEffect(() => {
if (!data) {
Expand Down Expand Up @@ -73,7 +73,7 @@
});
setRows(rowsLocal);
} catch (error) {
console.log('AccessibilityTable: ', error);

Check warning on line 76 in frontend/src/components/Map/components/AccessibilityTable.jsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
}
}, [data, t]);

Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/Map/components/Markers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import MarkerClusterGroup from 'react-leaflet-cluster';
import httpService from '../../../services/http/httpService';
import MarkerPopup from '../../MarkerPopup/MarkerPopup';
import { useCategories } from '../../Categories/CategoriesContext';
import { useFilters } from '../../../context/FiltersContext';
import ClusterMarker from '../../MarkerPopup/ClusterMarker';

/**
Expand Down Expand Up @@ -44,7 +44,7 @@
* @returns {React.ReactElement|Array} MarkerClusterGroup containing location markers, or empty array while loading
*/
const Markers = ({ onLoadingChange = null }) => {
const { categories, isInitialized } = useCategories();
const { selectedFilters, isInitialized } = useFilters();
const [markers, setMarkers] = useState([]);
const [areMarkersLoaded, setAreMarkersLoaded] = useState(false);
const map = useMap();
Expand All @@ -59,9 +59,9 @@
const fetchMarkers = async () => {
let locations;
try {
locations = await httpService.getLocations(categories);
locations = await httpService.getLocations(selectedFilters);
} catch (error) {
console.error('Failed to load locations:', error);

Check warning on line 64 in frontend/src/components/Map/components/Markers.jsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
setMarkers([]);
setAreMarkersLoaded(true);
return;
Expand Down Expand Up @@ -100,7 +100,7 @@
return () => {
setMarkers([]);
};
}, [categories, isInitialized]);
}, [selectedFilters, isInitialized]);

useEffect(() => {
const mapContainer = map.getContainer();
Expand Down
Loading
Loading