Skip to content

Commit

Permalink
WIP: save program afte rrunning it with correct name of program of ad…
Browse files Browse the repository at this point in the history
…venture
  • Loading branch information
hasan-sh committed May 8, 2024
1 parent 358da64 commit dd4cd47
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
12 changes: 8 additions & 4 deletions static/js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ export function initializeCodePage(options: InitializeCodePageOptions) {
keywordLanguage: theKeywordLanguage,
});
}

initializeHighlightedCodeBlocks(document.body);

const anchor = window.location.hash.substring(1);

Expand All @@ -240,7 +242,7 @@ export function initializeCodePage(options: InitializeCodePageOptions) {
});

tabs.on('afterSwitch', (ev) => {
currentTab = ev.newTab;
currentTab = decodeURIComponent(ev.newTab);
const adventure = theAdventures[currentTab];

if (!options.suppress_save_and_load_for_slides) {
Expand Down Expand Up @@ -423,7 +425,7 @@ export function initializeHighlightedCodeBlocks(where: Element) {
clearOutput();
});
}
const levelStr = $(preview).attr('level');
const levelStr = $(preview).attr('level') || theLevel.toString();
const lang = $(preview).attr('lang');
if (levelStr && lang) {
initializeTranslation({
Expand Down Expand Up @@ -570,7 +572,7 @@ export async function runit(level: number, lang: string, raw: boolean, disabled_

// Save under an existing id if this field is set
program_id: isServerSaveInfo(adventure?.save_info) ? adventure.save_info.id : undefined,
save_name: saveNameFromInput(),
save_name: saveNameFromInput() || currentTab,
};

let response = await postJsonWithAchievements('/parse', data);
Expand All @@ -587,6 +589,7 @@ export async function runit(level: number, lang: string, raw: boolean, disabled_
if (adventure && response.save_info) {
adventure.save_info = response.save_info;
adventure.editor_contents = code;
await saveIfNecessary();
}

if (response.Error) {
Expand Down Expand Up @@ -2023,7 +2026,8 @@ function programNeedsSaving(adventureName: string) {
// save a program that was loaded from local storage to the server.
// (Submitted programs are never saved again).
const programChanged = theGlobalEditor.contents !== adventure.editor_contents;
const nameChanged = $('#program_name').val() !== adventure.save_name;
const programName = $('#program_name').val() || currentTab;
const nameChanged = programName !== adventure.save_name;
const localStorageCanBeSavedToServer = theUserIsLoggedIn && adventure.save_info === 'local-storage';
const isUnchangeable = isServerSaveInfo(adventure.save_info) ? adventure.save_info.submitted : false;

Expand Down
11 changes: 7 additions & 4 deletions static/js/appbundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -104624,6 +104624,7 @@ def note_with_error(value, err):
keywordLanguage: theKeywordLanguage
});
}
initializeHighlightedCodeBlocks(document.body);
const anchor = window.location.hash.substring(1);
const validAnchor = [...Object.keys(theAdventures), "parsons", "quiz"].includes(anchor) ? anchor : void 0;
const tabs = new Tabs({
Expand All @@ -104633,7 +104634,7 @@ def note_with_error(value, err):
saveIfNecessary();
});
tabs.on("afterSwitch", (ev) => {
currentTab = ev.newTab;
currentTab = decodeURIComponent(ev.newTab);
const adventure = theAdventures[currentTab];
if (!options.suppress_save_and_load_for_slides) {
const programFromLs = localLoad(currentTabLsKey());
Expand Down Expand Up @@ -104769,7 +104770,7 @@ def note_with_error(value, err):
clearOutput();
});
}
const levelStr = $(preview).attr("level");
const levelStr = $(preview).attr("level") || theLevel.toString();
const lang = $(preview).attr("lang");
if (levelStr && lang) {
initializeTranslation({
Expand Down Expand Up @@ -104885,7 +104886,7 @@ def note_with_error(value, err):
short_name: adventure ? adventure.short_name : void 0,
raw,
program_id: isServerSaveInfo(adventure == null ? void 0 : adventure.save_info) ? adventure.save_info.id : void 0,
save_name: saveNameFromInput()
save_name: saveNameFromInput() || currentTab
};
let response = await postJsonWithAchievements("/parse", data);
program_data = response;
Expand All @@ -104897,6 +104898,7 @@ def note_with_error(value, err):
if (adventure && response.save_info) {
adventure.save_info = response.save_info;
adventure.editor_contents = code;
await saveIfNecessary();
}
if (response.Error) {
error.show(ClientMessages["Transpile_error"], response.Error);
Expand Down Expand Up @@ -106001,7 +106003,8 @@ def note_with_error(value, err):
return false;
}
const programChanged = theGlobalEditor.contents !== adventure.editor_contents;
const nameChanged = $("#program_name").val() !== adventure.save_name;
const programName = $("#program_name").val() || currentTab;
const nameChanged = programName !== adventure.save_name;
const localStorageCanBeSavedToServer = theUserIsLoggedIn && adventure.save_info === "local-storage";
const isUnchangeable = isServerSaveInfo(adventure.save_info) ? adventure.save_info.submitted : false;
const wasSavedBefore = adventure.save_info !== void 0;
Expand Down
4 changes: 2 additions & 2 deletions static/js/appbundle.js.map

Large diffs are not rendered by default.

0 comments on commit dd4cd47

Please sign in to comment.