-
-
Notifications
You must be signed in to change notification settings - Fork 806
/
GameTable.jsx
71 lines (66 loc) · 2.3 KB
/
GameTable.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { useEffect, useState } from 'react';
import shuffle from './utils/shuffleArray';
import SchulteTable from './components/SchulteTable';
import timeFormatter from './utils/timeFormatter';
const GameTable = () => {
const [data, setData] = useState(shuffle());
const [start, setStart] = useState(false);
const [nextNumber, setNextNumber] = useState(1);
const [result, setResult] = useState(null);
const restart = () => {
setResult(null);
setNextNumber(1);
setStart(true);
};
useEffect(() => {
const shuffledData = shuffle();
setData(shuffledData);
}, [nextNumber]);
return (
<main>
<h1 className="game-title mb-3">Schulte Table</h1>
{start && !result ? (
<SchulteTable
data={data}
nextNumber={nextNumber}
setNextNumber={setNextNumber}
setResult={setResult}
setStart={setStart}
start={start}
/>
) : (
<section className="center col">
{!result && (
<>
<button className="start-btn" onClick={() => setStart(true)}>
start
</button>
<p className="description">
Schulte tables are tables with randomly arranged characters, usually numbers used to
check and develop the speed of their visual search in a specific order. These tables
were originally developed by the German psychotherapist Walter Schulte as a
psychodiagnostic test for studying the properties of attention.
</p>
</>
)}
</section>
)}
{result && (
<section className="result-section">
<h1>Completed in {timeFormatter(result)}</h1>
<br />
<button className="start-btn" onClick={restart}>
Restart
</button>
<p className="description">
Schulte tables are tables with randomly arranged characters, usually numbers used to
check and develop the speed of their visual search in a specific order. These tables
were originally developed by the German psychotherapist Walter Schulte as a
psychodiagnostic test for studying the properties of attention.
</p>
</section>
)}
</main>
);
};
export default GameTable;