Skip to content

Commit

Permalink
feat: Change map style from chapter
Browse files Browse the repository at this point in the history
  • Loading branch information
josebui committed Apr 11, 2024
1 parent 8556066 commit ef97006
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
22 changes: 19 additions & 3 deletions src/storyMap/components/StoryMapForm/ChapterForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import _ from 'lodash/fp';
import { useTranslation } from 'react-i18next';
import AlignHorizontalCenterIcon from '@mui/icons-material/AlignHorizontalCenter';
import AlignHorizontalLeftIcon from '@mui/icons-material/AlignHorizontalLeft';
Expand Down Expand Up @@ -50,7 +51,13 @@ const ConfigButton = withProps(IconButton, {
});
const ChapterConfig = props => {
const { t } = useTranslation();
const { onAlignmentChange, chapter, onLocationChange, children } = props;
const {
onAlignmentChange,
chapter,
onLocationChange,
onMapStyleChange,
children,
} = props;
const [locationOpen, setLocationOpen] = useState(false);

const options = useMemo(
Expand Down Expand Up @@ -83,11 +90,12 @@ const ChapterConfig = props => {
}, []);

const onLocationChangeWrapper = useCallback(
location => {
(location, mapStyle) => {
onLocationChange(location);
onMapStyleChange(mapStyle);
onLocationClose();
},
[onLocationChange, onLocationClose]
[onLocationChange, onLocationClose, onMapStyleChange]
);

const hasVisualMedia = chapterHasVisualMedia(chapter);
Expand Down Expand Up @@ -171,6 +179,13 @@ const ChapterForm = ({ theme, record }) => {
[record.id, setConfig]
);

const onMapStyleChange = useCallback(
style => {
setConfig(_.set('style', style));
},
[setConfig]
);

return (
<Box
className={classList}
Expand All @@ -186,6 +201,7 @@ const ChapterForm = ({ theme, record }) => {
chapter={record}
onAlignmentChange={onFieldChange('alignment')}
onLocationChange={onFieldChange('location')}
onMapStyleChange={onMapStyleChange}
>
<Stack
className={`${theme} step-content`}
Expand Down
15 changes: 11 additions & 4 deletions src/storyMap/components/StoryMapForm/MapLocationDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const MapLocationDialog = props => {
const [mapZoom, setMapZoom] = useState(location?.zoom);
const [mapPitch, setMapPitch] = useState(location?.pitch);
const [mapBearing, setMapBearing] = useState(location?.bearing);
const [mapStyle, setMapStyle] = useState(config.style);
const [mapStyle, setMapStyle] = useState();
const [onConfirmStyleChange, setOnConfirmStyleChange] = useState();

const initialLocation = useMemo(() => {
Expand Down Expand Up @@ -204,9 +204,16 @@ const MapLocationDialog = props => {
pitch: mapPitch,
bearing: mapBearing,
});
console.log({ location });
onConfirm(location, mapStyle);
}, [onConfirm, mapCenter, mapZoom, mapPitch, mapBearing, mapStyle]);
onConfirm(location, mapStyle || config.style);
}, [
onConfirm,
mapCenter,
mapZoom,
mapPitch,
mapBearing,
mapStyle,
config.style,
]);

const handleCancel = useCallback(() => {
onClose();
Expand Down

0 comments on commit ef97006

Please sign in to comment.