Skip to content

Commit 634958a

Browse files
committed
Implemented message passing for chapter-selection
1 parent dbf4660 commit 634958a

File tree

4 files changed

+38
-13
lines changed

4 files changed

+38
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"properties": {
3636
"source-academy.frontendBaseUrl": {
3737
"type": "string",
38-
"default": "https://frontend.cloud.heyzec.dedyn.io",
38+
"default": "http://localhost:8000",
3939
"description": "URL to the Source Academy frontend"
4040
}
4141
}

src/commands/showPanel.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ async function handleMessage(
8585
sendToFrontend(panel, message);
8686
});
8787
break;
88+
case MessageTypeNames.ChangeChapter: {
89+
const info = context.globalState.get("info") ?? {};
90+
const uri = vscode.Uri.file(Editor.getFilePath(message.assessmentName, message.questionId)).toString();
91+
92+
_.set(info, `["${uri}"].chapter`, message.chapter ?? 1);
93+
context.globalState.update("info", info);
94+
client.sendRequest("source/publishInfo", info);
95+
break;
96+
}
8897
// case MessageTypeNames.Text:
8998
// if (!activeEditor) {
9099
// console.log("ERROR: activeEditor is not set");

src/utils/editor.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,7 @@ export class Editor {
3737
return this.editor?.document.getText();
3838
}
3939

40-
// TODO: This method is too loaded, it's not obvious it also shows the editor
41-
static async create(
42-
workspaceLocation: VscWorkspaceLocation,
43-
assessmentName: string,
44-
questionId: number,
45-
prepend: string = "",
46-
initialCode: string = "",
47-
): Promise<Editor> {
48-
const self = new Editor(workspaceLocation, assessmentName, questionId);
49-
self.assessmentName = assessmentName;
50-
self.questionId = questionId;
51-
40+
static getFilePath(assessmentName: string, questionId: number): string {
5241
let workspaceFolder = config.workspaceFolder;
5342
if (!workspaceFolder) {
5443
workspaceFolder = path.join(os.homedir(), ".sourceacademy");
@@ -62,6 +51,22 @@ export class Editor {
6251
`${assessmentName}_${questionId}.js`,
6352
);
6453

54+
return filePath
55+
}
56+
57+
// TODO: This method is too loaded, it's not obvious it also shows the editor
58+
static async create(
59+
workspaceLocation: VscWorkspaceLocation,
60+
assessmentName: string,
61+
questionId: number,
62+
prepend: string = "",
63+
initialCode: string = "",
64+
): Promise<Editor> {
65+
const self = new Editor(workspaceLocation, assessmentName, questionId);
66+
self.assessmentName = assessmentName;
67+
self.questionId = questionId;
68+
69+
const filePath = this.getFilePath(assessmentName, questionId);
6570
const uri = vscode.Uri.file(filePath);
6671
self.uri = uri.toString();
6772

src/utils/messages.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ const Messages = createMessages({
4040
EvalEditor: (workspaceLocation: VscWorkspaceLocation) => ({
4141
workspaceLocation: workspaceLocation,
4242
}),
43+
ChangeChapter: (
44+
assessmentName: string,
45+
questionId: number,
46+
chapter: number,
47+
variant: string
48+
) => ({
49+
assessmentName,
50+
questionId,
51+
chapter,
52+
variant
53+
})
4354
});
4455

4556
export default Messages;

0 commit comments

Comments
 (0)