Skip to content

Commit 61759c2

Browse files
authored
Merge pull request #1076 from joshunrau/json
add json support for instruments and only persist user-defined instruments in playground
2 parents 1113178 + 1cd38e2 commit 61759c2

File tree

12 files changed

+43
-6
lines changed

12 files changed

+43
-6
lines changed

apps/playground/src/components/Editor/Editor.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export const Editor = () => {
145145
/>
146146
<FileUploadDialog
147147
accept={{
148+
'application/json': ['.json'],
148149
'image/jpeg': ['.jpg', '.jpeg'],
149150
'image/png': ['.png'],
150151
'image/webp': ['.webp'],

apps/playground/src/components/Editor/EditorFileIcon.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ export const EditorFileIcon = ({ filename }: EditorFileIconProps) => {
108108
/>
109109
</svg>
110110
))
111+
.with('.json', () => (
112+
<svg viewBox="0 -960 960 960" xmlns="http://www.w3.org/2000/svg">
113+
<path
114+
d="M560-160v-80h120q17 0 28.5-11.5T720-280v-80q0-38 22-69t58-44v-14q-36-13-58-44t-22-69v-80q0-17-11.5-28.5T680-720H560v-80h120q50 0 85 35t35 85v80q0 17 11.5 28.5T840-560h40v160h-40q-17 0-28.5 11.5T800-360v80q0 50-35 85t-85 35zm-280 0q-50 0-85-35t-35-85v-80q0-17-11.5-28.5T120-400H80v-160h40q17 0 28.5-11.5T160-600v-80q0-50 35-85t85-35h120v80H280q-17 0-28.5 11.5T240-680v80q0 38-22 69t-58 44v14q36 13 58 44t22 69v80q0 17 11.5 28.5T280-240h120v80z"
115+
fill="#f9a825"
116+
/>
117+
</svg>
118+
))
111119
.otherwise(() => (
112120
<FileIcon />
113121
))}

apps/playground/src/components/Editor/EditorPane.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export const EditorPane = React.forwardRef<EditorPaneRef, EditorPaneProps>(funct
136136
return (
137137
<MonacoEditor
138138
className="h-full min-h-[576px]"
139-
defaultLanguage={fileType satisfies 'css' | 'html' | 'javascript' | 'typescript'}
139+
defaultLanguage={fileType satisfies 'css' | 'html' | 'javascript' | 'json' | 'typescript'}
140140
defaultValue={defaultFile.content}
141141
keepCurrentModel={true}
142142
key={defaultFile.id}

apps/playground/src/instruments/examples/interactive/Interactive-With-Video/cat-video.mp4 renamed to apps/playground/src/instruments/examples/interactive/Interactive-With-Embedded-Video/cat-video.mp4

File renamed without changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"timeLimit": 15
3+
}

apps/playground/src/instruments/examples/interactive/Interactive-With-Video/index.tsx renamed to apps/playground/src/instruments/examples/interactive/Interactive-With-Embedded-Video/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { createRoot } from '/runtime/v1/[email protected]/client.js';
44
import { z } from '/runtime/v1/[email protected]';
55

66
import catVideo from './cat-video.mp4';
7+
import config from './config.json';
78

89
const Task: React.FC<{ done: (data: { success: boolean }) => void }> = ({ done }) => {
9-
const [secondsRemaining, setSecondsRemaining] = useState(15);
10+
const [secondsRemaining, setSecondsRemaining] = useState<number>(config.timeLimit);
1011
const [value, setValue] = useState('');
1112

1213
useEffect(() => {
@@ -71,7 +72,7 @@ export default defineInstrument({
7172
authors: ['Joshua Unrau'],
7273
description: 'This test assesses whether a person knows what a cat is',
7374
license: 'Apache-2.0',
74-
title: 'Breakout Task'
75+
title: 'Interactive With Embedded Video'
7576
},
7677
internal: {
7778
edition: 1,

apps/playground/src/instruments/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { loadAssetAsBase64 } from '@/utils/load';
77
// Instruments in development
88
const EXCLUDED_LABELS: string[] = [];
99

10-
const textFiles: { [key: string]: string } = import.meta.glob('./**/*.{css,js,jsx,ts,tsx,svg}', {
10+
const textFiles: { [key: string]: string } = import.meta.glob('./**/*.{css,js,jsx,json,ts,tsx,svg}', {
1111
eager: true,
1212
import: 'default',
1313
query: '?raw'

apps/playground/src/store/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ export const useAppStore = create(
2727
}))
2828
),
2929
{
30+
merge: (_persistedState, currentState) => {
31+
const persistedState = _persistedState as
32+
| Partial<Pick<AppStore, 'instruments' | 'selectedInstrument' | 'settings'>>
33+
| undefined;
34+
const instruments = [
35+
...currentState.instruments,
36+
...(persistedState?.instruments ?? []).filter((instrument) => {
37+
return instrument.category === 'Saved';
38+
})
39+
];
40+
const selectedInstrument =
41+
instruments.find(({ id }) => id === persistedState?.selectedInstrument?.id) ??
42+
currentState.selectedInstrument;
43+
const settings = persistedState?.settings ?? currentState.settings;
44+
return { ...currentState, instruments, selectedInstrument, settings };
45+
},
3046
name: 'app',
3147
partialize: (state) => pick(state, ['instruments', 'selectedInstrument', 'settings']),
3248
storage: createJSONStorage(() => localStorage),

apps/playground/src/utils/file.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { match, P } from 'ts-pattern';
44

55
import type { EditorFile } from '@/models/editor-file.model';
66

7-
export type FileType = 'asset' | 'css' | 'html' | 'javascript' | 'typescript';
7+
export type FileType = 'asset' | 'css' | 'html' | 'javascript' | 'json' | 'typescript';
88

99
export function inferFileType(filename: string): FileType | null {
1010
return match(extractInputFileExtension(filename))
@@ -13,6 +13,7 @@ export function inferFileType(filename: string): FileType | null {
1313
.with(P.union('.ts', '.tsx'), () => 'typescript' as const)
1414
.with(P.union('.jpeg', '.jpg', '.png', '.webp', '.mp4'), () => 'asset' as const)
1515
.with(P.union('.html', '.svg'), () => 'html' as const)
16+
.with('.json', () => 'json' as const)
1617
.with(null, () => null)
1718
.exhaustive();
1819
}

packages/instrument-bundler/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export type BundlerInputFileExtension =
44
| '.jpeg'
55
| '.jpg'
66
| '.js'
7+
| '.json'
78
| '.jsx'
89
| '.mp4'
910
| '.png'

0 commit comments

Comments
 (0)