Skip to content

Commit 315b0cd

Browse files
committed
Add back navigation confirmation popup on matching pages
1 parent 59f7419 commit 315b0cd

File tree

4 files changed

+39
-26
lines changed

4 files changed

+39
-26
lines changed

frontend/package-lock.json

Lines changed: 22 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
"@mui/material": "^6.1.0",
2323
"@uiw/react-md-editor": "^4.0.4",
2424
"axios": "^1.7.7",
25+
"history": "^5.3.0",
2526
"react": "^18.3.1",
2627
"react-dom": "^18.3.1",
2728
"react-hook-form": "^7.53.0",
2829
"react-material-ui-carousel": "^3.4.2",
29-
"react-router-dom": "^6.26.2",
30+
"react-router-dom": "^6.3.0",
3031
"react-toastify": "^10.0.5",
3132
"socket.io-client": "^4.8.0",
3233
"vite-plugin-svgr": "^4.2.0"

frontend/src/contexts/MatchContext.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
import { useAuth } from "./AuthContext";
1616
import { toast } from "react-toastify";
1717
import useAppNavigate from "../components/UseAppNavigate";
18+
import { UNSAFE_NavigationContext } from "react-router-dom";
19+
import { Action, type History, type Transition } from "history";
1820

1921
type MatchUser = {
2022
id: string;
@@ -109,6 +111,8 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
109111
const [matchPending, setMatchPending] = useState<boolean>(false);
110112
const [loading, setLoading] = useState<boolean>(true);
111113

114+
const navigator = useContext(UNSAFE_NavigationContext).navigator as History;
115+
112116
useEffect(() => {
113117
if (user) {
114118
setMatchUser({
@@ -135,6 +139,16 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
135139
openSocketConnection();
136140
matchSocket.emit(MatchEvents.USER_CONNECTED, matchUser?.id);
137141

142+
const unblock = navigator.block((transition: Transition) => {
143+
if (
144+
transition.action === Action.Replace ||
145+
confirm(ABORT_MATCH_PROCESS_CONFIRMATION_MESSAGE)
146+
) {
147+
unblock();
148+
appNavigate(transition.location.pathname);
149+
}
150+
});
151+
138152
const handleBeforeUnload = (e: BeforeUnloadEvent) => {
139153
e.preventDefault();
140154
e.returnValue = ABORT_MATCH_PROCESS_CONFIRMATION_MESSAGE; // for legacy support, does not actually display message

frontend/src/pages/Home/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ const Home: React.FC = () => {
296296
}
297297
onClick={() => {
298298
setIsQueryingQnDB(true);
299-
getQuestionList(1, 10, "", complexities, categories, dispatch);
299+
getQuestionList(1, 1, "", complexities, categories, dispatch);
300300
}}
301301
>
302302
{isQueryingQnDB ? <CircularProgress /> : "Find my match!"}

0 commit comments

Comments
 (0)