Compare commits
10 Commits
dcccaf7962
...
e078607eb4
Author | SHA1 | Date | |
---|---|---|---|
|
e078607eb4 | ||
|
16d5982451 | ||
|
bb43900531 | ||
|
163050649a | ||
|
8b0c92969a | ||
|
fe6b12b34e | ||
|
1c635092be | ||
|
3c12e42f61 | ||
|
2b87ee958a | ||
|
ed92909aa5 |
6
.vscode/settings.json
vendored
Normal file
6
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"files.trimTrailingWhitespace": true,
|
||||
"files.insertFinalNewline": true,
|
||||
"files.trimFinalNewlines": true,
|
||||
"editor.renderFinalNewline": false
|
||||
}
|
80
README.md
80
README.md
@ -1,76 +1,12 @@
|
||||
# Second Clock
|
||||
# StopWatch
|
||||
|
||||
Temporary available in
|
||||
http://g2vb-h3ut-r9pw-ixj3.devices.waren.io:3000
|
||||
================================================================
|
||||
## RUN GUIDE
|
||||
|
||||
# Getting Started with Create React App
|
||||
1. Build Docker Image – `docker build -t cwchristerw/stopwatch .`
|
||||
2. Run Container – `docker run --rm cwchristerw/stopwatch`
|
||||
3. Open Web Browser – `http://172.17.0.[N]:3000`
|
||||
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
## UPDATE GUIDE
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### `npm start`
|
||||
|
||||
Runs the app in the development mode.\
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
|
||||
|
||||
The page will reload if you make edits.\
|
||||
You will also see any lint errors in the console.
|
||||
|
||||
### `npm test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.\
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
### `npm run build`
|
||||
|
||||
Builds the app for production to the `build` folder.\
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.\
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
### `npm run eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
|
||||
|
||||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
|
||||
|
||||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||
|
||||
### Code Splitting
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
|
||||
|
||||
### Analyzing the Bundle Size
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
|
||||
|
||||
### Making a Progressive Web App
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
|
||||
|
||||
### Advanced Configuration
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
|
||||
|
||||
### Deployment
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
|
||||
|
||||
### `npm run build` fails to minify
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
|
||||
1. Build Docker Image – `docker build -t cwchristerw/stopwatch .`
|
||||
2. Run Container with npm update command – `docker run --rm -v "$PWD":/usr/src/app/ cwchristerw/stopwatch npm update`
|
||||
|
17254
package-lock.json
generated
17254
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
21
package.json
21
package.json
@ -1,18 +1,17 @@
|
||||
{
|
||||
"name": "second-clock",
|
||||
"version": "0.1.0",
|
||||
"description": "Second Clock",
|
||||
"name": "stopwatch",
|
||||
"version": "0.1.1",
|
||||
"description": "StopWatch",
|
||||
"author": "Christer Warén",
|
||||
"private": true,
|
||||
"homepage": "http://g2vb-h3ut-r9pw-ixj3.devices.waren.io:3000",
|
||||
"dependencies": {
|
||||
"@testing-library/jest-dom": "^5.11.8",
|
||||
"@testing-library/react": "^11.2.2",
|
||||
"@testing-library/user-event": "^12.6.0",
|
||||
"react": "^17.0.1",
|
||||
"react-dom": "^17.0.1",
|
||||
"react-scripts": "4.0.1",
|
||||
"web-vitals": "^0.2.4"
|
||||
"@testing-library/jest-dom": "^5.16.4",
|
||||
"@testing-library/react": "^13.3.0",
|
||||
"@testing-library/user-event": "^14.2.1",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-scripts": "^5.0.1",
|
||||
"web-vitals": "^2.1.4"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
|
@ -24,7 +24,7 @@
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>React App</title>
|
||||
<title>Stopwatch</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"short_name": "Second Clock",
|
||||
"name": "Second Clock",
|
||||
"short_name": "Stopwatch",
|
||||
"name": "Stopwatch",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
|
@ -1,4 +1,6 @@
|
||||
.App {
|
||||
background-color: #373b43;
|
||||
min-height: 100vh;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@ -47,3 +49,10 @@
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@media (orientation: portrait) {
|
||||
.App-content {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ import logo from './logo.svg';
|
||||
import './App.css';
|
||||
import Timer from './Timer';
|
||||
import './Timer.css';
|
||||
import List from './List';
|
||||
import './List.css';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
@ -11,6 +13,7 @@ function App() {
|
||||
</header>
|
||||
<main className="App-content">
|
||||
<Timer />
|
||||
<List />
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
|
15
src/List.css
Normal file
15
src/List.css
Normal file
@ -0,0 +1,15 @@
|
||||
.list {
|
||||
text-align: center;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: calc(10px + 2vmin);
|
||||
color: white;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.timings ul {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
}
|
30
src/List.js
Normal file
30
src/List.js
Normal file
@ -0,0 +1,30 @@
|
||||
import React from 'react';
|
||||
//import React, { useState, useEffect } from 'react';
|
||||
|
||||
const List = () => {
|
||||
let list = [];
|
||||
if (list.length === 0) {
|
||||
list.push('No times saved');
|
||||
}
|
||||
|
||||
function clear() {
|
||||
list = [];
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="list">
|
||||
<div className="timings">
|
||||
<ul>
|
||||
{list.map((item, index) => (
|
||||
<li key={index}>{item}</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
<button className="button" onClick={clear}>
|
||||
Clear list
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default List;
|
@ -1,17 +1,16 @@
|
||||
.app {
|
||||
.timer {
|
||||
text-align: center;
|
||||
background-color: #282c34;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: calc(10px + 2vmin);
|
||||
color: white;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.time {
|
||||
font-size: 3rem;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.button {
|
||||
@ -21,6 +20,7 @@
|
||||
text-transform: uppercase;
|
||||
font-weight: 600;
|
||||
font-size: .8rem;
|
||||
border: 1px solid #1b1f2b;
|
||||
border-style: groove;
|
||||
}
|
||||
|
||||
@ -28,6 +28,10 @@
|
||||
outline-width: 0;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
background-color: #e8e7e6;
|
||||
}
|
||||
|
||||
.button-primary:hover {
|
||||
background-color: #2641d4;
|
||||
border: 1px solid #1b1f2b;
|
||||
@ -44,3 +48,12 @@
|
||||
border: 1px solid #152684;
|
||||
color: white;
|
||||
}
|
||||
|
||||
form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
form p {
|
||||
margin-bottom: 0px;
|
||||
}
|
36
src/Timer.js
36
src/Timer.js
@ -1,19 +1,23 @@
|
||||
// I used code as basis to this Timer
|
||||
// Timer is based on these with changes
|
||||
|
||||
// Build a React Timer Component Using Hooks by James King
|
||||
// https://upmostly.com/tutorials/build-a-react-timer-component-using-hooks
|
||||
|
||||
import React, { useState, useEffect } from 'react';
|
||||
|
||||
const Timer = () => {
|
||||
const [seconds, setSeconds] = useState(0);
|
||||
const [startTime, setStartTime] = useState(0);
|
||||
const [elapsedTime, setElapsedTime] = useState("0.0");
|
||||
const [isActive, setIsActive] = useState(false);
|
||||
|
||||
function toggle() {
|
||||
setStartTime(new Date());
|
||||
setIsActive(!isActive);
|
||||
}
|
||||
|
||||
function stop() {
|
||||
setSeconds(0);
|
||||
setStartTime(0);
|
||||
setElapsedTime("0.0");
|
||||
setIsActive(false);
|
||||
}
|
||||
|
||||
@ -21,25 +25,37 @@ const Timer = () => {
|
||||
let interval = null;
|
||||
if (isActive) {
|
||||
interval = setInterval(() => {
|
||||
setSeconds(seconds => seconds + 1);
|
||||
}, 1000);
|
||||
} else if (!isActive && seconds !== 0) {
|
||||
let epochElapsedTime = new Date() - startTime;
|
||||
|
||||
let elapsedTime = {
|
||||
minutes: new Date(epochElapsedTime).getMinutes(),
|
||||
seconds: new Date(epochElapsedTime).getSeconds(),
|
||||
milliseconds: new Date(epochElapsedTime).getMilliseconds()
|
||||
};
|
||||
|
||||
if(elapsedTime.minutes !== 0){
|
||||
setElapsedTime(elapsedTime.minutes + ":" + elapsedTime.seconds + "." + elapsedTime.milliseconds);
|
||||
} else {
|
||||
setElapsedTime(elapsedTime.seconds + "." + elapsedTime.milliseconds);
|
||||
}
|
||||
}, 10);
|
||||
} else if (!isActive && startTime !== 0 && elapsedTime !== "0.0") {
|
||||
clearInterval(interval);
|
||||
}
|
||||
return () => clearInterval(interval);
|
||||
}, [isActive, seconds]);
|
||||
}, [isActive, startTime, elapsedTime]);
|
||||
|
||||
return (
|
||||
<div className="timer">
|
||||
<div className="time">
|
||||
{seconds}s
|
||||
{elapsedTime}
|
||||
</div>
|
||||
<div className="row">
|
||||
<button className={`button button-primary button-primary-${isActive ? 'active' : 'inactive'}`} onClick={toggle}>
|
||||
{isActive ? 'Pause' : 'Start'}
|
||||
{isActive ? 'Pause' : 'Start'}
|
||||
</button>
|
||||
<button className="button" onClick={stop}>
|
||||
Stop
|
||||
Stop
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user