Skip to content

Commit 59fa731

Browse files
committed
fix: loop
1 parent 80bad7d commit 59fa731

File tree

4 files changed

+92
-21
lines changed

4 files changed

+92
-21
lines changed

.vscode/launch.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": []
7+
}

frontend/src/components/Chart.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ export default function Chart(props: ChartProps) {
4848

4949
// eslint-disable-next-line
5050
useEffect(() => {
51+
updateChart();
52+
}, []);
53+
54+
function updateChart() {
5155
if (fuelType === FuelType.E5) {
5256
setLineColor('#8884d8')
5357
setAvgValue(props.timeSlots.reduce((acc, value) => value.e5 + acc, 0) / (props.timeSlots.length || 1));
@@ -61,10 +65,11 @@ export default function Chart(props: ChartProps) {
6165
setAvgValue(props.timeSlots.reduce((acc, value) => value.diesel + acc, 0) / (props.timeSlots.length || 1));
6266
setGsValues(props.timeSlots.map(myValue => ({ timestamp: myValue.x, price: myValue.diesel - avgValue } as GsPoint)))
6367
}
64-
});
68+
}
6569

66-
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
70+
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
6771
setFuelType(((event.target as HTMLInputElement).value) as FuelType);
72+
updateChart();
6873
};
6974
return (<div>
7075
<ResponsiveContainer width="100%" height={300}>

frontend/src/components/Main.tsx

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@
1010
See the License for the specific language governing permissions and
1111
limitations under the License.
1212
*/
13-
import { Tabs, Tab, Box } from '@mui/material';
13+
import { Box } from '@mui/material';
1414
import { useEffect, useState, SyntheticEvent } from 'react';
1515
import DataTable, { TableDataRow } from './DataTable';
1616
import GsMap, { GsValue } from './GsMap';
1717
import { useRecoilRefresher_UNSTABLE, useRecoilValue } from 'recoil';
1818
import GlobalState from '../GlobalState';
1919
import styles from './main.module.scss';
2020
import Chart, {TimeSlot} from './Chart';
21+
import { BrowserRouter, Outlet, Route, Routes, Link} from 'react-router-dom';
22+
2123

2224
interface GasPriceAvgs {
2325
Postcode: string
@@ -130,8 +132,7 @@ export default function Main() {
130132
const globalJwtTokenState = useRecoilValue(GlobalState.jwtTokenState);
131133
const globalUserUuidState = useRecoilValue(GlobalState.userUuidState);
132134
const globalUserDataState = useRecoilValue(GlobalState.userDataState);
133-
const refreshJwtTokenState = useRecoilRefresher_UNSTABLE(GlobalState.jwtTokenState);
134-
135+
const refreshJwtTokenState = useRecoilRefresher_UNSTABLE(GlobalState.jwtTokenState);
135136

136137
const handleTabChange = (event: SyntheticEvent, newValue: number) => {
137138
setValue(newValue);
@@ -241,29 +242,69 @@ export default function Main() {
241242
.then(() => setController(null));
242243
}
243244

245+
const Area = () => {
246+
return (
247+
<>
248+
<DataTable diesel='Diesel' e10='E10' e5='E5' location='Location' showAverages={true} time='Time' rows={rows}></DataTable>
249+
</>
250+
)
251+
};
252+
253+
const Target = () => {
254+
return (
255+
<>
256+
<Chart timeSlots={avgTimeSlots}></Chart>
257+
<DataTable diesel='Diesel' e10='E10' e5='E5' location='Location' showAverages={true} time='Time' rows={rows}></DataTable>
258+
</>
259+
)
260+
}
261+
262+
const Map = () => {
263+
return (
264+
<>
265+
<GsMap gsValues={gsValues} center={globalUserDataState}></GsMap>
266+
</>
267+
)
268+
}
269+
270+
const Layout = () => {
271+
return (
272+
<>
273+
<div className={styles.headerTabs}>
274+
<div className={styles.headerTab}>
275+
<Link className={styles.linkText} to="/area">Area Gas Prices</Link>
276+
</div>
277+
<div className={styles.headerTab}>
278+
<Link className={styles.linkText} to="/target">Target Gas Prices</Link>
279+
</div>
280+
<div className={styles.headerTab}>
281+
<Link className={styles.linkText} to="/map">Map Gas Prices</Link>
282+
</div>
283+
</div>
284+
<Outlet />
285+
</>
286+
);
287+
}
288+
244289
// eslint-disable-next-line
245290
useEffect(() => {
246291
if (globalJwtTokenState?.length > 10 && globalUserUuidState?.length > 10 && first) {
247292
setTimeout(() => handleTabChange({} as unknown as SyntheticEvent, value), 3000);
248293
setFirst(false);
249-
}
294+
}
250295
});
251296

252297
return (<Box sx={{ width: '100%' }}>
253-
<Tabs value={value} onChange={handleTabChange} >
254-
<Tab label="Current Prices" />
255-
<Tab label="Last Price matches" />
256-
<Tab label="Current Prices Map" />
257-
</Tabs>
258-
<TabPanel value={value} index={0}>
259-
<DataTable diesel='Diesel' e10='E10' e5='E5' location='Location' showAverages={true} time='Time' rows={rows}></DataTable>
260-
</TabPanel>
261-
<TabPanel value={value} index={1}>
262-
<Chart timeSlots={avgTimeSlots}></Chart>
263-
<DataTable diesel='Diesel' e10='E10' e5='E5' location='Location' showAverages={true} time='Time' rows={rows}></DataTable>
264-
</TabPanel>
265-
<TabPanel value={value} index={2}>
266-
<GsMap gsValues={gsValues} center={globalUserDataState}></GsMap>
267-
</TabPanel>
298+
<BrowserRouter>
299+
<Routes>
300+
<Route path="/" element={<Layout />}>
301+
<Route index element={<Area />} />
302+
<Route path="area" element={<Area />} />
303+
<Route path="target" element={<Target />} />
304+
<Route path="map" element={<Map />} />
305+
<Route path="*" element={<Area />} />
306+
</Route>
307+
</Routes>
308+
</BrowserRouter>
268309
</Box>);
269310
}

frontend/src/components/main.module.scss

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,22 @@
1212
*/
1313
.myText {
1414
color: #000000;
15+
}
16+
17+
.headerTabs {
18+
display: flex;
19+
justify-content: space-around;
20+
}
21+
22+
.headerTab {
23+
width: fit-content;
24+
line-height: 2rem;
25+
}
26+
27+
.linkText {
28+
color: rgb(25, 118, 210);
29+
--Link-underlineColor: rgba(25, 118, 210, 0.4);
30+
font-family: "Roboto", "Helvetica", "Arial", sans-serif;
31+
font-weight: 400;
32+
text-decoration-color: var(--Link-underlineColor);
1533
}

0 commit comments

Comments
 (0)