Skip to content

Commit

Permalink
feat: cannot cancel if matched #1
Browse files Browse the repository at this point in the history
  • Loading branch information
luckylooky2 committed Sep 25, 2023
1 parent 9475d4a commit 3cd472e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/pages/Waiting.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useContext, useEffect } from "react";
import { useCallback, useContext, useEffect, useState } from "react";
import { useNavigate } from "react-router";
import Loading from "@utils/Loading";
import BasicButton from "@utils/BasicButton";
Expand All @@ -12,6 +12,7 @@ import { OpponentInfo } from "@typings/front";

const Waiting = () => {
const navigate = useNavigate();
const [matched, setMatched] = useState(false);
const { myInfo } = useContext(AuthContext);
const { socket } = useContext(SocketContext);
const { callInfo, dispatch } = useContext(CallContext);
Expand All @@ -30,6 +31,7 @@ const Waiting = () => {
"matching",
(data: { opponent: OpponentInfo[]; roomName: string }) => {
console.log("matching");
setMatched(true);
dispatch({
type: CallActionType.SET_MATCHING,
payload: {
Expand Down Expand Up @@ -68,6 +70,9 @@ const Waiting = () => {

const cancelWaiting = useCallback(() => {
dispatch({ type: CallActionType.DEL_ALL });
socket?.emit("unregister", {
nickname: myInfo?.nickname,
});
stopMicrophone();
navigate("/main");
}, [callInfo]);
Expand All @@ -85,7 +90,11 @@ const Waiting = () => {
return (
<Loading text={"상대방을 찾는 중입니다."}>
<div className="my-auto">
<BasicButton onClick={cancelWaiting} text="매칭 취소하기" />
<BasicButton
onClick={cancelWaiting}
text="매칭 취소하기"
disabled={matched}
/>
</div>
</Loading>
);
Expand Down

0 comments on commit 3cd472e

Please sign in to comment.