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
1,874 changes: 1,295 additions & 579 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
"name": "world-clock-bootcamp",
"version": "0.1.0",
"private": true,
"homepage": "https://kenleeyx.github.io/world-clock-bootcamp",
"dependencies": {
"bootstrap": "^5.3.1",
"gh-pages": "^6.0.0",
"react": "^18.1.0",
"react-bootstrap": "^2.8.0",
"react-dom": "^18.1.0",
"react-scripts": "5.0.1"
},
"scripts": {
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
"start": "react-scripts start",
"build": "react-scripts build"
},
Expand Down
1 change: 1 addition & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
font-size: calc(10px + 2vmin);
color: white;
}

7 changes: 4 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import React from "react";
import logo from "./logo.png";
import "./App.css";
import 'bootstrap/dist/css/bootstrap.min.css';
import WorldClock from "./WorldClock.js";

class App extends React.Component {
render() {
const timeZones = ['Asia/Singapore', 'America/Los_Angeles', 'Europe/London'];
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>
<WorldClock clockData = {timeZones}/>
</header>
</div>
);
Expand Down
33 changes: 33 additions & 0 deletions src/Clock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from "react";

export default class Clock extends React.Component {
constructor(props) {
super(props);
this.state = {
date: new Date()
};
}

tick() {
this.setState({
date: new Date()
})
}

componentDidMount(){
this.timerId = setInterval(()=>this.tick(), 1000);
}

componentWillUnmount(){
clearInterval(this.timerId);
}

render() {
const {zone} = this.props
return (
<div>
<p>{this.state.date.toLocaleString('en-GB', {timeZone: zone})}</p>
</div>
);
}
}
32 changes: 32 additions & 0 deletions src/WorldClock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from "react";
import Clock from "./Clock";
import Container from 'react-bootstrap/Container';
import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';

export default class WorldClock extends React.Component {
constructor(props) { //figure out how to add clockdata prop into here - array of timezone strings
super(props);
}

render() {
const {clockData} = this.props;
const clocks = clockData.map((timeZone)=>
<Row key = {timeZone.toString()}>
<Col>{timeZone}</Col>
<Col><Clock zone={timeZone}/></Col>
</Row>
);
return (
<div>
<Container>
<Row>
<Col>City</Col>
<Col>Clock</Col>
</Row>
{clocks}
</Container>
</div>
);
}
}
12 changes: 12 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,15 @@ import App from "./App";

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

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

// setInterval(tick, 1000);