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

Prevent closing the tab when there are unsaved changes #253

Merged
merged 1 commit into from
Sep 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions timetagger/app/stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,14 @@ def __init__(self):
window.document.addEventListener(
"visibilitychange", lambda: self.sync_soon(1.0), False
)
window.addEventListener("beforeunload", self._beforeunload, False)

def _beforeunload(self, ev):
if self.state == "pending":
msg = "The most recent changes have not yet been stored."
ev.returnValue = msg
return msg
return None

def reset(self):
# The sub stores
Expand Down