From 7a5faac08d23497f57c52c4b8d504943a0d45be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Wed, 4 Sep 2024 09:10:18 +0300 Subject: [PATCH] feat(runtime): reactive source for editor files --- packages/react/src/Panels/WorkspacePanel.tsx | 3 ++- packages/runtime/src/store/editor.ts | 1 + packages/runtime/src/store/index.ts | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/react/src/Panels/WorkspacePanel.tsx b/packages/react/src/Panels/WorkspacePanel.tsx index 3badbba4..6da12062 100644 --- a/packages/react/src/Panels/WorkspacePanel.tsx +++ b/packages/react/src/Panels/WorkspacePanel.tsx @@ -89,6 +89,7 @@ function EditorSection({ theme, tutorialStore, hasEditor }: PanelProps) { const selectedFile = useStore(tutorialStore.selectedFile); const currentDocument = useStore(tutorialStore.currentDocument); const lessonFullyLoaded = useStore(tutorialStore.lessonFullyLoaded); + const files = useStore(tutorialStore.files); const lesson = tutorialStore.lesson!; @@ -132,7 +133,7 @@ function EditorSection({ theme, tutorialStore, hasEditor }: PanelProps) { theme={theme} showFileTree={tutorialStore.hasFileTree()} editorDocument={currentDocument} - files={lesson.files[1]} + files={files} i18n={lesson.data.i18n as I18n} hideRoot={lesson.data.hideRoot} helpAction={helpAction} diff --git a/packages/runtime/src/store/editor.ts b/packages/runtime/src/store/editor.ts index d613909b..f5e92f64 100644 --- a/packages/runtime/src/store/editor.ts +++ b/packages/runtime/src/store/editor.ts @@ -19,6 +19,7 @@ export class EditorStore { selectedFile = atom(); documents = map({}); + files = computed(this.documents, (documents) => Object.keys(documents).sort()); currentDocument = computed([this.documents, this.selectedFile], (documents, selectedFile) => { if (!selectedFile) { return undefined; diff --git a/packages/runtime/src/store/index.ts b/packages/runtime/src/store/index.ts index cdb6f357..64e365fa 100644 --- a/packages/runtime/src/store/index.ts +++ b/packages/runtime/src/store/index.ts @@ -207,6 +207,10 @@ export class TutorialStore { return this._editorStore.documents; } + get files(): ReadableAtom { + return this._editorStore.files; + } + get template(): Files | undefined { return this._lessonTemplate; }