1
0

Compare commits

..

10 Commits

Author SHA1 Message Date
Christer Warén
e078607eb4 Update List.js 2022-06-17 13:18:23 +03:00
Christer Warén
16d5982451 Update README.md 2022-06-17 13:18:08 +03:00
Christer Warén
bb43900531 Bumb Version & Update Dependencies 2022-06-17 13:17:48 +03:00
Christer Warén
163050649a Add VSCode settings 2022-03-05 15:56:33 +02:00
Christer Warén
8b0c92969a Updated Timer CSS 2021-01-04 22:57:10 +02:00
Christer Warén
fe6b12b34e Updated Timer 2021-01-04 20:02:38 +02:00
Christer Warén
1c635092be Added List 2021-01-04 20:02:16 +02:00
Christer Warén
3c12e42f61 Updated CSS 2021-01-04 16:49:01 +02:00
Christer Warén
2b87ee958a Changed package name 2021-01-04 16:48:51 +02:00
Christer Warén
ed92909aa5 Updated layout 2021-01-04 16:00:47 +02:00
12 changed files with 6267 additions and 11212 deletions

6
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,6 @@
{
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"editor.renderFinalNewline": false
}

View File

@ -1,76 +1,12 @@
# Second Clock # StopWatch
Temporary available in ## RUN GUIDE
http://g2vb-h3ut-r9pw-ixj3.devices.waren.io:3000
================================================================
# 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 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`
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 cant go back!**
If you arent 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 youre on your own.
You dont have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldnt feel obligated to use this feature. However we understand that this tool wouldnt be useful if you couldnt 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)

17238
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,18 +1,17 @@
{ {
"name": "second-clock", "name": "stopwatch",
"version": "0.1.0", "version": "0.1.1",
"description": "Second Clock", "description": "StopWatch",
"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.11.8", "@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^11.2.2", "@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^12.6.0", "@testing-library/user-event": "^14.2.1",
"react": "^17.0.1", "react": "^18.2.0",
"react-dom": "^17.0.1", "react-dom": "^18.2.0",
"react-scripts": "4.0.1", "react-scripts": "^5.0.1",
"web-vitals": "^0.2.4" "web-vitals": "^2.1.4"
}, },
"scripts": { "scripts": {
"start": "react-scripts start", "start": "react-scripts start",

View File

@ -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>React App</title> <title>Stopwatch</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>

View File

@ -1,6 +1,6 @@
{ {
"short_name": "Second Clock", "short_name": "Stopwatch",
"name": "Second Clock", "name": "Stopwatch",
"icons": [ "icons": [
{ {
"src": "favicon.ico", "src": "favicon.ico",

View File

@ -1,4 +1,6 @@
.App { .App {
background-color: #373b43;
min-height: 100vh;
text-align: center; text-align: center;
} }
@ -47,3 +49,10 @@
transform: rotate(360deg); transform: rotate(360deg);
} }
} }
@media (orientation: portrait) {
.App-content {
flex-direction: column;
}
}

View File

@ -2,6 +2,8 @@ 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 (
@ -11,6 +13,7 @@ function App() {
</header> </header>
<main className="App-content"> <main className="App-content">
<Timer /> <Timer />
<List />
</main> </main>
</div> </div>
); );

15
src/List.css Normal file
View 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
View 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;

View File

@ -1,17 +1,16 @@
.app { .timer {
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 {
@ -21,6 +20,7 @@
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,6 +28,10 @@
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;
@ -44,3 +48,12 @@
border: 1px solid #152684; border: 1px solid #152684;
color: white; color: white;
} }
form {
display: flex;
flex-direction: column;
}
form p {
margin-bottom: 0px;
}

View File

@ -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 // 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 [seconds, setSeconds] = useState(0); const [startTime, setStartTime] = 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() {
setSeconds(0); setStartTime(0);
setElapsedTime("0.0");
setIsActive(false); setIsActive(false);
} }
@ -21,18 +25,30 @@ const Timer = () => {
let interval = null; let interval = null;
if (isActive) { if (isActive) {
interval = setInterval(() => { interval = setInterval(() => {
setSeconds(seconds => seconds + 1); let epochElapsedTime = new Date() - startTime;
}, 1000);
} else if (!isActive && seconds !== 0) { 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); clearInterval(interval);
} }
return () => clearInterval(interval); return () => clearInterval(interval);
}, [isActive, seconds]); }, [isActive, startTime, elapsedTime]);
return ( return (
<div className="timer"> <div className="timer">
<div className="time"> <div className="time">
{seconds}s {elapsedTime}
</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}>