import React, { useState } from 'react'; import { makeStyles, Typography, AppBar, Toolbar, IconButton, } from '@material-ui/core'; import ArrowBackIcon from '@material-ui/icons/ArrowBack'; import { useHistory, useParams } from 'react-router-dom'; import ContainerDimensions from 'react-container-dimensions'; import { useEffectAsync } from '../reactHelper'; import { useTranslation } from '../common/components/LocalizationProvider'; import Map from '../map/core/Map'; import MapPositions from '../map/MapPositions'; const useStyles = makeStyles(() => ({ root: { height: '100%', display: 'flex', flexDirection: 'column', }, mapContainer: { flexGrow: 1, }, })); const EventPage = () => { const classes = useStyles(); const history = useHistory(); const t = useTranslation(); const { id } = useParams(); const [event, setEvent] = useState(); const [position, setPosition] = useState(); useEffectAsync(async () => { if (id) { const response = await fetch(`/api/events/${id}`); if (response.ok) { setEvent(await response.json()); } else { throw Error(await response.text()); } } }, [id]); useEffectAsync(async () => { if (event && event.positionId) { const response = await fetch(`/api/positions?id=${event.positionId}`); if (response.ok) { const positions = await response.json(); if (positions.length > 0) { setPosition(positions[0]); } } else { throw Error(await response.text()); } } }, [event]); return (
history.push('/')}> {t('positionEvent')}
{position && }
); }; export default EventPage;