Skip to content

Commit 958c933

Browse files
authored
Merge pull request #963 from joshunrau/build-time
2 parents 9c2b951 + 0c563a5 commit 958c933

11 files changed

Lines changed: 137 additions & 9 deletions

File tree

apps/playground/src/components/Editor/setup.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ class TypeScriptSuggestAdapter extends SuggestAdapter implements CompletionItemP
1717
override triggerCharacters = ['.', '"', "'"];
1818
}
1919

20-
const customEnv = `
21-
declare module 'react/jsx-runtime' {
22-
export * from '/runtime/v1/react@18.x/jsx-runtime'
23-
}`;
24-
2520
self.MonacoEnvironment = {
2621
getWorker(_, label) {
2722
if (label === 'typescript' || label === 'javascript') {
@@ -156,6 +151,6 @@ loader.config({ monaco });
156151

157152
const uri = monaco.Uri.parse('globals.d.ts');
158153

159-
monaco.languages.typescript.typescriptDefaults.addExtraLib(envTypes + customEnv, 'globals.d.ts');
154+
monaco.languages.typescript.typescriptDefaults.addExtraLib(envTypes, 'globals.d.ts');
160155
monaco.editor.createModel(envTypes, 'typescript', uri);
161156
}

apps/web/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
}
2222
</script>
2323
</head>
24-
<body class="overflow-hidden bg-slate-100 text-slate-900 dark:bg-slate-900 dark:text-slate-100">
24+
<body class="bg-slate-100 text-slate-900 dark:bg-slate-900 dark:text-slate-100">
2525
<div class="flex min-h-screen flex-col" id="root"></div>
2626
<script type="module" src="/src/main.tsx"></script>
2727
</body>

apps/web/src/features/about/pages/AboutPage.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const translations = {
1414
en: 'Branch',
1515
fr: 'Branche'
1616
},
17+
buildDate: {
18+
en: 'Build Date',
19+
fr: 'Date de construction'
20+
},
1721
buildType: {
1822
en: 'Build Type',
1923
fr: 'Type de construction'
@@ -65,6 +69,9 @@ export const AboutPage = () => {
6569

6670
const translateReleaseInfo = (release: ReleaseInfo) => {
6771
const translatedReleaseInfo = {
72+
[t(translations.buildDate)]: new Date(release.buildTime).toLocaleDateString(resolvedLanguage, {
73+
dateStyle: 'long'
74+
}),
6875
[t(translations.buildType)]: t(translations.buildTypes[release.type]),
6976
[t(translations.version)]: release.version
7077
};

apps/web/src/features/setup/pages/SetupPage/SetupPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export type SetupPageProps = {
2323
export const SetupPage = ({ onSubmit }: SetupPageProps) => {
2424
const { t } = useTranslation();
2525
return (
26-
<div className="flex h-screen flex-col items-center justify-center overflow-y-scroll">
26+
<div className="flex flex-col items-center justify-center">
2727
<Card className="w-full grow px-4 sm:m-8 sm:max-w-xl sm:grow-0 md:max-w-2xl">
2828
<Card.Header className="flex items-center justify-center">
2929
<Logo className="m-2 h-auto w-16" variant="auto" />
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { useEffect, useState } from '/runtime/v1/react@18.x';
2+
3+
const colors = ['red', 'blue', 'green', 'yellow'];
4+
const words = ['RED', 'BLUE', 'GREEN', 'YELLOW'];
5+
6+
function getRandomElement<T>(arr: T[]): T {
7+
return arr[Math.floor(Math.random() * arr.length)]!;
8+
}
9+
10+
type StroopTaskProps = {
11+
done: (data: { score: number }) => void;
12+
};
13+
14+
export const StroopTask: React.FC<StroopTaskProps> = () => {
15+
const [currentWord, setCurrentWord] = useState('');
16+
const [currentColor, setCurrentColor] = useState('');
17+
const [score, setScore] = useState(0);
18+
const [timeLeft, setTimeLeft] = useState(60); // 60 seconds for the task
19+
20+
useEffect(() => {
21+
const interval = setInterval(() => {
22+
setTimeLeft((prevTime) => (prevTime > 0 ? prevTime - 1 : 0));
23+
}, 1000);
24+
return () => clearInterval(interval);
25+
}, []);
26+
27+
useEffect(() => {
28+
if (timeLeft > 0) {
29+
generateNewTask();
30+
}
31+
}, [timeLeft]);
32+
33+
const generateNewTask = () => {
34+
const word = getRandomElement(words);
35+
const color = getRandomElement(colors);
36+
setCurrentWord(word);
37+
setCurrentColor(color);
38+
};
39+
40+
const handleColorClick = (color: string) => {
41+
if (color === currentColor) {
42+
setScore(score + 1);
43+
}
44+
generateNewTask();
45+
};
46+
47+
return (
48+
<div>
49+
<h1>Stroop Task</h1>
50+
<div>
51+
<h2>Time Left: {timeLeft} seconds</h2>
52+
<h2>Score: {score}</h2>
53+
</div>
54+
{timeLeft > 0 ? (
55+
<div>
56+
<h2 style={{ color: currentColor }}>{currentWord}</h2>
57+
<div>
58+
{colors.map((color) => (
59+
<button
60+
key={color}
61+
style={{ backgroundColor: color, color: 'white', margin: '5px', padding: '10px' }}
62+
onClick={() => handleColorClick(color)}
63+
>
64+
{color.toUpperCase()}
65+
</button>
66+
))}
67+
</div>
68+
</div>
69+
) : (
70+
<h2>Time is up! Your final score is {score}</h2>
71+
)}
72+
</div>
73+
);
74+
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { defineInstrument } from '/runtime/v1/@opendatacapture/runtime-core';
2+
import { createRoot } from '/runtime/v1/react-dom@18.x/client.js';
3+
import { z } from '/runtime/v1/zod@3.23.x';
4+
5+
import { StroopTask } from './StroopTask.tsx';
6+
7+
import './styles.css';
8+
9+
export default defineInstrument({
10+
content: {
11+
render(done) {
12+
const rootElement = document.createElement('div');
13+
document.body.appendChild(rootElement);
14+
const root = createRoot(rootElement);
15+
root.render(<StroopTask done={(data) => done(data)} />);
16+
}
17+
},
18+
details: {
19+
description: 'The Stroop Task is a psychological test designed to measure cognitive flexibility and attention.',
20+
estimatedDuration: 1,
21+
instructions: ['Please follow the instructions on the screen.'],
22+
license: 'Apache-2.0',
23+
title: 'Stroop Task'
24+
},
25+
internal: {
26+
edition: 1,
27+
name: 'INTERACTIVE_INSTRUMENT'
28+
},
29+
kind: 'INTERACTIVE',
30+
language: 'en',
31+
measures: {
32+
score: {
33+
kind: 'const',
34+
label: 'Score',
35+
ref: 'score'
36+
}
37+
},
38+
tags: ['Interactive'],
39+
validationSchema: z.object({
40+
score: z.number().int()
41+
})
42+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
background-color: white;
3+
}

packages/release-info/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export async function getReleaseInfo(): Promise<ReleaseInfo> {
3333
if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
3434
return $DevelopmentReleaseInfo.parseAsync({
3535
branch: await getGitBranch(),
36+
buildTime: Date.now(),
3637
commit: await getGitCommit(),
3738
type: process.env.NODE_ENV,
3839
version: await fs
@@ -42,6 +43,7 @@ export async function getReleaseInfo(): Promise<ReleaseInfo> {
4243
} satisfies DevelopmentReleaseInfo);
4344
} else if (process.env.NODE_ENV === 'production') {
4445
return $ProductionReleaseInfo.parseAsync({
46+
buildTime: Date.now(),
4547
type: 'production',
4648
version: process.env.RELEASE_VERSION!
4749
} satisfies ProductionReleaseInfo);

packages/schemas/src/setup/setup.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ export const $ReleaseVersion = z.string().regex(/[0-9]+.[0-9]+.[0-9]+/);
77
export type DevelopmentReleaseInfo = z.infer<typeof $DevelopmentReleaseInfo>;
88
export const $DevelopmentReleaseInfo = z.object({
99
branch: z.string().min(1),
10+
buildTime: z.number(),
1011
commit: z.string().length(8),
1112
type: z.enum(['development', 'test']),
1213
version: $ReleaseVersion
1314
});
1415

1516
export type ProductionReleaseInfo = z.infer<typeof $ProductionReleaseInfo>;
1617
export const $ProductionReleaseInfo = z.object({
18+
buildTime: z.number(),
1719
type: z.literal('production'),
1820
version: $ReleaseVersion
1921
});

runtime/v1/env.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ declare module '*.webp' {
2727
const src: string;
2828
export default src;
2929
}
30+
31+
declare module 'react/jsx-runtime' {
32+
export * from '/runtime/v1/react@18.x/jsx-runtime';
33+
}

0 commit comments

Comments
 (0)