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
4 changes: 4 additions & 0 deletions public/world-clocks-vector-436373.jpg:Zone.Identifier
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=https://www.google.com/
HostUrl=https://cdn4.vectorstock.com/i/1000x1000/63/73/world-clocks-vector-436373.jpg
5 changes: 3 additions & 2 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
}

.App-logo {
height: 40vmin;
height: 30vmin;
width: 40vmin;
pointer-events: none;
}

Expand All @@ -14,6 +15,6 @@
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
font-size: calc(5px + 1vmin);
color: white;
}
16 changes: 11 additions & 5 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import React from "react";
import logo from "./logo.png";
import logo from "./clock.jpg";
import "./App.css";
import Clock from "./clock";

class App extends React.Component {
// call clearInterval tear down the tier

render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<h1>Coordinated Universal Time</h1>
{/* Render date value that is stored in state */}
<Clock timeZone={"Asia/Singapore"} />
<Clock timeZone={"UTC"} />
{[1, 1, 1, 1, 1].map(() => (
<Clock timeZone={"UTC"} />
))}
</header>
</div>
);
}
}

export default App;
Empty file added src/WorldClock.js
Empty file.
Binary file added src/clock.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions src/clock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from "react";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

File should be capital Clock.js as this is a component. Components always capitalized


class Clock extends React.Component {
constructor(props) {
super(props);
this.timeZone = props.timeZone;
Comment on lines +4 to +6
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this here is unnecessary. You should just be able to use this.props to access the props from anywhere in the component without defining those in the constructor

// Initialise component state to contain "date" attribute with current date and time
this.state = { date: new Date() };
console.log(props.timeZone);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Let's always remove console logs before pushing our code, as those are just for debugging

}

componentDidMount() {
// Set date value in state every second to current date and time
// Save setInterval timer ID in class variable for teardown in another class method
function updateDate() {
this.setState({date: new Date()})
console.log("hi")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

can remove

}
setInterval(updateDate, 10000);

this.timerId = setInterval(() => {
// callback function
this.setState({
date: new Date(),
});
}, 1000);
}

componentWillUnmount() {
// Teardown setInterval timer with timer ID saved as class variable
clearInterval(this.timerId);
}

render() {
return (
// Render date value that is stored in state
<p>
{this.state.date.toLocaleString("en-GB", { timeZone: this.timeZone })}
</p>
);
}
}

export default Clock;
21 changes: 21 additions & 0 deletions src/container.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// import Container from "react-bootstrap/Container";
// import Row from "react-bootstrap/Row";
// import Col from "react-bootstrap/Col";


// function container() {
// return (
// <Container>
// <Row>
// <Col>1 of 2</Col>
// <Col>2 of 2</Col>
// </Row>
// <Row>
// <Col>1 of 3</Col>
// <Col>2 of 3</Col>
// </Row>
// </Container>
// );
// }

// export default container;
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";


const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<App />);