Skip to content

Commit

Permalink
fix: attempt to make warning work on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
juancarlosfarah committed Apr 12, 2024
1 parent 3435ddf commit 7333e99
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/modules/interaction/ParticipantInteraction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,21 @@ const ParticipantInteraction = (): ReactElement => {
useState<Interaction>(defaultInteraction);

useEffect(() => {
const handleBeforeUnload = (event: BeforeUnloadEvent): void => {
const handleBeforeUnload = (event: BeforeUnloadEvent): string => {
if (!interaction.completed) {
// Perform actions before the component unloads
event.preventDefault();

// eslint-disable-next-line no-alert,no-restricted-globals
confirm('Confirm refresh');
// Chrome requires returnValue to be set
// Prompt the user before leaving
const confirmationMessage = 'Are you sure you want to leave?';

// Chrome requires returnValue to be set
// eslint-disable-next-line no-param-reassign
event.returnValue = confirmationMessage; // For Chrome
return confirmationMessage; // For standard browsers
}
return '';
};
window.addEventListener('beforeunload', handleBeforeUnload);
return () => {
Expand Down

0 comments on commit 7333e99

Please sign in to comment.