Skip to content

Commit e8d62b8

Browse files
committed
Merge branch 'master' of github.com:SERESLab/SERESLab.github.io
2 parents 2c6dc98 + 60ff984 commit e8d62b8

File tree

4 files changed

+268
-131
lines changed

4 files changed

+268
-131
lines changed
Lines changed: 84 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import React, { useEffect, useState } from 'react';
22

3-
// Settings for each face task variant
43
const FACE_TASKS = [
5-
{ gridSize: 2, trials: 25 }, // faceTask2.html
6-
{ gridSize: 3, trials: 25 }, // faceTask3.html
7-
{ gridSize: 4, trials: 25 }, // faceTask4.html
4+
{ gridSize: 2, trials: 25 },
5+
{ gridSize: 3, trials: 25 },
6+
{ gridSize: 4, trials: 25 },
87
];
98

10-
// Image counts (adjust if your assets differ)
119
const RIGHT_IMAGE_COUNT = 62;
1210
const WRONG_IMAGE_COUNT = 8;
1311

@@ -24,16 +22,15 @@ const FaceTask = () => {
2422
const [trial, setTrial] = useState(0);
2523
const [grid, setGrid] = useState([]);
2624
const [completed, setCompleted] = useState(false);
25+
const [showCross, setShowCross] = useState(true);
2726

28-
// Preload image paths
2927
const rightImagePaths = Array.from({ length: RIGHT_IMAGE_COUNT }, (_, i) =>
3028
require(`../assets/images/Right/image-${i + 1}.jpg`)
3129
);
3230
const wrongImagePaths = Array.from({ length: WRONG_IMAGE_COUNT }, (_, i) =>
3331
require(`../assets/images/Wrong/image-${i + 1}.jpg`)
3432
);
3533

36-
// Generate a new grid for each trial
3734
const generateNewGrid = () => {
3835
const totalCells = task.gridSize * task.gridSize;
3936
let newGrid = getRandomSubset(rightImagePaths, totalCells).map((src, i) => ({
@@ -42,7 +39,6 @@ const FaceTask = () => {
4239
isCorrect: false,
4340
}));
4441

45-
// Replace one random image with a wrong one
4642
const replacedIndex = Math.floor(Math.random() * totalCells);
4743
newGrid[replacedIndex] = {
4844
src: wrongImagePaths[Math.floor(Math.random() * wrongImagePaths.length)],
@@ -53,27 +49,29 @@ const FaceTask = () => {
5349
setGrid(newGrid);
5450
};
5551

56-
// Initialize the first grid only once
5752
useEffect(() => {
5853
generateNewGrid();
59-
// eslint-disable-next-line react-hooks/exhaustive-deps
60-
}, []); // Only run once on mount
54+
55+
const timer = setTimeout(() => {
56+
setShowCross(false);
57+
}, 10000); // 10 seconds
58+
59+
return () => clearTimeout(timer);
60+
}, []);
6161

6262
const handleClick = (index) => {
6363
if (completed) return;
64-
64+
6565
const newTrial = trial + 1;
6666
setTrial(newTrial);
67-
67+
6868
if (newTrial >= task.trials) {
6969
setCompleted(true);
7070
} else {
71-
// Generate new grid for next trial
7271
generateNewGrid();
7372
}
7473
};
7574

76-
// Dynamic grid style
7775
const gridStyle = {
7876
display: 'grid',
7977
gap: `${5 - task.gridSize}vw`,
@@ -96,42 +94,57 @@ const FaceTask = () => {
9694
height: '90vh',
9795
width: '100vw',
9896
overflow: 'hidden',
97+
position: 'relative',
98+
backgroundColor: '#fff',
9999
}}
100100
>
101-
<p
102-
id="completion-message"
103-
style={{
104-
display: completed ? 'block' : 'none',
105-
fontFamily: 'Arial, sans-serif',
106-
fontSize: 18,
107-
marginBottom: 20,
108-
}}
109-
>
110-
Completed, please move onto the next task!
111-
</p>
112-
{!completed && (
113-
<div className="grid" style={gridStyle}>
114-
{grid.map((image, idx) => (
115-
<img
116-
key={`${trial}-${image.id}`}
117-
src={image.src}
118-
className="grid-item"
119-
data-id={image.id}
120-
data-correct={image.isCorrect ? 'T' : 'F'}
121-
alt="Game"
122-
style={{
123-
objectFit: 'cover',
124-
cursor: 'pointer',
125-
border: '2px solid transparent',
126-
transition: '0.3s',
127-
width: `calc(70vh / ${task.gridSize + 1})`,
128-
height: `calc(70vh / ${task.gridSize + 1})`,
129-
}}
130-
onClick={() => handleClick(idx)}
131-
/>
132-
))}
133-
</div>
101+
{showCross && (
102+
console.log("Rendering fixation cross...") || (
103+
<div style={styles.crossContainer}>
104+
<div style={styles.cross}>+</div>
105+
</div>
106+
)
107+
)}
108+
109+
{!showCross && (
110+
<>
111+
<p
112+
id="completion-message"
113+
style={{
114+
display: completed ? 'block' : 'none',
115+
fontFamily: 'Arial, sans-serif',
116+
fontSize: 18,
117+
marginBottom: 20,
118+
}}
119+
>
120+
Completed, please move onto the next task!
121+
</p>
122+
{!completed && (
123+
<div className="grid" style={gridStyle}>
124+
{grid.map((image, idx) => (
125+
<img
126+
key={`${trial}-${image.id}`}
127+
src={image.src}
128+
className="grid-item"
129+
data-id={image.id}
130+
data-correct={image.isCorrect ? 'T' : 'F'}
131+
alt="Game"
132+
style={{
133+
objectFit: 'cover',
134+
cursor: 'pointer',
135+
border: '2px solid transparent',
136+
transition: '0.3s',
137+
width: `calc(70vh / ${task.gridSize + 1})`,
138+
height: `calc(70vh / ${task.gridSize + 1})`,
139+
}}
140+
onClick={() => handleClick(idx)}
141+
/>
142+
))}
143+
</div>
144+
)}
145+
</>
134146
)}
147+
135148
<style>{`
136149
.grid-item:hover {
137150
border-color: #3498db;
@@ -141,4 +154,26 @@ const FaceTask = () => {
141154
);
142155
};
143156

144-
export default FaceTask;
157+
// Styles
158+
const styles = {
159+
crossContainer: {
160+
position: 'absolute',
161+
top: 0,
162+
left: 0,
163+
height: '100vh',
164+
width: '100vw',
165+
display: 'flex',
166+
justifyContent: 'center',
167+
alignItems: 'center',
168+
zIndex: 9999,
169+
backgroundColor: '#fff',
170+
border: '3px dashed red', // Debug visual
171+
},
172+
cross: {
173+
fontSize: '100px',
174+
fontWeight: 'bold',
175+
color: 'black',
176+
},
177+
};
178+
179+
export default FaceTask;

webcamstudy/src/components/TextTask.jsx

Lines changed: 80 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { useEffect, useRef, useState } from 'react';
22

33
const TEXTS = [
4-
// textTask.html
54
`Twas brillig, and the slithy toves
65
Did gyre and gimble in the wabe:
76
All mimsy were the borogoves,
@@ -35,28 +34,7 @@ He chortled in his joy.
3534
’Twas brillig, and the slithy toves
3635
Did gyre and gimble in the wabe:
3736
All mimsy were the borogoves,
38-
And the mome raths outgrabe.`,
39-
// textTask2.html
40-
`This time Alice waited patiently until it chose to speak again.
41-
In a minute or two the Caterpillar took the hookah out of its mouth and yawned once or twice, and shook itself.
42-
Then it got down off the mushroom, and crawled away in the grass, merely remarking as it went, “One side will make you grow taller, and the other side will make you grow shorter.”
43-
“One side of what? The other side of what?” thought Alice to herself.
44-
“Of the mushroom,” said the Caterpillar, just as if she had asked it aloud; and in another moment it was out of sight.
45-
Alice remained looking thoughtfully at the mushroom for a minute, trying to make out which were the two sides of it; and as it was perfectly round, she found this a very difficult question.
46-
However, at last she stretched her arms round it as far as they would go, and broke off a bit of the edge with each hand.
47-
“And now which is which?” she said to herself, and nibbled a little of the right-hand bit to try the effect: the next moment she felt a violent blow underneath her chin: it had struck her foot!
48-
She was a good deal frightened by this very sudden change, but she felt that there was no time to be lost, as she was shrinking rapidly; so she set to work at once to eat some of the other bit.
49-
Her chin was pressed so closely against her foot, that there was hardly room to open her mouth; but she did it at last, and managed to swallow a morsel of the lefthand bit.`,
50-
// textTask3.html
51-
`As soon as she had made out the proper way of nursing it, (which was to twist it up into a sort of knot, and then keep tight hold of its right ear and left foot, so as to prevent its undoing itself,) she carried it out into the open air. “If I don’t take this child away with me,” thought Alice, “they’re sure to kill it in a day or two: wouldn’t it be murder to leave it behind?” She said the last words out loud, and the little thing grunted in reply (it had left off sneezing by this time). “Don’t grunt,” said Alice; “that’s not at all a proper way of expressing yourself.”
52-
53-
The baby grunted again, and Alice looked very anxiously into its face to see what was the matter with it. There could be no doubt that it had a very turn-up nose, much more like a snout than a real nose; also its eyes were getting extremely small for a baby: altogether Alice did not like the look of the thing at all. “But perhaps it was only sobbing,” she thought, and looked into its eyes again, to see if there were any tears.
54-
55-
No, there were no tears. “If you’re going to turn into a pig, my dear,” said Alice, seriously, “I’ll have nothing more to do with you. Mind now!” The poor little thing sobbed again (or grunted, it was impossible to say which), and they went on for some while in silence.
56-
57-
Alice was just beginning to think to herself, “Now, what am I to do with this creature when I get it home?” when it grunted again, so violently, that she looked down into its face in some alarm. This time there could be no mistake about it: it was neither more nor less than a pig, and she felt that it would be quite absurd for her to carry it further.
58-
59-
So she set the little creature down, and felt quite relieved to see it trot away quietly into the wood. “If it had grown up,” she said to herself, “it would have made a dreadfully ugly child: but it makes rather a handsome pig, I think.” And she began thinking over other children she knew, who might do very well as pigs, and was just saying to herself, “if one only knew the right way to change them—” when she was a little startled by seeing the Cheshire Cat sitting on a bough of a tree a few yards off.`
37+
And the mome raths outgrabe.`
6038
];
6139

6240
function pickRandomText() {
@@ -65,9 +43,20 @@ function pickRandomText() {
6543

6644
const TextTask = () => {
6745
const [text] = useState(() => pickRandomText());
46+
const [showCross, setShowCross] = useState(true);
6847
const formattedTextRef = useRef(null);
6948

7049
useEffect(() => {
50+
const timer = setTimeout(() => {
51+
setShowCross(false);
52+
}, 10000); // Hide tracking cross after 10 seconds
53+
54+
return () => clearTimeout(timer);
55+
}, []);
56+
57+
useEffect(() => {
58+
if (showCross) return;
59+
7160
let sentenceCount = 1;
7261
let wordCount = 1;
7362
let character_id = 0;
@@ -107,49 +96,87 @@ const TextTask = () => {
10796
sentenceCount++;
10897
}
10998
});
110-
}, [text]);
99+
}, [text, showCross]);
111100

112101
return (
113-
<div className="textTask" style={{
114-
textAlign: 'center',
115-
fontFamily: 'Arial, sans-serif',
116-
height: '100%',
117-
display: 'flex',
118-
flexDirection: 'column',
119-
justifyContent: 'center',
120-
alignItems: 'center'
121-
}}>
122-
<h3 style={{ margin: '2em 25% 0' }}>
123-
Please read the following text carefully:
124-
</h3>
125-
<div
126-
ref={formattedTextRef}
127-
className="formatted-text"
128-
style={{
129-
display: 'flex',
130-
flexWrap: 'wrap',
131-
justifyContent: 'flex-start',
132-
textAlign: 'left',
133-
margin: '40px auto',
134-
maxWidth: '33%',
135-
width: '100%',
136-
lineHeight: 2
137-
}}
138-
/>
102+
<div
103+
className="textTask"
104+
style={{
105+
textAlign: 'center',
106+
fontFamily: 'Arial, sans-serif',
107+
height: '100vh',
108+
width: '100vw',
109+
display: 'flex',
110+
flexDirection: 'column',
111+
justifyContent: 'center',
112+
alignItems: 'center',
113+
position: 'relative',
114+
backgroundColor: '#fff',
115+
}}
116+
>
117+
{showCross ? (
118+
console.log("Fixation cross is rendering...") || (
119+
<div style={styles.crossContainer}>
120+
<div style={styles.cross}>+</div>
121+
</div>
122+
)
123+
) : (
124+
<>
125+
<h3 style={{ margin: '2em 25% 0' }}>
126+
Please read the following text carefully:
127+
</h3>
128+
<div
129+
ref={formattedTextRef}
130+
className="formatted-text"
131+
style={{
132+
display: 'flex',
133+
flexWrap: 'wrap',
134+
justifyContent: 'flex-start',
135+
textAlign: 'left',
136+
margin: '40px auto',
137+
maxWidth: '33%',
138+
width: '100%',
139+
lineHeight: 2,
140+
}}
141+
/>
142+
</>
143+
)}
144+
139145
<style>{`
140146
.word-block {
141147
display: inline-flex;
142148
flex-wrap: nowrap;
143149
}
144150
.letter {
145-
font-size: 1.35em;
151+
font-size: 24px;
146152
}
147153
.space {
148-
width: 0.25vw;
154+
width: 4px;
149155
}
150156
`}</style>
151157
</div>
152158
);
153159
};
154160

155-
export default TextTask;
161+
const styles = {
162+
crossContainer: {
163+
position: 'absolute',
164+
top: 0,
165+
left: 0,
166+
height: '100vh',
167+
width: '100vw',
168+
display: 'flex',
169+
justifyContent: 'center',
170+
alignItems: 'center',
171+
zIndex: 9999,
172+
backgroundColor: '#fff',
173+
border: '3px dashed red', // Temporary debug border — remove later
174+
},
175+
cross: {
176+
fontSize: '100px',
177+
fontWeight: 'bold',
178+
color: 'black',
179+
},
180+
};
181+
182+
export default TextTask;

0 commit comments

Comments
 (0)