Compare commits
No commits in common. "e078607eb4d5f1d5d1a5c426f51292b6aa44c11b" and "dcccaf796207cbee55d8818919d6fa36ccc4ec10" have entirely different histories.
e078607eb4
...
dcccaf7962
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"files.trimTrailingWhitespace": true,
|
|
||||||
"files.insertFinalNewline": true,
|
|
||||||
"files.trimFinalNewlines": true,
|
|
||||||
"editor.renderFinalNewline": false
|
|
||||||
}
|
|
80
README.md
80
README.md
@ -1,12 +1,76 @@
|
|||||||
# StopWatch
|
# Second Clock
|
||||||
|
|
||||||
## RUN GUIDE
|
Temporary available in
|
||||||
|
http://g2vb-h3ut-r9pw-ixj3.devices.waren.io:3000
|
||||||
|
================================================================
|
||||||
|
|
||||||
1. Build Docker Image – `docker build -t cwchristerw/stopwatch .`
|
# Getting Started with Create React App
|
||||||
2. Run Container – `docker run --rm cwchristerw/stopwatch`
|
|
||||||
3. Open Web Browser – `http://172.17.0.[N]:3000`
|
|
||||||
|
|
||||||
## UPDATE GUIDE
|
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||||
|
|
||||||
1. Build Docker Image – `docker build -t cwchristerw/stopwatch .`
|
## Available Scripts
|
||||||
2. Run Container with npm update command – `docker run --rm -v "$PWD":/usr/src/app/ cwchristerw/stopwatch npm update`
|
|
||||||
|
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)
|
||||||
|
17302
package-lock.json
generated
17302
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
21
package.json
21
package.json
@ -1,17 +1,18 @@
|
|||||||
{
|
{
|
||||||
"name": "stopwatch",
|
"name": "second-clock",
|
||||||
"version": "0.1.1",
|
"version": "0.1.0",
|
||||||
"description": "StopWatch",
|
"description": "Second Clock",
|
||||||
"author": "Christer Warén",
|
"author": "Christer Warén",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
"homepage": "http://g2vb-h3ut-r9pw-ixj3.devices.waren.io:3000",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@testing-library/jest-dom": "^5.16.4",
|
"@testing-library/jest-dom": "^5.11.8",
|
||||||
"@testing-library/react": "^13.3.0",
|
"@testing-library/react": "^11.2.2",
|
||||||
"@testing-library/user-event": "^14.2.1",
|
"@testing-library/user-event": "^12.6.0",
|
||||||
"react": "^18.2.0",
|
"react": "^17.0.1",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^17.0.1",
|
||||||
"react-scripts": "^5.0.1",
|
"react-scripts": "4.0.1",
|
||||||
"web-vitals": "^2.1.4"
|
"web-vitals": "^0.2.4"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "react-scripts start",
|
"start": "react-scripts start",
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
work correctly both with client-side routing and a non-root public URL.
|
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`.
|
Learn how to configure a non-root public URL by running `npm run build`.
|
||||||
-->
|
-->
|
||||||
<title>Stopwatch</title>
|
<title>React App</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"short_name": "Stopwatch",
|
"short_name": "Second Clock",
|
||||||
"name": "Stopwatch",
|
"name": "Second Clock",
|
||||||
"icons": [
|
"icons": [
|
||||||
{
|
{
|
||||||
"src": "favicon.ico",
|
"src": "favicon.ico",
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
.App {
|
.App {
|
||||||
background-color: #373b43;
|
|
||||||
min-height: 100vh;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,10 +47,3 @@
|
|||||||
transform: rotate(360deg);
|
transform: rotate(360deg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@media (orientation: portrait) {
|
|
||||||
.App-content {
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -2,8 +2,6 @@ import logo from './logo.svg';
|
|||||||
import './App.css';
|
import './App.css';
|
||||||
import Timer from './Timer';
|
import Timer from './Timer';
|
||||||
import './Timer.css';
|
import './Timer.css';
|
||||||
import List from './List';
|
|
||||||
import './List.css';
|
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
@ -13,7 +11,6 @@ function App() {
|
|||||||
</header>
|
</header>
|
||||||
<main className="App-content">
|
<main className="App-content">
|
||||||
<Timer />
|
<Timer />
|
||||||
<List />
|
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
15
src/List.css
15
src/List.css
@ -1,15 +0,0 @@
|
|||||||
.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
30
src/List.js
@ -1,30 +0,0 @@
|
|||||||
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,16 +1,17 @@
|
|||||||
.timer {
|
.app {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
background-color: #282c34;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
font-size: calc(10px + 2vmin);
|
font-size: calc(10px + 2vmin);
|
||||||
color: white;
|
color: white;
|
||||||
flex: 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.time {
|
.time {
|
||||||
font-size: 3rem;
|
font-size: 3rem;
|
||||||
|
padding: 2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button {
|
.button {
|
||||||
@ -20,7 +21,6 @@
|
|||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
font-size: .8rem;
|
font-size: .8rem;
|
||||||
border: 1px solid #1b1f2b;
|
|
||||||
border-style: groove;
|
border-style: groove;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,10 +28,6 @@
|
|||||||
outline-width: 0;
|
outline-width: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button:hover {
|
|
||||||
background-color: #e8e7e6;
|
|
||||||
}
|
|
||||||
|
|
||||||
.button-primary:hover {
|
.button-primary:hover {
|
||||||
background-color: #2641d4;
|
background-color: #2641d4;
|
||||||
border: 1px solid #1b1f2b;
|
border: 1px solid #1b1f2b;
|
||||||
@ -48,12 +44,3 @@
|
|||||||
border: 1px solid #152684;
|
border: 1px solid #152684;
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
form {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
form p {
|
|
||||||
margin-bottom: 0px;
|
|
||||||
}
|
|
36
src/Timer.js
36
src/Timer.js
@ -1,23 +1,19 @@
|
|||||||
// Timer is based on these with changes
|
// I used code as basis to this Timer
|
||||||
|
|
||||||
// Build a React Timer Component Using Hooks by James King
|
// Build a React Timer Component Using Hooks by James King
|
||||||
// https://upmostly.com/tutorials/build-a-react-timer-component-using-hooks
|
// https://upmostly.com/tutorials/build-a-react-timer-component-using-hooks
|
||||||
|
|
||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
|
|
||||||
const Timer = () => {
|
const Timer = () => {
|
||||||
const [startTime, setStartTime] = useState(0);
|
const [seconds, setSeconds] = useState(0);
|
||||||
const [elapsedTime, setElapsedTime] = useState("0.0");
|
|
||||||
const [isActive, setIsActive] = useState(false);
|
const [isActive, setIsActive] = useState(false);
|
||||||
|
|
||||||
function toggle() {
|
function toggle() {
|
||||||
setStartTime(new Date());
|
|
||||||
setIsActive(!isActive);
|
setIsActive(!isActive);
|
||||||
}
|
}
|
||||||
|
|
||||||
function stop() {
|
function stop() {
|
||||||
setStartTime(0);
|
setSeconds(0);
|
||||||
setElapsedTime("0.0");
|
|
||||||
setIsActive(false);
|
setIsActive(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,37 +21,25 @@ const Timer = () => {
|
|||||||
let interval = null;
|
let interval = null;
|
||||||
if (isActive) {
|
if (isActive) {
|
||||||
interval = setInterval(() => {
|
interval = setInterval(() => {
|
||||||
let epochElapsedTime = new Date() - startTime;
|
setSeconds(seconds => seconds + 1);
|
||||||
|
}, 1000);
|
||||||
let elapsedTime = {
|
} else if (!isActive && seconds !== 0) {
|
||||||
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);
|
clearInterval(interval);
|
||||||
}
|
}
|
||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
}, [isActive, startTime, elapsedTime]);
|
}, [isActive, seconds]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="timer">
|
<div className="timer">
|
||||||
<div className="time">
|
<div className="time">
|
||||||
{elapsedTime}
|
{seconds}s
|
||||||
</div>
|
</div>
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<button className={`button button-primary button-primary-${isActive ? 'active' : 'inactive'}`} onClick={toggle}>
|
<button className={`button button-primary button-primary-${isActive ? 'active' : 'inactive'}`} onClick={toggle}>
|
||||||
{isActive ? 'Pause' : 'Start'}
|
{isActive ? 'Pause' : 'Start'}
|
||||||
</button>
|
</button>
|
||||||
<button className="button" onClick={stop}>
|
<button className="button" onClick={stop}>
|
||||||
Stop
|
Stop
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user