diff --git a/src/components/DirectionsTable.js b/src/components/DirectionsTable.js index c4c35d0..3f9752f 100644 --- a/src/components/DirectionsTable.js +++ b/src/components/DirectionsTable.js @@ -12,13 +12,18 @@ import IconButton from '@mui/material/IconButton'; import EditIcon from '@mui/icons-material/Edit'; import ModalEditPoint from './ModalEditPoint'; import Box from '@mui/material/Box'; - +import StraightenIcon from '@mui/icons-material/Straighten'; +import DirectionsRunIcon from '@mui/icons-material/DirectionsRun'; +import DirectionsBikeIcon from '@mui/icons-material/DirectionsBike'; +import DirectionsCarIcon from '@mui/icons-material/DirectionsCar'; +import DirectionsBusIcon from '@mui/icons-material/DirectionsBus'; +import AccessTimeIcon from '@mui/icons-material/AccessTime'; import {grey, red} from '@mui/material/colors'; import {lighten} from '@mui/material'; import {useTranslation} from 'react-i18next'; -const DirectionsTable = ({calculatedRoutes, allPoints, onChangeHover, onChangeIdHoverPoint,onChangeNearestRedPoint, onChangePoints}) => { +const DirectionsTable = ({calculatedRoutes, allPoints, onChangeHover, onChangeIdHoverPoint,onChangeNearestRedPoint, onChangePoints, typeTransport}) => { const{t} = useTranslation(); const [openModal,setOpenModal] = useState(null); @@ -59,71 +64,98 @@ const DirectionsTable = ({calculatedRoutes, allPoints, onChangeHover, onChangeId setOpenModal(false); }; const rowNames = allPoints.red ? allPoints.red.map(point => point.name) : []; + const transportIcons = { + 'foot-walking': , + 'cycling-regular': , + 'driving-car': , + 'driving-hgv': + }; return <> - { - calculatedRoutes && calculatedRoutes.length > 0 && allPoints.blue.length && allPoints.red.length && - + {calculatedRoutes && calculatedRoutes.length > 0 && allPoints.blue.length && allPoints.red.length && ( +
- - { - bluePoints.map((bluePoint, index) => - - handleClickIcon(index,'blue')} size='small'> - + + {bluePoints.map((bluePoint, index) => ( + + + handleClickIcon(index, 'blue')} size="small"> + - + {bluePoint.name?.toUpperCase()} - ) - } - {t('averageTime')} + + ))} + + + {t('averageTime')} + {transportIcons[typeTransport]} + + + + {calculatedRoutes.map((row, index) => ( - handleCellHover(allPoints.red[index].id)} onMouseLeave={()=> handleCellLeave()} + `2px solid ${theme.palette.secondary.dark}`: undefined}} + onMouseEnter={() => handleCellHover(allPoints.red[index].id)} + onMouseLeave={handleCellLeave} + sx={{ + '&:hover': index === shortestRouteIndex + ? { bgcolor: lighten(red[50], 0.75) } + : { bgcolor: 'grey.200' }, + border: index === shortestRouteIndex + ? theme => `2px solid ${theme.palette.secondary.dark}` + : undefined, + }} > - - handleClickIcon(index,'red')} size='small'> - theme.palette.secondary.dark : theme => theme.palette.secondary.main}} fontSize='small'/> + + handleClickIcon(index, 'red')} size="small"> + - + {rowNames[index]?.toUpperCase()} - {row.name} + + {row.name} + - { - row.data.map((data) => ( - { - data.map((value, index ) => ( - {value + (index === 0 ? 'km' : 'min')}
- )) - }
- )) - } + {row.data.map((d, i) => ( + + {d.map((x, i) => ( + + + {i === 0 && } + {i === 1 && } + + {x + (i === 0 ? 'km' : 'min')} + + ))} + + ))} - {row.data.avg} min + + {row.data.avg} min +
))}
- } - { openModal && - } + )} + {openModal && ( + + )} ; }; @@ -146,7 +178,8 @@ DirectionsTable.propTypes = { onChangeNearestRedPoint: PropTypes.func.isRequired, onChangeHover: PropTypes.func.isRequired, onChangeIdHoverPoint: PropTypes.func.isRequired, - onChangePoints: PropTypes.func.isRequired + onChangePoints: PropTypes.func.isRequired, + typeTransport: PropTypes.string.isRequired }; export default DirectionsTable; \ No newline at end of file diff --git a/src/views/Map/MainContent.js b/src/views/Map/MainContent.js index 8f1d5b4..0fcb922 100644 --- a/src/views/Map/MainContent.js +++ b/src/views/Map/MainContent.js @@ -17,7 +17,7 @@ import ModalInfo from '../../components/ModalInfo'; import ModalAddPoint from '../../components/ModalAddPoint'; import { primaryColor, secondaryColor } from '../../theme'; import { v4 as uuid } from 'uuid'; -const MainContent = ({mapStyle, mode, routes, calculatedRoutes, onChangePoints, allPoints, onChangeHover, hover, idHoverPoint, onChangeIdHoverPoint }) => { +const MainContent = ({mapStyle, mode, routes, calculatedRoutes, onChangePoints, allPoints, onChangeHover, hover, idHoverPoint, onChangeIdHoverPoint, typeTransport }) => { const [viewport, setViewport] = useState(INITIAL_VIEWPORT); const [openModal, setOpenModal] = useState(false); const [nearestRedPoint,setNearestRedPoint] = useState(null); @@ -354,7 +354,8 @@ const MainContent = ({mapStyle, mode, routes, calculatedRoutes, onChangePoints, right: 18, background: 'white' }}> - + ; }; @@ -386,7 +387,8 @@ MainContent.propTypes = { PropTypes.string, PropTypes.oneOf([null]) ]), - onChangeIdHoverPoint: PropTypes.func.isRequired + onChangeIdHoverPoint: PropTypes.func.isRequired, + typeTransport: PropTypes.string.isRequired }; export default MainContent; diff --git a/src/views/Map/MapView.js b/src/views/Map/MapView.js index 3215101..3dbdc2f 100644 --- a/src/views/Map/MapView.js +++ b/src/views/Map/MapView.js @@ -14,13 +14,14 @@ const Map = () => { const [hover, setHover] = useState(false); const [idHoverPoint,setIdHoverPoint] = useState(null); const [allPoints,setAllPoints] = useState(localStorage.getItem('ThePerfectSpot') ? JSON.parse(localStorage.getItem('ThePerfectSpot')):{red: [], blue: []}); - + const [typeTransport, setTypeTransport] = useState('foot-walking'); const sidePanelContent = ; const mainContent = { onChangeHover={setHover} idHoverPoint={idHoverPoint} onChangeIdHoverPoint={setIdHoverPoint} + typeTransport={typeTransport} />; return { +const SidePanelContent = ({ onChangeModePoints, onRoutesChange, onChangeCalculatedRoutes, allPoints, onChangePoints, onChangeTypeTransport}) => { const requestError = http.getError(); const {t} = useTranslation(); const transportOptions = [ @@ -98,6 +98,7 @@ const SidePanelContent = ({ onChangeModePoints, onRoutesChange, onChangeCalculat }; const handleTransportationType = (transportationType) => { + onChangeTypeTransport(transportationType); setTransportation(transportationType); if (allPoints.red?.length && allPoints.blue?.length) { calculateDirectionsTable(transportationType); @@ -155,7 +156,8 @@ SidePanelContent.propTypes = { name: PropTypes.string })).isRequired, }).isRequired, - onChangePoints: PropTypes.func.isRequired + onChangePoints: PropTypes.func.isRequired, + onChangeTypeTransport: PropTypes.func.isRequired }; export default SidePanelContent;