Skip to content

Commit

Permalink
Merge branch 'dev' into Fix/#187
Browse files Browse the repository at this point in the history
  • Loading branch information
pp449 authored Oct 27, 2023
2 parents 82b6559 + 21db013 commit 3c14848
Show file tree
Hide file tree
Showing 19 changed files with 447 additions and 511 deletions.
514 changes: 59 additions & 455 deletions __mocks__/constants/matchRoundMock.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion __mocks__/handlers/matchHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const players: GetMatchPlayerScoreInfos = {
matchPlayerResultStatus: '진행중',
},
],
matchMessage: [
matchMessages: [
{
channelId: 123,
content: '안녕하세요',
Expand Down
5 changes: 5 additions & 0 deletions src/@types/admin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface CallAdmin {
matchRound: number;
matchName: string;
callName: string;
}
5 changes: 3 additions & 2 deletions src/@types/bracket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ interface PlayerInfo {
}
interface MatchInfo {
matchName: string;
matchStatus: string;
matchId: number;
matchStatus: 'READY' | 'PROGRESS' | 'END';
matchRound: number;
matchCurrentSet: number;
matchSetCurrent: number;
matchPlayerInfoList: PlayerInfo[];
matchId: number;
alarm: boolean;
}

export interface BracketContents {
Expand Down
3 changes: 2 additions & 1 deletion src/@types/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export type IconKind =
| 'sendEmail'
| 'modify'
| 'setting'
| 'cancel';
| 'cancel'
| 'shortcut';
1 change: 1 addition & 0 deletions src/components/Content/ContentModify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const ContentModify = ({ title, content, onUpdateContent }: ContentModifyProps)
css={css`
text-align: start;
white-space: pre-line;
padding: 3rem;
`}
>
<PreviewTitle>{titleRef.current ? titleRef.current.value : ''}</PreviewTitle>
Expand Down
2 changes: 2 additions & 0 deletions src/components/Icon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
MdSettings,
MdCancel,
MdIndeterminateCheckBox,
MdOutlineShortcut,
} from 'react-icons/md';
import { MouseEventHandler } from 'react';

Expand All @@ -35,6 +36,7 @@ const ICON: { [key in IconKind]: IconType } = {
setting: MdSettings,
cancel: MdCancel,
disqualification: MdIndeterminateCheckBox,
shortcut: MdOutlineShortcut,
};

interface IconProps {
Expand Down
91 changes: 91 additions & 0 deletions src/components/RoundAlarm/RoundAlarmBody.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import authAPI from '@apis/authAPI';
import Icon from '@components/Icon';
import styled from '@emotion/styled';
import { BracketContents } from '@type/bracket';
import { useRouter } from 'next/router';
import { useEffect, useState } from 'react';

interface Props {
curRound: number;
havingAlarm: boolean;
}

const RoundAlarmBody = ({ curRound, havingAlarm }: Props) => {
const router = useRouter();

console.log(havingAlarm);

const [roundInfo, setRoundInfo] = useState<BracketContents>();

useEffect(() => {
const getRoundInfo = async () => {
try {
const res = await authAPI({
method: 'get',
url: `/api/match/${router.query.channelLink as string}/${curRound}`,
});

setRoundInfo(res.data);
} catch (error) {}
};

getRoundInfo();
}, []);

const moveToCheckIn = (matchId: number) => {
authAPI({
method: 'post',
url: `/api/match/${router.query.channelLink as string}/${matchId}/call-off`,
});

router.push(`/contents/${router.query.channelLink as string}/checkIn/${matchId}`);
};

return (
<Ground>
{roundInfo?.matchInfoDtoList.map((match) => {
return (
<GroupContainer key={match.matchId} onClick={() => moveToCheckIn(match.matchId)}>
<GroupTitle>{match.matchName}</GroupTitle>
<Icon kind='shortcut' size={25} />

{(match.alarm || havingAlarm) && <AlarmCircle />}
</GroupContainer>
);
})}
</Ground>
);
};

const Ground = styled.div`
margin: 2rem 0;
`;

const GroupContainer = styled.div`
width: 15rem;
height: 4rem;
display: flex;
align-items: center;
border: 0.2rem solid #132043;
justify-content: space-around;
position: relative;
cursor: pointer;
`;

const GroupTitle = styled.div`
font-size: 2rem;
`;

const AlarmCircle = styled.div`
position: absolute;
width: 0.8rem;
height: 0.8rem;
right: 0.4rem;
background-color: #c70039;
border-radius: 0.4rem;
`;

export default RoundAlarmBody;
52 changes: 52 additions & 0 deletions src/components/RoundAlarm/RoundAlarmHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import styled from '@emotion/styled';

interface Props {
liveRound: number;
curRound: number;
}

type bracketStatus = 'PAST' | 'PRESENT' | 'FUTURE';

const RoundAlarmHeader = ({ liveRound, curRound }: Props) => {
return (
<>
{liveRound > curRound && <Button status='PAST'>Round {curRound}</Button>}
{liveRound === curRound && <Button status='PRESENT'>Round {curRound}</Button>}
{liveRound < curRound && <Button status='FUTURE'>Round {curRound}</Button>}
</>
);
};

const Button = styled.button<{ status: bracketStatus }>`
width: 12rem;
height: 4rem;
border: none;
padding: 0;
margin: 0;
font-size: 1.6rem;
color: white;
${(prop) =>
prop.status === 'PAST' &&
`
background-color : #7C81AD;
cursor: pointer;
`}
${(prop) =>
prop.status === 'PRESENT' &&
`
background-color : #4B527E;
cursor: pointer;
`}
${(prop) =>
prop.status === 'FUTURE' &&
`
background-color : #2E4374;
cursor: not-allowed
`}
`;

export default RoundAlarmHeader;
52 changes: 43 additions & 9 deletions src/components/RoundCheckIn/CallAdminChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,34 @@ import { css } from '@emotion/react';
import styled from '@emotion/styled';
import Image from 'next/image';
import { Client } from '@stomp/stompjs';
import React, { useEffect, useState, ChangeEvent } from 'react';
import React, { useEffect, useState, ChangeEvent, useRef } from 'react';
import { useRouter } from 'next/router';
import { BASE_PROFILE_IMG } from '@config/index';

interface CallAdminChatProps {
client: Client | undefined;
matchId: string;
players: MatchPlayerScoreInfos[];
matchMessage: MatchMessages[];
matchMessages: MatchMessages[];
requestUser: number;
}

const CallAdminChat = ({
client,
matchId,
players,
matchMessage,
matchMessages,
requestUser,
}: CallAdminChatProps) => {
const [chats, setChats] = useState<MatchMessages[]>([]);
const [inputMessage, setInputMessage] = useState('');
const router = useRouter();
const { channelLink } = router.query;
const chatEndRef = useRef<HTMLDivElement>(null);

const scrollToBottom = () => {
chatEndRef.current?.scrollIntoView({ behavior: 'smooth' });
};

const handleInputMessage = (e: ChangeEvent<HTMLInputElement>) => {
setInputMessage(e.target.value);
Expand Down Expand Up @@ -57,16 +63,37 @@ const CallAdminChat = ({
setInputMessage('');
};

const callAdmin = () => {
if (!client) {
return;
}

if (!window.confirm('관리자를 호출하시겠어요?\n호출한 이후에는 취소할 수 없습니다.')) {
console.log('cancel');
return;
}

const requestUserParticipantId = players.find(
(player) => player.matchPlayerId === requestUser,
)?.participantId;

client.publish({
destination: `/app/match/${
router.query.channelLink as string
}/${requestUserParticipantId}/${matchId}/call-admin`,
});
};

const findUserIMG = (playerParticipantId: number): string => {
const user = players.find((player) => player.participantId === playerParticipantId);

if (!user) return '';
if (!user) return BASE_PROFILE_IMG;
return user.profileSrc;
};

const findUserName = (playerParticipantId: number): string => {
const user = players.find((player) => player.participantId === playerParticipantId);
if (!user) return '';
if (!user) return '관리자';
return user.gameId;
};

Expand All @@ -88,15 +115,19 @@ const CallAdminChat = ({
}, [client]);

useEffect(() => {
if (!matchMessage || matchMessage.length === 0) return;
setChats(matchMessage);
}, [matchMessage]);
if (!matchMessages || matchMessages.length === 0) return;
setChats(matchMessages.reverse());
}, [matchMessages]);

useEffect(() => {
scrollToBottom();
}, [chats]);

return (
<Container>
<Header>
<div>Chat</div>
<CallAdminButton>Call Admin</CallAdminButton>
<CallAdminButton onClick={callAdmin}>Call Admin</CallAdminButton>
</Header>
<ChattingWrapper>
{chats.length !== 0 &&
Expand Down Expand Up @@ -126,6 +157,7 @@ const CallAdminChat = ({
</ChattingContent>
</ChattingInfo>
))}
<div ref={chatEndRef} />
</ChattingWrapper>
<div
css={css`
Expand Down Expand Up @@ -170,6 +202,8 @@ const CallAdminButton = styled.button`
width: 9rem;
border: none;
border-radius: 0.3rem;
cursor: pointer;
`;

const ChattingWrapper = styled.div`
Expand Down
6 changes: 3 additions & 3 deletions src/components/RoundCheckIn/CheckInPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface CheckInPageProps {
client: Client | undefined;
matchId: string;
players: MatchPlayerScoreInfos[];
matchMessage: MatchMessages[];
matchMessages: MatchMessages[];
requestUser: number;
checkInUser: number[];
currentMatchRound: number;
Expand All @@ -23,7 +23,7 @@ const CheckInPage = ({
client,
matchId,
players,
matchMessage,
matchMessages,
requestUser,
checkInUser,
currentMatchRound,
Expand Down Expand Up @@ -120,7 +120,7 @@ const CheckInPage = ({
client={client}
matchId={matchId}
players={players}
matchMessage={matchMessage}
matchMessages={matchMessages}
requestUser={requestUser}
/>
</ChattingWrapper>
Expand Down
Loading

0 comments on commit 3c14848

Please sign in to comment.