Skip to content

Conversation

afsar-hussai
Copy link

@afsar-hussai afsar-hussai commented Feb 15, 2025

πŸš€ Feature: Warn Users Before Closing/Reloading Tab

Fixes Issue

**My PR closes #452 **

πŸ‘¨β€πŸ’» Changes proposed(What did you do ?)

  • Created a custom React hook (useBeforeUnload) that listens to the beforeunload event.
  • Displays a warning dialog when a user attempts to close or reload the browser tab.
  • Used this hook in App.jsx to ensure it applies globally across the entire app.

βœ”οΈ Check List

  • My code follows the code style of this project.
  • This PR does not contain plagiarized content.
  • The title and description clearly explain the approach.

Note to reviewers

  • The feature is implemented using a custom React hook that defaults to true, ensuring the dialog always appears unless explicitly disabled.
  • Please test this by closing, or refreshing the tab.
  • Please review and give feedback.

πŸ“· Screenshots

N/A

Copy link

vercel bot commented Feb 15, 2025

@afsar-hussai is attempting to deploy a commit to the dunsin's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Dun-sin
Copy link
Owner

Dun-sin commented Feb 15, 2025

Hi @afsar-hussai please provide a working screen recording for this and kindly attach it to the PR

@Dun-sin
Copy link
Owner

Dun-sin commented Mar 4, 2025

Hi @afsar-hussai please provide a working screen recording for this and kindly attach it to the PR

@afsar-hussai


import { useEffect } from "react"

export const useCloseAndReloadHandle=(condition=true)=>{
Copy link
Contributor

Choose a reason for hiding this comment

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

can you name the args betters

Copy link
Author

Choose a reason for hiding this comment

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

In general Hooks are written with use, so here i created a hook thats why i use useCloseAndReloadHandle as hook name.


function App() {
ReactGA.initialize(import.meta.env.VITE_GOOGLE_ANALYTICS);
useCloseAndReloadHandle();
Copy link
Contributor

Choose a reason for hiding this comment

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

how do you plan to check if the chat is active or not?

Copy link
Author

Choose a reason for hiding this comment

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

yes please can you guide me to do this. lets colabrate and do this.

@t-trafer
Copy link
Contributor

t-trafer commented Mar 4, 2025

a few things to add here:

  • only intercept the beforeunload event if the chat is active
  • adding custom messages is not permissible as per modern browser standards, do add a comment for that in the code for future reference
  • improve the variable/file name to avoid confusion

@t-trafer
Copy link
Contributor

t-trafer commented Mar 5, 2025

is this under active development? i can work on this if needed

@Dun-sin
Copy link
Owner

Dun-sin commented Mar 6, 2025

is this under active development? i can work on this if needed

@t-trafer he still has 5 days to fix his PR, in the meantime you can check other issues and see what else you can work on

@t-trafer
Copy link
Contributor

t-trafer commented Mar 6, 2025

yeah that works @Dun-sin thanks

@Dun-sin
Copy link
Owner

Dun-sin commented Mar 11, 2025

@t-trafer still want to work on this?

@Dun-sin
Copy link
Owner

Dun-sin commented Mar 17, 2025

hi @afsar-hussai the time assigned to this Issue is over, your PR is now closed. Thanks for trying to contribute, you're free to ask to work on other issues, if you can meet up with the time assigned.

@Dun-sin Dun-sin closed this Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] send warning dialog when users want to close the tab
3 participants