index.tsx (2544B)
1 import React from "react"; 2 import { Route, BrowserRouter as Router, Switch } from "react-router-dom"; 3 4 import CreateEvent from "./pages/CreateEvent"; 5 import DualConvertor from "./pages/DualConvertor"; 6 import FutureConversion from "./pages/FutureConversion"; 7 import Help from "./pages/Help"; 8 import SimpleConvertor from "./pages/SimpleConvertor"; 9 import UNIXTime from "./pages/UNIXTime"; 10 11 import Footer from "./comps/Footer"; 12 import Header from "./comps/Header"; 13 14 import { displayTime } from "../utils"; 15 import { basePath, DEFAULT_TZ, HM, localTimezone, YMD } from "../utils"; 16 import useTime from "../utils/useTime"; 17 18 function App<never>(): JSX.Element { 19 const now = useTime(); 20 const [timezone1, setTimezone1] = React.useState(DEFAULT_TZ); 21 const [timezone2, setTimezone2] = React.useState(localTimezone); 22 const [date, setDate] = React.useState( 23 displayTime({ fmtStr: YMD, time: now, timezone: localTimezone }) 24 ); 25 const [time, setTime] = React.useState( 26 displayTime({ fmtStr: HM, time: now, timezone: localTimezone }) 27 ); 28 29 return ( 30 <Router> 31 <div 32 className="container-fluid" 33 style={{ paddingLeft: 0, paddingRight: 0 }} 34 > 35 <Header /> 36 <Switch> 37 <Route 38 path={`${basePath}/future`} 39 render={() => ( 40 <FutureConversion 41 date={date} 42 setDate={setDate} 43 setTime={setTime} 44 setTZ1={setTimezone1} 45 setTZ2={setTimezone2} 46 time={time} 47 TZ1={timezone1} 48 TZ2={timezone2} 49 /> 50 )} 51 /> 52 <Route path={`${basePath}/help`} render={() => <Help time={now} />} /> 53 <Route 54 path={`${basePath}/from-to`} 55 render={() => ( 56 <DualConvertor 57 setTZ1={setTimezone2} 58 setTZ2={setTimezone1} 59 time={now} 60 TZ1={timezone2} 61 TZ2={timezone1} 62 /> 63 )} 64 /> 65 <Route path={`${basePath}/create`} render={() => <CreateEvent />} /> 66 <Route path={`${basePath}/([0-9]+)`} render={() => <UNIXTime />} /> 67 <Route 68 path={`${basePath}/`} 69 render={() => ( 70 <SimpleConvertor 71 setTZ1={setTimezone1} 72 time={now} 73 TZ1={timezone1} 74 /> 75 )} 76 /> 77 </Switch> 78 <Footer /> 79 </div> 80 </Router> 81 ); 82 } 83 84 export default App;