Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 126a208

Browse files
committed
マルチプレイ、参加リクエストを何度も送れないようにする
1 parent e9140a7 commit 126a208

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/components/Exhibition/Menu/Multiplay.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const Multiplay: React.FC<
3838
ReturnType<typeof useMultiplay> & {
3939
onClose: () => void;
4040
}
41-
> = ({ join, leave, onClose, players }) => {
41+
> = ({ alreadyJoinRequested, join, leave, onClose, players }) => {
4242
const [groupId, setGroupId] = useState("");
4343

4444
const handleChangeInput = useCallback(
@@ -49,12 +49,16 @@ export const Multiplay: React.FC<
4949
);
5050

5151
const handleClickJoinButton = useCallback(() => {
52+
if (alreadyJoinRequested) {
53+
return;
54+
}
55+
5256
join(groupId ? groupId : undefined);
53-
}, [groupId, join]);
57+
}, [alreadyJoinRequested, groupId, join]);
5458

5559
return (
5660
<ExhibitionPopup label="みんなでトリップする" onClose={onClose} small>
57-
<div className="flex flex-col h-full w-full">
61+
<div className="flex flex-col w-full h-full">
5862
<div css={description}>
5963
友達と一緒にトリップしたいときは夢番地を入力してトリップしよう!入力せずにトリップするとランダムな夢番地に繋がるよ
6064
</div>
@@ -70,7 +74,7 @@ export const Multiplay: React.FC<
7074
/>
7175
{!players && (
7276
<div
73-
className="bg-blue-400 bold cursor-pointer mt-auto text-center"
77+
className="mt-auto text-center bg-blue-400 cursor-pointer bold"
7478
css={connectButton}
7579
onClick={handleClickJoinButton}
7680
>
@@ -79,7 +83,7 @@ export const Multiplay: React.FC<
7983
)}
8084
{!!players && (
8185
<div
82-
className="bg-red-400 bold cursor-pointer mt-auto text-center"
86+
className="mt-auto text-center bg-red-400 cursor-pointer bold"
8387
css={connectButton}
8488
onClick={leave}
8589
>

src/hooks/exhibition/useMultuplay.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export const useMultiplay = () => {
4444
> | null>(null);
4545
const [lastUpdate, setLastUpdate] = useState<UpdatePayload | null>(null);
4646
const [socket, setSocket] = useState(createSocket());
47+
const [alreadyJoinRequested, setAlreadyJoinRequested] = useState(false);
4748

4849
//
4950

@@ -63,6 +64,7 @@ export const useMultiplay = () => {
6364

6465
const join = useCallback(
6566
(payload?: string) => {
67+
setAlreadyJoinRequested(true);
6668
socket.connect();
6769
socket.emit("join", payload);
6870
GA.multiplay("join");
@@ -95,6 +97,7 @@ export const useMultiplay = () => {
9597
);
9698

9799
const handleSocketDisconnect = useCallback(() => {
100+
setAlreadyJoinRequested(false);
98101
setPlayers(null);
99102
GA.multiplay("leave");
100103
}, []);
@@ -180,6 +183,7 @@ export const useMultiplay = () => {
180183
//
181184

182185
return {
186+
alreadyJoinRequested,
183187
join,
184188
leave: handleLeave,
185189
players,

0 commit comments

Comments
 (0)