mirror of
https://github.com/hazemKrimi/touch-programming.git
synced 2026-05-01 18:20:26 +00:00
Show a proper timer
This commit is contained in:
@@ -70,7 +70,7 @@ function Code({code, loaded}: CodeProps) {
|
||||
const incorrectlyTyped = characters.filter(char => !char).length;
|
||||
|
||||
if (timer > 0) {
|
||||
setScore((typed / 5 - incorrectlyTyped) / (timer / 60));
|
||||
setScore(Math.abs(typed / 5 - incorrectlyTyped) / (timer / 60));
|
||||
setAccuracy(correctlyTyped / typed * 100);
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { useTypingContext } from "contexts/typing";
|
||||
|
||||
import './index.css';
|
||||
import { renderTimer } from "./utils";
|
||||
|
||||
type StatsProps = {
|
||||
loaded: boolean;
|
||||
}
|
||||
|
||||
function Score({loaded}: StatsProps) {
|
||||
function Score({ loaded }: StatsProps) {
|
||||
const {
|
||||
timer,
|
||||
score,
|
||||
@@ -17,7 +18,7 @@ function Score({loaded}: StatsProps) {
|
||||
|
||||
return (
|
||||
<div className='score'>
|
||||
<p>Time: {timer}</p>
|
||||
{renderTimer(timer)}
|
||||
<p>WPM: {Math.round(score)}</p>
|
||||
<p>Accuracy: {Math.round(accuracy)}%</p>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
export function renderTimer(timer: number) {
|
||||
const leftValue = Math.round(timer / 60);
|
||||
const rightValue = timer < 60 ? timer : timer % 60;
|
||||
|
||||
return (
|
||||
<p>Time: {leftValue < 10 && 0}{leftValue}:{rightValue < 10 && 0}{rightValue}</p>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user