forked from City-of-Helsinki/servicemap-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Show barbecue places on the map * Use correct icons * Render info about barbecue places * Use new hook to fetch data of barbecue places * Add info text & update translations
- Loading branch information
1 parent
150a170
commit 30736be
Showing
10 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/components/MobilityPlatform/BarbecuePlaces/BarbecuePlaces.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* eslint-disable react-hooks/exhaustive-deps */ | ||
import React, { useEffect } from 'react'; | ||
import { useMap } from 'react-leaflet'; | ||
import { useSelector } from 'react-redux'; | ||
import barbecuePlaceIconBw from 'servicemap-ui-turku/assets/icons/contrast/icons-icon_barbecue_place-bw.svg'; | ||
import barbecuePlaceIcon from 'servicemap-ui-turku/assets/icons/icons-icon_barbecue_place.svg'; | ||
import { useMobilityPlatformContext } from '../../../context/MobilityPlatformContext'; | ||
import { useAccessibleMap } from '../../../redux/selectors/settings'; | ||
import useMobilityDataFetch from '../utils/useMobilityDataFetch'; | ||
import { createIcon, isDataValid, fitToMapBounds } from '../utils/utils'; | ||
import MarkerComponent from '../MarkerComponent'; | ||
import BarbecuePlacesContent from './components/BarbecuePlacesContent'; | ||
|
||
const BarbecuePlaces = () => { | ||
const options = { | ||
type_name: 'BarbecuePlace', | ||
}; | ||
|
||
const { showBarbecuePlaces } = useMobilityPlatformContext(); | ||
|
||
const map = useMap(); | ||
|
||
const useContrast = useSelector(useAccessibleMap); | ||
|
||
const { icon } = global.L; | ||
|
||
const customIcon = icon(createIcon(useContrast ? barbecuePlaceIconBw : barbecuePlaceIcon)); | ||
|
||
const { data } = useMobilityDataFetch(options, showBarbecuePlaces); | ||
const renderData = isDataValid(showBarbecuePlaces, data); | ||
|
||
useEffect(() => { | ||
fitToMapBounds(renderData, data, map); | ||
}, [showBarbecuePlaces, data]); | ||
|
||
return (renderData | ||
? data.map(item => ( | ||
<MarkerComponent key={item.id} item={item} icon={customIcon}> | ||
<BarbecuePlacesContent item={item} /> | ||
</MarkerComponent> | ||
)) | ||
: null | ||
); | ||
}; | ||
|
||
export default BarbecuePlaces; |
52 changes: 52 additions & 0 deletions
52
...MobilityPlatform/BarbecuePlaces/components/BarbecuePlacesContent/BarbecuePlacesContent.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import { Typography } from '@mui/material'; | ||
import { useIntl } from 'react-intl'; | ||
import styled from '@emotion/styled'; | ||
|
||
const BarbecuePlacesContent = ({ item }) => { | ||
const intl = useIntl(); | ||
return ( | ||
<StyledContainer> | ||
<StyledHeader> | ||
<Typography variant="subtitle2" component="h3"> | ||
{intl.formatMessage({ id: 'mobilityPlatform.content.barbecuePlace.title' })} | ||
</Typography> | ||
</StyledHeader> | ||
<StyledText> | ||
<Typography variant="body2" component="p"> | ||
{`${item.extra.malli.trim()} (${item.extra.valmistaja})`} | ||
</Typography> | ||
</StyledText> | ||
</StyledContainer> | ||
); | ||
}; | ||
|
||
const StyledContainer = styled.div(({ theme }) => ({ | ||
margin: theme.spacing(1), | ||
})); | ||
|
||
const StyledHeader = styled.div(({ theme }) => ({ | ||
width: '85%', | ||
borderBottom: '1px solid #000', | ||
paddingBottom: theme.spacing(0.5), | ||
})); | ||
|
||
const StyledText = styled.div(({ theme }) => ({ | ||
marginTop: theme.spacing(0.5), | ||
})); | ||
|
||
BarbecuePlacesContent.propTypes = { | ||
item: PropTypes.shape({ | ||
extra: PropTypes.shape({ | ||
malli: PropTypes.string, | ||
valmistaja: PropTypes.string, | ||
}), | ||
}), | ||
}; | ||
|
||
BarbecuePlacesContent.defaultProps = { | ||
item: {}, | ||
}; | ||
|
||
export default BarbecuePlacesContent; |
3 changes: 3 additions & 0 deletions
3
src/components/MobilityPlatform/BarbecuePlaces/components/BarbecuePlacesContent/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import BarbecuePlacesContent from './BarbecuePlacesContent'; | ||
|
||
export default BarbecuePlacesContent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import BarbecuePlaces from './BarbecuePlaces'; | ||
|
||
export default BarbecuePlaces; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters