Skip to content

Commit

Permalink
fix: bottomNav settings add close button PL-18
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkojamG authored and mhieta committed Nov 28, 2024
1 parent 0cb7a47 commit fc5a397
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 32 deletions.
11 changes: 5 additions & 6 deletions src/components/BottomNav/BottomNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import MobileSettingsHeader from '../MobileSettingsHeader/MobileSettingsHeader';

const { bottomNavHeight } = config;

const BottomNav = () => {
function BottomNav() {
const location = useLocation();
const intl = useIntl();
const small = useMediaQuery('(max-width:477px)');
Expand Down Expand Up @@ -59,7 +59,7 @@ const BottomNav = () => {
}
};

const handleNav = (value) => {
const handleNav = value => {
switch (value) {
// Back button
case 0:
Expand Down Expand Up @@ -103,7 +103,7 @@ const BottomNav = () => {
}}
>
<StyledDiv>
<MobileSettingsHeader textId="general.ownSettings" />
<MobileSettingsHeader textId="general.ownSettings" onClose={handleBackButton} />
<SettingsDropdowns variant="ownSettings" />
</StyledDiv>
</StyledDrawer>
Expand All @@ -121,7 +121,7 @@ const BottomNav = () => {
},
}}
>
<MapSettings />
<MapSettings onClose={handleBackButton} />
</StyledDrawer>
<nav>
<StyledPaper elevation={10}>
Expand Down Expand Up @@ -153,7 +153,7 @@ const BottomNav = () => {
</nav>
</>
);
};
}

