Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import { useApp } from 'src/context/AppContext';
import { useAuth } from 'context/AuthContext';
import useIsTabActive from './hooks/useIsTabActive';
import MatchFound from './pages/MatchFound';
import { useCloseAndReloadHandle } from './hooks/useCloseHandle';

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.


const { isLoggedIn } = useAuth();
const { updateOnlineStatus, app } = useApp();
Expand Down
23 changes: 23 additions & 0 deletions client/src/hooks/useCloseHandle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@


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.

useEffect(()=>{
const closeWindowHandler=(event)=>{
if (condition) {
event.preventDefault();
event.returnValue='';

}

}

window.addEventListener('beforeunload',closeWindowHandler);

return ()=>{
window.removeEventListener('beforeunload',closeWindowHandler)
}

},[condition])
}
Loading