Skip to content

Commit

Permalink
feat(runtime): reactive source for editor files
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Sep 4, 2024
1 parent 2e259fa commit 81eac67
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/react/src/Panels/WorkspacePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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!;

Expand Down Expand Up @@ -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}
Expand Down
1 change: 1 addition & 0 deletions packages/runtime/src/store/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class EditorStore {
selectedFile = atom<string | undefined>();
documents = map<EditorDocuments>({});

files = computed(this.documents, (documents) => Object.keys(documents));
currentDocument = computed([this.documents, this.selectedFile], (documents, selectedFile) => {
if (!selectedFile) {
return undefined;
Expand Down
4 changes: 4 additions & 0 deletions packages/runtime/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ export class TutorialStore {
return this._editorStore.documents;
}

get files(): ReadableAtom<string[]> {
return this._editorStore.files;
}

get template(): Files | undefined {
return this._lessonTemplate;
}
Expand Down

0 comments on commit 81eac67

Please sign in to comment.