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

Commit

Permalink
マルチプレイ、参加リクエストを何度も送れないようにする
Browse files Browse the repository at this point in the history
  • Loading branch information
calmery committed Feb 27, 2021
1 parent e9140a7 commit 126a208
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/components/Exhibition/Menu/Multiplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const Multiplay: React.FC<
ReturnType<typeof useMultiplay> & {
onClose: () => void;
}
> = ({ join, leave, onClose, players }) => {
> = ({ alreadyJoinRequested, join, leave, onClose, players }) => {
const [groupId, setGroupId] = useState("");

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

const handleClickJoinButton = useCallback(() => {
if (alreadyJoinRequested) {
return;
}

join(groupId ? groupId : undefined);
}, [groupId, join]);
}, [alreadyJoinRequested, groupId, join]);

return (
<ExhibitionPopup label="みんなでトリップする" onClose={onClose} small>
<div className="flex flex-col h-full w-full">
<div className="flex flex-col w-full h-full">
<div css={description}>
友達と一緒にトリップしたいときは夢番地を入力してトリップしよう!入力せずにトリップするとランダムな夢番地に繋がるよ
</div>
Expand All @@ -70,7 +74,7 @@ export const Multiplay: React.FC<
/>
{!players && (
<div
className="bg-blue-400 bold cursor-pointer mt-auto text-center"
className="mt-auto text-center bg-blue-400 cursor-pointer bold"
css={connectButton}
onClick={handleClickJoinButton}
>
Expand All @@ -79,7 +83,7 @@ export const Multiplay: React.FC<
)}
{!!players && (
<div
className="bg-red-400 bold cursor-pointer mt-auto text-center"
className="mt-auto text-center bg-red-400 cursor-pointer bold"
css={connectButton}
onClick={leave}
>
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/exhibition/useMultuplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const useMultiplay = () => {
> | null>(null);
const [lastUpdate, setLastUpdate] = useState<UpdatePayload | null>(null);
const [socket, setSocket] = useState(createSocket());
const [alreadyJoinRequested, setAlreadyJoinRequested] = useState(false);

//

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

const join = useCallback(
(payload?: string) => {
setAlreadyJoinRequested(true);
socket.connect();
socket.emit("join", payload);
GA.multiplay("join");
Expand Down Expand Up @@ -95,6 +97,7 @@ export const useMultiplay = () => {
);

const handleSocketDisconnect = useCallback(() => {
setAlreadyJoinRequested(false);
setPlayers(null);
GA.multiplay("leave");
}, []);
Expand Down Expand Up @@ -180,6 +183,7 @@ export const useMultiplay = () => {
//

return {
alreadyJoinRequested,
join,
leave: handleLeave,
players,
Expand Down

0 comments on commit 126a208

Please sign in to comment.