Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/#165: 게임 결과 입력하는 칸 추가 및 자동으로 다음 라운드 페이지가 보이도록 추가 #168

Merged
merged 10 commits into from
Oct 10, 2023
Merged
Changes from 1 commit
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
57 changes: 49 additions & 8 deletions src/components/RoundCheckIn/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { connectToStomp } from '@config/stomp';
import { Client, StompSubscription } from '@stomp/stompjs';
import authAPI from '@apis/authAPI';
import { useRouter } from 'next/router';
import { css } from '@emotion/react';

export interface MatchPlayerScoreInfos {
matchPlayerId: number;
Expand All @@ -31,8 +32,9 @@ export interface MatchMessages {

export interface GetMatchPlayerScoreInfos {
requestMatchPlayerId: number;
currentMatchRound: number;
totalMatchRound: number;
matchRound: number;
matchCurrentSet: number;
matchSetCount: number;
matchPlayerInfos: MatchPlayerScoreInfos[];
matchMessage: MatchMessages[];
}
Expand Down Expand Up @@ -73,19 +75,43 @@ const RoundCheckIn = ({ channelLink, matchId }: RoundCheckInProps) => {
const tmpClient = connectToStomp();
tmpClient.activate();

let subscription: StompSubscription;
let checkInSubscription: StompSubscription;
let nextRoundSubscription: StompSubscription;

tmpClient.onConnect = () => {
setClient(tmpClient);
subscription = tmpClient.subscribe(`/match/${matchId}`, (data) => {
checkInSubscription = tmpClient.subscribe(`/match/${matchId}`, (data) => {
const readyUserPlayerId = Number(JSON.parse(data.body).matchPlayerId);
if (checkInUser.includes(readyUserPlayerId)) return;
setCheckInUser((prevUsers) => [...prevUsers, readyUserPlayerId]);
});

if (!matchPlayers) return;
nextRoundSubscription = tmpClient.subscribe(
`/match/${matchId}/${matchPlayers.matchCurrentSet}`,
(data) => {
alert('다음 라운드가 진행됩니다');
const responseData = JSON.parse(data.body);
if (!matchPlayers) return;
setMatchPlayers((prevMatchPlayer) => {
if (!prevMatchPlayer) return;
return {
...prevMatchPlayer,
matchRound: responseData.matchRound,
matchCurrentSet: responseData.matchCurrentSet,
matchSetCount: responseData.matchSetCount,
matchPlayerInfos: responseData.matchPlayerInfoList,
};
});
setCheckInUser([]);
},
);
};

return () => {
if (!client) return;
if (subscription) subscription.unsubscribe();
if (checkInSubscription) checkInSubscription.unsubscribe();
if (nextRoundSubscription) nextRoundSubscription.unsubscribe();
client.deactivate();
};
}, []);
Expand All @@ -103,8 +129,23 @@ const RoundCheckIn = ({ channelLink, matchId }: RoundCheckInProps) => {
<Container>
<ContainerHeader>
<RoundInfo>
{matchPlayers ? matchPlayers.currentMatchRound : 0} of{' '}
{matchPlayers ? matchPlayers.totalMatchRound : 0}
<div
css={css`
font-size: 1.5em;
display: inline-block;
`}
>
{matchPlayers ? matchPlayers.matchRound : 0} ROUND{' '}
</div>
<div
css={css`
display: inline-block;
padding-left: 3rem;
`}
>
{matchPlayers ? matchPlayers.matchCurrentSet : 0} of{' '}
Comment on lines +145 to +153
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{' '} 이 부분 나중에 삭제하시면 좋을 것 같아요

{matchPlayers ? matchPlayers.matchSetCount : 0}
</div>
</RoundInfo>
<FlexWrapper>
<CheckInfo>
Expand All @@ -131,7 +172,7 @@ const RoundCheckIn = ({ channelLink, matchId }: RoundCheckInProps) => {
matchMessage={matchPlayers ? matchPlayers.matchMessage : []}
requestUser={matchPlayers ? matchPlayers.requestMatchPlayerId : -1}
checkInUser={checkInUser}
currentMatchRound={matchPlayers ? matchPlayers.currentMatchRound : -1}
currentMatchRound={matchPlayers ? matchPlayers.matchCurrentSet : -1}
/>
</FlexWrapper>
</Container>
Expand Down