From 78746219d0faff45aa83c39881c76ced25ca6b5d Mon Sep 17 00:00:00 2001 From: Wojtek Bazant Date: Thu, 31 Oct 2024 11:11:13 +0000 Subject: [PATCH] Allow 'back to settings' from location --- .../connect/ConnectSettingsLocation.js | 27 +++++++++++++++++++ src/components/connect/connectRoutes.js | 19 +++++++++++++ src/components/desktop/SidePane.js | 17 +++++++++--- src/redux/locationSlice.js | 5 ++++ 4 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 src/components/connect/ConnectSettingsLocation.js diff --git a/src/components/connect/ConnectSettingsLocation.js b/src/components/connect/ConnectSettingsLocation.js new file mode 100644 index 00000000..f06efa62 --- /dev/null +++ b/src/components/connect/ConnectSettingsLocation.js @@ -0,0 +1,27 @@ +import { useEffect } from 'react' +import { useDispatch } from 'react-redux' + +import { setFromSettings } from '../../redux/locationSlice' +import { useIsDesktop } from '../../utils/useBreakpoint' + +const ConnectSettingsLocation = ({ isSettings }) => { + const dispatch = useDispatch() + const isDesktop = useIsDesktop() + + useEffect(() => { + if (isDesktop) { + if (isSettings) { + dispatch(setFromSettings(true)) + } + return () => { + if (!window.location.pathname.startsWith('/locations')) { + dispatch(setFromSettings(false)) + } + } + } + }, [dispatch, isDesktop, isSettings]) + + return null +} + +export default ConnectSettingsLocation diff --git a/src/components/connect/connectRoutes.js b/src/components/connect/connectRoutes.js index 2feddfe6..3077da70 100644 --- a/src/components/connect/connectRoutes.js +++ b/src/components/connect/connectRoutes.js @@ -7,6 +7,7 @@ import ConnectNewLocation from './ConnectNewLocation' import ConnectOverscroll from './ConnectOverscroll' import ConnectPath from './ConnectPath' import ConnectReview from './ConnectReview' +import ConnectSettingsLocation from './ConnectSettingsLocation' import ConnectTypes from './ConnectTypes' import DisconnectLocation from './DisconnectLocation' import DisconnectReview from './DisconnectReview' @@ -171,6 +172,24 @@ const connectRoutes = [ {({ match }) => match && } , + /* + * ConnectSettingsLocation + * why: we can access location page from either map or settings on desktop and want the back button to work + * + * action: if on settings page set a flag in Redux. If away from map or settings, remove the flag + */ + + {({ match }) => + match && ( + + ) + } + , ] export default connectRoutes diff --git a/src/components/desktop/SidePane.js b/src/components/desktop/SidePane.js index ef5e24f1..7eeb48b4 100644 --- a/src/components/desktop/SidePane.js +++ b/src/components/desktop/SidePane.js @@ -46,15 +46,22 @@ const SidePane = () => { const history = useAppHistory() const { t } = useTranslation() const { review } = useSelector((state) => state.review) - const { locationId, isBeingEdited: isEditingLocation } = useSelector( - (state) => state.location, - ) + const { + locationId, + isBeingEdited: isEditingLocation, + fromSettings, + } = useSelector((state) => state.location) const goToMap = (event) => { event.stopPropagation() history.push('/map') } + const goToSettings = (event) => { + event.stopPropagation() + history.push('/settings') + } + return ( @@ -137,7 +144,9 @@ const SidePane = () => { match && ( <> - + {t('back')} diff --git a/src/redux/locationSlice.js b/src/redux/locationSlice.js index 97f526cc..0829ce98 100644 --- a/src/redux/locationSlice.js +++ b/src/redux/locationSlice.js @@ -92,6 +92,7 @@ const locationSlice = createSlice({ position: null, // {lat: number, lng: number} locationId: null, isBeingEdited: false, + fromSettings: false, form: null, tooltipOpen: false, streetViewOpen: false, @@ -184,6 +185,9 @@ const locationSlice = createSlice({ setTabIndex: (state, action) => { state.pane.tabIndex = action.payload }, + setFromSettings: (state, action) => { + state.fromSettings = action.payload + }, }, extraReducers: { [updateLastMapView]: (state, action) => { @@ -288,6 +292,7 @@ export const { setTabIndex, fullyOpenPaneDrawer, partiallyClosePaneDrawer, + setFromSettings, } = locationSlice.actions export default locationSlice.reducer