Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#379): confirm exit from playground #515

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/playground/public/assets/js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@ function registerAskScriptEditor(
askScriptServerUrl: string
) {
const editor = ace.edit(editorElementId);
let dirty = false;
editor.setTheme('ace/theme/twilight');
editor.session.setMode('ace/mode/javascript');
editor.session.setOption('useWorker', false);
editor.session.on('change', () => {
if (dirty) return;
playgroundIsDirty(!dirty);
dirty = true;
km4 marked this conversation as resolved.
Show resolved Hide resolved
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that now when we have isDirty check, we can just attach onbeforeunload once for all without the need for the extra playgroundIsDirty function.

Suggested change
});
});
window.onbeforeunload = function (e: any) {
if (isDirty) {
e.preventDefault();
e.returnValue = '';
}
};


editor.commands.addCommand({
name: 'alertalert',
Expand Down Expand Up @@ -81,6 +87,7 @@ async function executeAskScript(
const json = await response.json();
if (response.status == 200) {
showSuccessfulResponse(json.result);
playgroundIsDirty(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
playgroundIsDirty(false);
isDirty = false;

Copy link
Contributor Author

@km4 km4 Nov 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mhagmajer
what about this isDirty flag? Now is undefined variable for this scope. If I push dirty params to all functions eg.

async function executeAskScript(
  askScriptCode: string,
  askScriptServerUrl: string,
  isDirty: boolean
) {

executeAskScriptFromEditor(editor, askScriptServerUrl, isDirty); the flag dosnt update in the top.

} else {
showErrorResponse(json.error);
}
Expand All @@ -107,3 +114,12 @@ function removeFadeInClass() {
const resultElem = document.getElementById('result')!;
resultElem.classList.remove('fadeIn');
}

function playgroundIsDirty(isDirty: boolean): void {
window.onbeforeunload = function (e: any) {
if (isDirty) {
e.preventDefault();
e.returnValue = '';
}
};
}