diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b14dcb7..53e00876 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # CHANGELOG +## Not released +- Fix selected store state in sample-app [#142](https://github.com/CartoDB/carto-react-template/pull/142) + ## 1.0.0-beta5 (2020-11-27) - Adapt layout for mobile [#134](https://github.com/CartoDB/carto-react-template/pull/134) - Update favicons for better visibility on dark themes [#136](https://github.com/CartoDB/carto-react-template/pull/136) diff --git a/template-sample-app/template/src/components/views/stores/Stores.js b/template-sample-app/template/src/components/views/stores/Stores.js index 057bee13..d669ed7c 100644 --- a/template-sample-app/template/src/components/views/stores/Stores.js +++ b/template-sample-app/template/src/components/views/stores/Stores.js @@ -34,7 +34,7 @@ export default function Stores() { }) ); // Add layer - dispatch(addLayer({ id: LAYER_ID, source: SOURCE_ID, selectedStore: null })); + dispatch(addLayer({ id: LAYER_ID, source: SOURCE_ID })); // Clean up when leave return function cleanup() { diff --git a/template-sample-app/template/src/components/views/stores/StoresDetail.js b/template-sample-app/template/src/components/views/stores/StoresDetail.js index 6c2c6a45..17e677a0 100644 --- a/template-sample-app/template/src/components/views/stores/StoresDetail.js +++ b/template-sample-app/template/src/components/views/stores/StoresDetail.js @@ -16,10 +16,10 @@ import NavigateNextIcon from '@material-ui/icons/NavigateNext'; import CloseIcon from '@material-ui/icons/Close'; import { WrapperWidgetUI, FormulaWidgetUI, HistogramWidgetUI } from '@carto/react/ui'; -import { selectSourceById, setViewState } from '@carto/react/redux'; +import { updateLayer, selectSourceById, setViewState } from '@carto/react/redux'; import { getStore, getRevenuePerMonth } from 'models/StoreModel'; -import { MONTHS_LABELS } from './constants'; +import { LAYER_ID, MONTHS_LABELS } from './constants'; import { Isochrone } from 'components/common/Isochrone'; import { currencyFormatter } from 'utils/formatter'; import { setError } from 'config/appSlice'; @@ -74,7 +74,11 @@ export default function StoresDetail() { dispatch(setError(`getRevenuePerMonth error: ${error.message}`)); }); - return function cleanup() { + // Set selected store on the layer + dispatch(updateLayer(LAYER_ID, { selectedStore: id })); + + return () => { + dispatch(updateLayer(LAYER_ID, { selectedStore: null })); abortController.abort(); }; }, [dispatch, source, id, location.state]);