Skip to content

Commit

Permalink
Widget: asking user for permission to reload the page
Browse files Browse the repository at this point in the history
  • Loading branch information
gusthoff committed Sep 8, 2024
1 parent 9b22f64 commit cd77a0c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
5 changes: 5 additions & 0 deletions frontend/src/ts/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ export const RESET_CONFIRM_MSG =
'Your changes will be lost after reset. ' +
'Are you sure you want to reset the editor and the compiler options?';

export const RELOAD_CONFIRM_MSG =
'Changing this setting requires reloading the page: ' +
'your changes will be lost. ' +
'Are you sure you want to proceed?';

export const DOWNLOAD_TOOLTIP = 'Download source files';
export const DOWNLOAD_MAINTENANCE =
'The download functionilty is currently undergoing maintenance';
Expand Down
50 changes: 32 additions & 18 deletions frontend/src/ts/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,23 @@ class Widget {
this.setTabbedView(tabbedView);

tabSetting.addEventListener('change', () => {
let tabbedView = 'true';
if (!tabSetting.checked) {
tabbedView = 'false';
}
cookies.set('tabbed_view', tabbedView, {expires: 3650});
this.setTabbedView(tabSetting.checked);
if (window.confirm(Strings.RELOAD_CONFIRM_MSG)) {
let tabbedView = 'true';
if (!tabSetting.checked) {
tabbedView = 'false';
}
cookies.set('tabbed_view', tabbedView, {expires: 3650});
this.setTabbedView(tabSetting.checked);

// Current approach: just reload the page to
// set the correct theme for all widgets.
location.reload();
// Current approach: just reload the page to
// set the correct theme for all widgets.
location.reload();
}
else
{
// Revert if user chooses "no change"
tabSetting.checked = !tabSetting.checked;
}
});

this.initCompilerSwitches();
Expand All @@ -175,16 +182,23 @@ class Widget {
this.setTheme(cookieTheme);

themeSetting.addEventListener('change', () => {
let theme = 'light';
if (themeSetting.checked) {
theme = 'dark';
}
cookies.set('theme', theme, {expires: 3650});
this.setTheme(theme);
if (window.confirm(Strings.RELOAD_CONFIRM_MSG)) {
let theme = 'light';
if (themeSetting.checked) {
theme = 'dark';
}
cookies.set('theme', theme, {expires: 3650});
this.setTheme(theme);

// Current approach: just reload the page to
// set the correct theme for all widgets.
location.reload();
// Current approach: just reload the page to
// set the correct theme for all widgets.
location.reload();
}
else
{
// Revert if user chooses "no change"
themeSetting.checked = !themeSetting.checked;
}
});

const resetButton =
Expand Down

0 comments on commit cd77a0c

Please sign in to comment.