const StyledPaper = styled(Paper)(({ theme }) => ({
position: 'fixed',
Expand All @@ -173,7 +173,6 @@ const StyledBottomNavigation = styled(BottomNavigation)(() => ({
height: 78,
}));


const StyledBottomNavigationAction = styled(BottomNavigationAction)(({ small }) => {
const styles = {
color: '#000',
Expand Down
51 changes: 32 additions & 19 deletions src/components/MapSettings/MapSettings.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import styled from '@emotion/styled';
import { FormControl, FormControlLabel, Radio, RadioGroup, Typography } from '@mui/material';
import {
FormControl, FormControlLabel, Radio, RadioGroup, Typography,
} from '@mui/material';
import React from 'react';
import { FormattedMessage, useIntl } from 'react-intl';
import { useDispatch, useSelector } from 'react-redux';
import PropTypes from 'prop-types';
import { setMapType } from '../../redux/actions/settings';
import { selectMapRef } from '../../redux/selectors/general';
import { selectMapType } from '../../redux/selectors/settings';
Expand All @@ -12,7 +15,7 @@ import MobileSettingsHeader from '../MobileSettingsHeader/MobileSettingsHeader';
import SMButton from '../ServiceMapButton';
import ExternalMapUrlCreator from './externalMapUrlCreator';

const MapSettings = () => {
function MapSettings({ onClose }) {
const intl = useIntl();
const dispatch = useDispatch();

Expand All @@ -21,7 +24,7 @@ const MapSettings = () => {
const locale = useSelector(getLocale);

const mapSettings = {};
SettingsUtility.mapSettings.forEach((setting) => {
SettingsUtility.mapSettings.forEach(setting => {
mapSettings[setting] = {
action: () => setMapType(setting),
labelId: `settings.map.${setting}`,
Expand All @@ -42,18 +45,18 @@ const MapSettings = () => {
const openEspooUrl = () => {
const { lng, lat } = map.getCenter();
const urlToEspooMap = ExternalMapUrlCreator.createEspoo3DMapUrl(lng, lat, locale);
window.open(urlToEspooMap)
}
window.open(urlToEspooMap);
};

const openVantaaUrl = () => {
const urlToVantaaMap = ExternalMapUrlCreator.createVantaa3DMapUrl(locale);
window.open(urlToVantaaMap)
}
window.open(urlToVantaaMap);
};

return (
<>
<FormControl sx={{ textAlign: 'left', pt: 3 }} component="fieldset" fullWidth>
<MobileSettingsHeader textId="settings.map.title" />
<MobileSettingsHeader textId="settings.map.title" onClose={onClose} />
<Typography><FormattedMessage id="settings.map.info" /></Typography>
<RadioGroup
aria-label={intl.formatMessage({ id: 'settings.map.title' })}
Expand All @@ -62,23 +65,25 @@ const MapSettings = () => {
onChange={(event, value) => dispatch(setMapType(value))}
value={mapType}
>
{Object.keys(mapSettings).map((key) => {
{Object.keys(mapSettings).map(key => {
if (Object.prototype.hasOwnProperty.call(mapSettings, key)) {
const item = mapSettings[key];
return (<FormControlLabel
value={key}
key={key}
control={(<Radio id={`${key}-map-type-radio`} color="primary" />)}
labelPlacement="end"
label={<FormattedMessage id={item.labelId} />}
/>);
return (
<FormControlLabel
value={key}
key={key}
control={(<Radio id={`${key}-map-type-radio`} color="primary" />)}
labelPlacement="end"
label={<FormattedMessage id={item.labelId} />}
/>
);
}
return null;
})}
</RadioGroup>
</FormControl>
<Styled3DMapContainer>
<MobileSettingsHeader textId="settings.3dmap.title" />
<MobileSettingsHeader textId="settings.3dmap.title" onClose={onClose} />
<Styled3DMapLinkButton onClick={openHelsinkiUrl} role="link" data-sm="3dMapLink">
<Typography><FormattedMessage id="settings.3dmap.link.helsinki" /></Typography>
</Styled3DMapLinkButton>
Expand All @@ -87,11 +92,11 @@ const MapSettings = () => {
</Styled3DMapLinkButton>
<Styled3DMapLinkButton onClick={openVantaaUrl} role="link" data-sm="3dMapLink">
<Typography><FormattedMessage id="settings.3dmap.link.vantaa" /></Typography>
</Styled3DMapLinkButton>
</Styled3DMapLinkButton>
</Styled3DMapContainer>
</>
);
};
}

const Styled3DMapContainer = styled('div')(({ theme }) => ({
paddingTop: theme.spacing(3),
Expand All @@ -104,4 +109,12 @@ const Styled3DMapLinkButton = styled(SMButton)(({ theme }) => ({
marginTop: theme.spacing(2),
}));

MapSettings.propTypes = {
onClose: PropTypes.func,
};

MapSettings.defaultProps = {
onClose: null,
};

export default MapSettings;
50 changes: 43 additions & 7 deletions src/components/MobileSettingsHeader/MobileSettingsHeader.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
import { FormLabel } from '@mui/material';
import { FormLabel, IconButton } from '@mui/material';
import { Close } from '@mui/icons-material';
import styled from '@emotion/styled';
import React from 'react';
import { FormattedMessage } from 'react-intl';
import { FormattedMessage, useIntl } from 'react-intl';
import PropTypes from 'prop-types';

const MobileSettingsHeader = ({ textId }) => (
<StyledFormLabel>
<FormattedMessage id={textId} />
</StyledFormLabel>
);
function MobileSettingsHeader({ textId, onClose }) {
const intl = useIntl();

return (
<StyledWrapper>
{onClose && (
<StyledCloseButton
onClick={onClose}
aria-label={intl.formatMessage({ id: 'general.close' })}
>
<Close />
</StyledCloseButton>
)}
<StyledFormLabel>
<FormattedMessage id={textId} />
</StyledFormLabel>
</StyledWrapper>
);
}

const StyledFormLabel = styled(FormLabel)(() => ({
fontWeight: 700,
Expand All @@ -18,7 +33,28 @@ const StyledFormLabel = styled(FormLabel)(() => ({
color: '#000',
}));

const StyledWrapper = styled('div')(() => ({
display: 'flex',
alignItems: 'flex-start',
justifyContent: 'space-between',
marginBottom: '1rem',
}));

const StyledCloseButton = styled(IconButton)(() => ({
order: 1,
padding: 0,
svg: {
fill: '#000',
},
}));

MobileSettingsHeader.propTypes = {
textId: PropTypes.string.isRequired,
onClose: PropTypes.func,
};

MobileSettingsHeader.defaultProps = {
onClose: null,
};

export default MobileSettingsHeader;

0 comments on commit fc5a397

Please sign in to comment.