Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,32 @@
.read-the-docs {
color: #888;
}
.table-row {
display: flex;
border: 1px solid #ccc; /* Add a bottom border to each row */
justify-content: center;
align-items: center;
}

.table-cell {
padding: 10px; /* Add padding to cells */

width: 170px;
justify-content: center;
align-items: center;
}

.table-time {
padding: 10px; /* Add padding to cells */
border: 1px solid #ccc; /* Add a right border to cells */
width: 300px;
align-items: center;
justify-content: center;
}
.table-cell:last-child {
padding: 10px; /* Add padding to cells */
border: 1px solid #ccc; /* Add a right border to cells */
width: 300px;
align-items: center;
justify-content: center;
}
63 changes: 49 additions & 14 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,55 @@
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";
import Row from "react-bootstrap/Row";
import Col from "react-bootstrap/Col";
// import "bootstrap/dist/css/bootstrap.min.css";

function App() {
export default function App() {
return (
<>
<div>
<img src={logo} className="logo" alt="Rocket logo" />
</div>
<h1>World Clock</h1>
<div className="card">
<p>
Edit <code>src/App.jsx</code> and save to test HMR
</p>
</div>
</>
<Container>
<Row>
<Col>
<div>
<img src={logo} className="logo" alt="Rocket logo" />
</div>
</Col>
</Row>
<Row>
<Col>
<h1>Calvin's World Clock</h1>
<p>Best Effort</p>
</Col>
</Row>

<Row className="table-row">
<Col className="table-cell">Cities</Col>

<Col className="table-time">TimeZone</Col>
</Row>
<Row className="table-row">
<Col className="table-cell">Asia/Singapore:</Col>
<Col className="table-time">
<Clock timeZone="Asia/Singapore" />
</Col>
</Row>

<Row className="table-row">
<Col className="table-cell">Australia/Canberra:</Col>
<Col className="table-cell">
<Clock timeZone="Australia/Canberra" />
</Col>
</Row>

<Row className="table-row">
<Col className="table-cell">Europe/Berlin:</Col>
<Col className="table-cell">
<Clock timeZone="Europe/Berlin" />
</Col>
</Row>
Comment on lines +33 to +52
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can improve this by using a data structure and map it!

const data = [
{
    timeZone: "Europe/Berlin",
    city: "Berlin"
}, ...]

and then

data.map((item) => {
     return (
           <Row className="table-row">
        <Col className="table-cell">{item.city}</Col>
        <Col className="table-cell">
          <Clock timeZone={item.timeZone} />
        </Col>
      </Row>
     )
})

</Container>
);
}

export default App;
23 changes: 23 additions & 0 deletions src/Clock.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useState, useEffect } from "react";

export default function Clock(props) {
const [date, setDate] = useState(new Date());
//to run effect at each render to refresh by 1 second
useEffect(() => {
const timerId = setInterval(() => {
setDate(new Date());
}, 1000);
return () => {
clearInterval(timerId);
};
});
//Label for the time
return (
<>
<p>
{props.timeZone}:
{date.toLocaleString("en-GB", { timeZone: `${props.timeZone}` })}
</p>
</>
);
}
21 changes: 20 additions & 1 deletion src/main.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
import ReactDOM from "react-dom/client";
import App from "./App.jsx";
import "./index.css";
import React from "react";

ReactDOM.createRoot(document.getElementById("root")).render(<App />);
{
ReactDOM.createRoot(document.getElementById("root")).render(<App />);
}

// function tick() {
// const element = (
// <div>
// <h1> Hello, world!</h1>
// <h2> It is {new Date().toLocaleTimeString()}.</h2>
// <h2>
// <App />
// </h2>
// </div>
// );
// root.render(element);
// }
// setInterval(tick, 1000);

// const root = ReactDOM.createRoot(document.getElementById("root"));