Skip to content

Commit

Permalink
Linting map
Browse files Browse the repository at this point in the history
  • Loading branch information
gr812b committed Mar 31, 2024
1 parent 88f0080 commit 4c189be
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 237 deletions.
71 changes: 36 additions & 35 deletions front-end/src/components/map/LapTimes.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
import '../../styles/lapTimes.css';
import React from 'react';

const SIGFIGS = 3;

const LapTimes = ({ laps, gotoTimeCallback }) => {
if (laps.length === 0) {
return (
<>
<p className='laptimes_helptext'>
if (laps.length === 0) {
return (
<>
<p className='laptimes_helptext'>
Right click and drag to draw gates<br />
Choose the gate type at the top <br />
Place a start and end to show lap times<br />
</p>
</>
)
}
return (
<div className="laptimes_container">
<a className="laptimes_download" download="laps.json" href={URL.createObjectURL(new Blob([JSON.stringify(laps.toSorted((a, b) => a.start - b.start), null, 4)], { type: `application/json` }))}>Download lap data</a>
{laps.toSorted((a, b) => a.start - b.start).map((lap, index) => {
return (
<div key={[lap, index]} className="laptimes_lap">
<button className="laptimes_accordion" onClick={() => gotoTimeCallback(lap.start)}>Lap {index}: {((lap.end - lap.start) / 1000).toFixed(SIGFIGS)}s <span className="laptimes_drilldown">V</span></button>
<div className="laptimes_panel">
<table>
<tbody>
{lap.checkpoints.map((checkpoint, index) => {
return (
<tr className="laptimes_tr" key={[checkpoint, index]}>
<td>Checkpoint {index}</td>
<td>{((checkpoint - lap.start) / 1000).toFixed(SIGFIGS)}s</td>
</tr>
)
})}
</tbody>
</table>
</div>
</div>
)
})}
</div>
)
</p>
</>
);
}
return (
<div className="laptimes_container">
<a className="laptimes_download" download="laps.json" href={URL.createObjectURL(new Blob([JSON.stringify(laps.toSorted((a, b) => a.start - b.start), null, 4)], { type: 'application/json' }))}>Download lap data</a>
{laps.toSorted((a, b) => a.start - b.start).map((lap, index) => {
return (
<div key={[lap, index]} className="laptimes_lap">
<button className="laptimes_accordion" onClick={() => gotoTimeCallback(lap.start)}>Lap {index}: {((lap.end - lap.start) / 1000).toFixed(SIGFIGS)}s <span className="laptimes_drilldown">V</span></button>
<div className="laptimes_panel">
<table>
<tbody>
{lap.checkpoints.map((checkpoint, index) => {
return (
<tr className="laptimes_tr" key={[checkpoint, index]}>
<td>Checkpoint {index}</td>
<td>{((checkpoint - lap.start) / 1000).toFixed(SIGFIGS)}s</td>
</tr>
);
})}
</tbody>
</table>
</div>
</div>
);
})}
</div>
);

}
};

export default LapTimes;
28 changes: 14 additions & 14 deletions front-end/src/components/map/MapChart.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { useState } from 'react';
import React, { useState } from 'react';
import '../../styles/mapChart.css';
import MapDisplay from './MapDisplay';
import LapTimes from './LapTimes';

const MapChart = () => {
const [laps, setLaps] = useState([]);
const [gotoTime, setGotoTime] = useState(0);
return (
<div className="map_container">
<div className="map_display_container">
<MapDisplay setLapsCallback={setLaps} gotoTime={gotoTime} />
</div>
<div className="map_laptime_container">
<LapTimes laps={laps} gotoTimeCallback={setGotoTime} />
</div>
</div>
)
}
const [laps, setLaps] = useState([]);
const [gotoTime, setGotoTime] = useState(0);
return (
<div className="map_container">
<div className="map_display_container">
<MapDisplay setLapsCallback={setLaps} gotoTime={gotoTime} />
</div>
<div className="map_laptime_container">
<LapTimes laps={laps} gotoTimeCallback={setGotoTime} />
</div>
</div>
);
};

export default MapChart;
Loading

0 comments on commit 4c189be

Please sign in to comment.