1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
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 PositionsMap from '../map/PositionsMap';
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 (
<div className={classes.root}>
<AppBar color="inherit" position="static">
<Toolbar>
<IconButton color="inherit" edge="start" onClick={() => history.push('/')}>
<ArrowBackIcon />
</IconButton>
<Typography variant="h6">{t('positionEvent')}</Typography>
</Toolbar>
</AppBar>
<div className={classes.mapContainer}>
<ContainerDimensions>
<Map>
{position && <PositionsMap positions={[position]} />}
</Map>
</ContainerDimensions>
</div>
</div>
);
};
export default EventPage;
|