aboutsummaryrefslogtreecommitdiff
path: root/modern/src/EventPage.js
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-04-17 15:38:40 -0700
committerAnton Tananaev <anton@traccar.org>2022-04-17 15:38:40 -0700
commitad8484a08ef7eabb41afb33a9774ba8502da1d53 (patch)
tree957204d055150ee29251b24b28a9ed1d0afe88d0 /modern/src/EventPage.js
parent914f3dae0e34304eebbfaae2b7740e53206ce527 (diff)
downloadtrackermap-web-ad8484a08ef7eabb41afb33a9774ba8502da1d53.tar.gz
trackermap-web-ad8484a08ef7eabb41afb33a9774ba8502da1d53.tar.bz2
trackermap-web-ad8484a08ef7eabb41afb33a9774ba8502da1d53.zip
Handle query parameters
Diffstat (limited to 'modern/src/EventPage.js')
-rw-r--r--modern/src/EventPage.js77
1 files changed, 77 insertions, 0 deletions
diff --git a/modern/src/EventPage.js b/modern/src/EventPage.js
new file mode 100644
index 00000000..48c6d807
--- /dev/null
+++ b/modern/src/EventPage.js
@@ -0,0 +1,77 @@
+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 { useEffectAsync } from './reactHelper';
+import { useTranslation } from './LocalizationProvider';
+import ContainerDimensions from 'react-container-dimensions';
+import Map from './map/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());
+ }
+ }
+ }, [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]);
+ }
+ }
+ }
+ }, [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;