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' ;
1414import { useEffect , useState , SyntheticEvent } from 'react' ;
1515import DataTable , { TableDataRow } from './DataTable' ;
1616import GsMap , { GsValue } from './GsMap' ;
1717import { useRecoilRefresher_UNSTABLE , useRecoilValue } from 'recoil' ;
1818import GlobalState from '../GlobalState' ;
1919import styles from './main.module.scss' ;
2020import Chart , { TimeSlot } from './Chart' ;
21+ import { BrowserRouter , Outlet , Route , Routes , Link } from 'react-router-dom' ;
22+
2123
2224interface 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}
0 commit comments