diff --git a/src/App.css b/src/App.css index e1c10c6..0ef653a 100644 --- a/src/App.css +++ b/src/App.css @@ -37,3 +37,29 @@ .read-the-docs { color: #888; } + +.table-row { + display: flex; + justify-content: center; + align-items: center; +} + +.table-cell { + padding: 10px; /* Add padding to cells */ + width: 150px; + justify-content: center; + align-items: center; +} + +.table-time { + padding: 10px; /* Add padding to cells */ + width: 300px; + align-items: center; + justify-content: center; +} +.table-cell:last-child { + padding: 10px; /* Add padding to cells */ + width: 300px; + align-items: center; + justify-content: center; +} diff --git a/src/App.jsx b/src/App.jsx index 9d138e2..84528c4 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,20 +1,76 @@ import logo from "/logo.png"; import "./App.css"; +import { useState } from "react"; +import { useEffect } from "react"; +import Clock from "./Clock"; +import Container from "react-bootstrap/Container"; +import Row from "react-bootstrap/Row"; +import Col from "react-bootstrap/Col"; -function App() { +export default function App() { return ( - <> -
- Rocket logo -
+
+ Rocket logo

World Clock

-

- Edit src/App.jsx and save to test HMR -

+ {/* This feels violative of the DIY principle, but idk how to make it into a component */} + + + City + Clock + + + +

Asia/Seoul

+ + +

+ +

+ +
+ + +

Asia/Singapore

+ + +

+ +

+ +
+ + +

Europe/London

+ + +

+ +

+ +
+
- +
); } -export default App; +// This works too but the boxes are not aligned +//
+// +// +// City +// Clock +// +// +// +// +// +// +// +// +// +// +// +//
+// diff --git a/src/Clock.jsx b/src/Clock.jsx new file mode 100644 index 0000000..e3bd036 --- /dev/null +++ b/src/Clock.jsx @@ -0,0 +1,25 @@ +import { useState } from "react"; +import { useEffect } from "react"; + +// Clock function +export default function Clock(props) { + // useState allows you to add state to functional components. It essentially allows you to store and update data. + const [date, setDate] = useState(new Date()); + // useEffect tells the clock to move by second. useEffect is used to perform side effects in a component. + useEffect(() => { + const timeId = setInterval(() => { + setDate(new Date()); + }, 1000); + return () => { + clearInterval(timeId); + }; + }); + + return ( + // Add time zone label to make it clearer which time zone each clock is rendering. + <> + {/* {props.timeZone} */} +

{date.toLocaleString("en-GB", { timeZone: `${props.timeZone}` })}

+ + ); +} diff --git a/src/main.jsx b/src/main.jsx index ac77a71..3be7432 100644 --- a/src/main.jsx +++ b/src/main.jsx @@ -1,5 +1,6 @@ import ReactDOM from "react-dom/client"; import App from "./App.jsx"; import "./index.css"; +// import "bootstrap/dist/css/bootstrap.min.css"; ReactDOM.createRoot(document.getElementById("root")).render();