From 63cf082bd077087e551d2946c3e2a48a605a3532 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 15 May 2022 09:58:37 -0700 Subject: Clean up replay page --- modern/src/other/ReplayPage.js | 192 ++++++++++++++++++----------------------- 1 file changed, 84 insertions(+), 108 deletions(-) (limited to 'modern/src/other/ReplayPage.js') diff --git a/modern/src/other/ReplayPage.js b/modern/src/other/ReplayPage.js index 9b66853d..1fddc21c 100644 --- a/modern/src/other/ReplayPage.js +++ b/modern/src/other/ReplayPage.js @@ -1,6 +1,8 @@ -import React, { useState, useEffect, useRef } from 'react'; +import React, { + useState, useEffect, useRef, useCallback, +} from 'react'; import { - Grid, FormControlLabel, Switch, IconButton, TextField, makeStyles, Paper, Slider, Toolbar, Tooltip, Typography, + Grid, IconButton, makeStyles, Paper, Slider, Toolbar, Tooltip, Typography, } from '@material-ui/core'; import ArrowBackIcon from '@material-ui/icons/ArrowBack'; import SettingsIcon from '@material-ui/icons/Settings'; @@ -22,7 +24,10 @@ const useStyles = makeStyles((theme) => ({ height: '100%', }, sidebar: { + display: 'flex', + flexDirection: 'column', position: 'absolute', + zIndex: 3, left: 0, top: 0, margin: theme.spacing(1.5), @@ -32,6 +37,17 @@ const useStyles = makeStyles((theme) => ({ margin: 0, }, }, + title: { + flexGrow: 1, + }, + slider: { + width: '100%', + }, + controls: { + display: 'flex', + justifyContent: 'space-between', + alignItems: 'center', + }, formControlLabel: { height: '100%', width: '100%', @@ -39,15 +55,16 @@ const useStyles = makeStyles((theme) => ({ justifyContent: 'space-between', alignItems: 'center', }, - reportFilterContainer: { - flex: 1, + content: { + display: 'flex', + flexDirection: 'column', padding: theme.spacing(2), [theme.breakpoints.down('sm')]: { margin: theme.spacing(1), }, - }, - sliderContainer: { - padding: theme.spacing(2), + [theme.breakpoints.up('md')]: { + marginTop: theme.spacing(1), + }, }, })); @@ -63,12 +80,13 @@ const ReplayPage = () => { const history = useHistory(); const timerRef = useRef(); + const defaultDeviceId = useSelector((state) => state.devices.selectedId); + const [positions, setPositions] = useState([]); const [index, setIndex] = useState(0); - const [selectedDeviceId, setSelectedDeviceId] = useState(); - const [playbackSpeed, setPlaybackSpeed] = useState(''); + const [selectedDeviceId, setSelectedDeviceId] = useState(defaultDeviceId); const [expanded, setExpanded] = useState(true); - const [isPlaying, setIsPlaying] = useState(false); + const [playing, setPlaying] = useState(false); const deviceName = useSelector((state) => { if (selectedDeviceId) { @@ -80,8 +98,12 @@ const ReplayPage = () => { return null; }); + const onClick = useCallback((positionId) => { + history.push(`/position/${positionId}`); + }, [history]); + useEffect(() => { - if (isPlaying && positions.length > 0) { + if (playing && positions.length > 0) { timerRef.current = setInterval(() => { setIndex((index) => index + 1); }, 500); @@ -90,7 +112,7 @@ const ReplayPage = () => { } return () => clearInterval(timerRef.current); - }, [isPlaying, positions]); + }, [playing, positions]); useEffect(() => { if (index >= positions.length) { @@ -113,105 +135,59 @@ const ReplayPage = () => {
- {index < positions.length && } + {index < positions.length && ( + + )}
- - - - - - - history.push('/')}> - - - - - {t('reportReplay')} - - {!expanded && ( - - setExpanded(true)}> - - - - )} - - - - - - {!expanded ? ( - - - - {deviceName} - - - ({ value: index }))} - value={index} - onChange={(_, index) => setIndex(index)} - valueLabelDisplay="auto" - valueLabelFormat={(i) => (i < positions.length ? formatTime(positions[i]) : '')} - ValueLabelComponent={TimeLabel} - /> - - - {`${index}/${positions.length}`} - - setIndex((index) => index - 1)} disabled={isPlaying}> - - - - - setIsPlaying(!isPlaying)}> - {isPlaying ? : } - - - - setIndex((index) => index + 1)} disabled={isPlaying}> - - - - {formatTime(positions[index])} - - - - ) : ( - - - - setPlaybackSpeed(e.target.value)} - variant="filled" - /> - - - setIsPlaying(e.target.checked)} - color="primary" - edge="start" - /> - )} - label={t('reportAutoPlay')} - labelPlacement="start" - /> - - - + + + history.push('/')}> + + + {t('reportReplay')} + {!expanded && ( + + setExpanded(true)}> + + + )} - - + + + + {!expanded ? ( + <> + {deviceName} + ({ value: index }))} + value={index} + onChange={(_, index) => setIndex(index)} + valueLabelDisplay="auto" + valueLabelFormat={(i) => (i < positions.length ? formatTime(positions[i]) : '')} + ValueLabelComponent={TimeLabel} + /> +
+ {`${index}/${positions.length}`} + setIndex((index) => index - 1)} disabled={playing}> + + + setPlaying(!playing)}> + {playing ? : } + + setIndex((index) => index + 1)} disabled={playing}> + + + {formatTime(positions[index].fixTime)} +
+ + ) : ( + + )} +
); -- cgit v1.2.3