Skip to content

Commit

Permalink
Disable autosave on the code page when viewing a program #6043
Browse files Browse the repository at this point in the history
  • Loading branch information
boryanagoncharenko committed Jan 30, 2025
1 parent 66011f0 commit 343e17c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
8 changes: 7 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1452,12 +1452,14 @@ def index(level, program_id):
return utils.error_page(error=404, ui_message=gettext('no_such_level'))

loaded_program = None
suppress_save_and_load = False
if program_id:
result = g_db().program_by_id(program_id)
if not result or not get_current_user_program_permissions(result):
return utils.error_page(error=404, ui_message=gettext('no_such_program'))

loaded_program = Program.from_database_row(result)
suppress_save_and_load = True

# Initially all levels are available -> strip those for which conditions
# are not met or not available yet
Expand Down Expand Up @@ -1668,6 +1670,7 @@ def index(level, program_id):
adventures=adventures,
initial_tab=initial_tab,
current_user_name=current_user()['username'],
suppress_save_and_load=suppress_save_and_load,
))


Expand All @@ -1683,12 +1686,14 @@ def tryit(level, program_id):
return utils.error_page(error=404, ui_message=gettext('no_such_level'))

loaded_program = None
suppress_save_and_load = False
if program_id:
result = g_db().program_by_id(program_id)
if not result or not get_current_user_program_permissions(result):
return utils.error_page(error=404, ui_message=gettext('no_such_program'))

loaded_program = Program.from_database_row(result)
suppress_save_and_load = True

# Initially all levels are available -> strip those for which conditions
# are not met or not available yet
Expand Down Expand Up @@ -1899,6 +1904,7 @@ def tryit(level, program_id):
adventures=adventures,
initial_tab=initial_tab,
current_user_name=current_user()['username'],
suppress_save_and_load=suppress_save_and_load,
))


Expand Down Expand Up @@ -2069,7 +2075,7 @@ def render_code_in_editor(level):
adventures=adventures,
initial_tab='start',
current_user_name=current_user()['username'],
suppress_save_and_load_for_slides=True,
suppress_save_and_load=True,
))


Expand Down
6 changes: 3 additions & 3 deletions static/js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export interface InitializeCodePageOptions {
readonly start_tutorial?: boolean;
readonly initial_tab: string;
readonly current_user_name?: string;
readonly suppress_save_and_load_for_slides?: boolean;
readonly suppress_save_and_load?: boolean;
readonly enforce_developers_mode?: boolean;
}

Expand Down Expand Up @@ -255,7 +255,7 @@ export function initializeCodePage(options: InitializeCodePageOptions) {
currentTab = ev.newTab;
const adventure = theAdventures[currentTab];

if (!options.suppress_save_and_load_for_slides) {
if (!options.suppress_save_and_load) {
// Load initial code from local storage, if available
const programFromLs = localLoad(currentTabLsKey());
// if we are in raw (used in slides) we don't want to load from local storage, we always want to show startcode
Expand All @@ -282,7 +282,7 @@ export function initializeCodePage(options: InitializeCodePageOptions) {
initializeShareProgramButtons();
initializeHandInButton();

if (options.suppress_save_and_load_for_slides) {
if (options.suppress_save_and_load) {
disableAutomaticSaving();
}

Expand Down
4 changes: 2 additions & 2 deletions static/js/appbundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -121187,7 +121187,7 @@ def note_with_error(value, err):
tabs.on("afterSwitch", (ev) => {
currentTab = ev.newTab;
const adventure = theAdventures[currentTab];
if (!options.suppress_save_and_load_for_slides) {
if (!options.suppress_save_and_load) {
const programFromLs = localLoad(currentTabLsKey());
if (programFromLs && adventure) {
adventure.editor_contents = programFromLs.code;
Expand All @@ -121207,7 +121207,7 @@ def note_with_error(value, err):
$("#hand_in_button").on("click", () => $("#hand_in_modal").show());
initializeShareProgramButtons();
initializeHandInButton();
if (options.suppress_save_and_load_for_slides) {
if (options.suppress_save_and_load) {
disableAutomaticSaving();
}
window.addEventListener("beforeunload", () => saveIfNecessary(), { capture: true });
Expand Down
4 changes: 2 additions & 2 deletions static/js/appbundle.js.map

Large diffs are not rendered by default.

0 comments on commit 343e17c

Please sign in to comment.