Skip to content

Commit 5f78c5f

Browse files
committed
docs: add example with video
1 parent 6a4b708 commit 5f78c5f

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed
Binary file not shown.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { defineInstrument } from '/runtime/v1/@opendatacapture/runtime-core';
2+
import { useEffect, useState } from '/runtime/v1/[email protected]';
3+
import { createRoot } from '/runtime/v1/[email protected]/client.js';
4+
import { z } from '/runtime/v1/[email protected]';
5+
6+
import catVideo from './cat-video.mp4';
7+
8+
const Task: React.FC<{ done: (data: { success: boolean }) => void }> = ({ done }) => {
9+
const [secondsRemaining, setSecondsRemaining] = useState(5);
10+
const [value, setValue] = useState('');
11+
12+
useEffect(() => {
13+
const interval = setInterval(() => {
14+
setSecondsRemaining((value) => value && value - 1);
15+
}, 1000);
16+
return () => clearInterval(interval);
17+
}, []);
18+
19+
useEffect(() => {
20+
if (!secondsRemaining) {
21+
done({ success: false });
22+
}
23+
}, [done, secondsRemaining]);
24+
25+
useEffect(() => {
26+
if (value.toLowerCase() === 'cat') {
27+
done({ success: true });
28+
}
29+
}, [value]);
30+
31+
return (
32+
<div
33+
style={{
34+
alignItems: 'center',
35+
display: 'flex',
36+
flexDirection: 'column',
37+
gap: '20px',
38+
justifyContent: 'center',
39+
minHeight: '80vh'
40+
}}
41+
>
42+
<h3>Which animal is in the video?</h3>
43+
<div>
44+
<label htmlFor="response">Response: </label>
45+
<input id="response" name="response" value={value} onChange={(event) => setValue(event.target.value)} />
46+
</div>
47+
<div>
48+
<span>Time Remaining: {secondsRemaining}</span>
49+
</div>
50+
<video controls muted>
51+
<source src={catVideo} type="video/mp4" />
52+
</video>
53+
</div>
54+
);
55+
};
56+
57+
export default defineInstrument({
58+
clientDetails: {
59+
estimatedDuration: 1,
60+
instructions: ['Please watch the video and then answer the question.']
61+
},
62+
content: {
63+
render(done) {
64+
const rootElement = document.createElement('div');
65+
document.body.appendChild(rootElement);
66+
const root = createRoot(rootElement);
67+
root.render(<Task done={done} />);
68+
}
69+
},
70+
details: {
71+
authors: ['Joshua Unrau'],
72+
description: 'This test assesses whether a person knows what a cat is',
73+
license: 'Apache-2.0',
74+
title: 'Breakout Task'
75+
},
76+
internal: {
77+
edition: 1,
78+
name: 'CAT_VIDEO_TASK'
79+
},
80+
kind: 'INTERACTIVE',
81+
language: 'en',
82+
measures: {
83+
success: {
84+
kind: 'const',
85+
ref: 'success'
86+
}
87+
},
88+
tags: ['Interactive', 'React'],
89+
validationSchema: z.object({
90+
success: z.boolean()
91+
})
92+
});

0 commit comments

Comments
 (0)