Skip to content

Commit d099eb4

Browse files
committed
fix: tabs
1 parent ca7b0a2 commit d099eb4

File tree

4 files changed

+27
-86
lines changed

4 files changed

+27
-86
lines changed

frontend/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"ol": "^7.3.0",
2020
"react": "^18.2.0",
2121
"react-dom": "^18.2.0",
22-
"react-router-dom": "^6.0.0",
2322
"react-scripts": "5.0.1",
2423
"recharts": "^2.12.4",
2524
"recoil": "^0.7.6",

frontend/src/components/Chart.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,19 @@ export interface ChartProps {
3737

3838
export default function Chart(props: ChartProps) {
3939
//console.log(props.timeSlots);
40+
const [updated, setUpdated] = useState(0);
4041
const [gsValues, setGsValues] = useState([] as GsPoint[]);
4142
const [fuelTypeState, setfuelTypeState] = useRecoilState(GlobalState.fuelTypeState);
4243
const [lineColor, setLineColor] = useState('#8884d8');
4344
const [avgValue, setAvgValue] = useState(0.0);
4445

4546
// eslint-disable-next-line
4647
useEffect(() => {
47-
updateChart();
48-
}, []);
48+
if(updated < 3) {
49+
setUpdated(updated + 1);
50+
updateChart();
51+
}
52+
});
4953

5054
function updateChart() {
5155
if (fuelTypeState === FuelType.E5) {
@@ -65,6 +69,7 @@ export default function Chart(props: ChartProps) {
6569

6670
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
6771
setfuelTypeState(((event.target as HTMLInputElement).value) as FuelType);
72+
setUpdated(0);
6873
updateChart();
6974
};
7075
return (<div>

frontend/src/components/DataTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface TableDataRow {
2828
dieselClass: string;
2929
}
3030

31-
interface DataTableProps {
31+
export interface DataTableProps {
3232
location: string;
3333
time: string;
3434
showAverages: boolean;

frontend/src/components/Main.tsx

Lines changed: 19 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
See the License for the specific language governing permissions and
1111
limitations under the License.
1212
*/
13-
import { Box } from '@mui/material';
13+
import { Box, InputProps, Tab, Tabs } 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';
21+
2222

2323

2424
interface GasPriceAvgs {
@@ -95,30 +95,9 @@ interface TimeSlotResponse {
9595
CountyDataID: number;
9696
}
9797

98-
interface TabPanelProps {
99-
children?: React.ReactNode;
100-
index: number;
101-
value: number;
102-
}
103-
104-
function TabPanel(props: TabPanelProps) {
105-
const { children, value, index, ...other } = props;
106-
107-
return (
108-
<div
109-
role="tabpanel"
110-
hidden={value !== index}
111-
id={`simple-tabpanel-${index}`}
112-
aria-labelledby={`simple-tab-${index}`}
113-
{...other}
114-
>
115-
{value === index && (
116-
<Box sx={{ p: 3 }} className={styles.myText}>
117-
{children}
118-
</Box>
119-
)}
120-
</div>
121-
);
98+
interface TargetAreaProperties {
99+
rows: TableDataRow[];
100+
timeSlots: TimeSlot[];
122101
}
123102

124103
export default function Main() {
@@ -242,69 +221,27 @@ export default function Main() {
242221
.then(() => setController(null));
243222
}
244223

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-
289224
// eslint-disable-next-line
290225
useEffect(() => {
291226
if (globalJwtTokenState?.length > 10 && globalUserUuidState?.length > 10 && first) {
292-
setTimeout(() => handleTabChange({} as unknown as SyntheticEvent, value), 3000);
227+
setTimeout(() => handleTabChange({} as unknown as SyntheticEvent, value), 3000);
293228
setFirst(false);
294229
}
295230
});
296231

297232
return (<Box sx={{ width: '100%' }}>
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>
233+
<Tabs value={value} onChange={handleTabChange} centered={true}>
234+
<Tab label="Current Prices"/>
235+
<Tab label="Last Price matches"/>
236+
<Tab label="Current Prices Map"/>
237+
</Tabs>
238+
{ value === 0 &&
239+
<DataTable diesel='Diesel' e10='E10' e5='E5' location='Location' showAverages={true} time='Time' rows={rows}></DataTable>}
240+
{ value === 1 &&
241+
<Chart timeSlots={avgTimeSlots}></Chart>}
242+
{ value === 1 &&
243+
<DataTable diesel='Diesel' e10='E10' e5='E5' location='Location' showAverages={true} time='Time' rows={rows}></DataTable>}
244+
{ value === 2 &&
245+
<GsMap gsValues={gsValues} center={globalUserDataState}></GsMap>}
309246
</Box>);
310247
}

0 commit comments

Comments
 (0)