Skip to content

Commit

Permalink
merge: 사용자 피드백을 반영하여 게임 화면에서 멤버별 투표 현황 보여주기 #427
Browse files Browse the repository at this point in the history
[FEAT] 사용자 피드백을 반영하여 게임 화면에서 멤버별 투표 현황 보여주기
  • Loading branch information
rbgksqkr authored Dec 11, 2024
2 parents fa9f278 + 77cc45c commit 218925d
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 12 deletions.
2 changes: 2 additions & 0 deletions frontend/src/apis/balanceContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ interface myGameStatusParams {

interface VoteIsFinished {
isFinished: boolean;
memberCount: number;
voteCount: number;
}

interface MatchingResultParams {
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/constants/url.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { getUserInfo } from '@/apis/room';

const BASE_URL = process.env.API_BASE_URL;

export const API_URL = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { css } from '@emotion/react';
import type { Theme } from '@emotion/react';

export const gameVoteStatusLayout = css`
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
gap: 1.2rem;
height: 4rem;
`;

export const voteStatusMessage = (theme: Theme, isPending: boolean) => css`
font-weight: bold;
font-size: 1.6rem;
opacity: ${isPending ? theme.opacity.invisible : theme.opacity.default};
transition: 1s;
`;

export const voteAnnounceMessage = (theme: Theme) => css`
color: ${theme.color.gray500};
font-weight: bold;
font-size: 1.2rem;
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {
gameVoteStatusLayout,
voteStatusMessage,
voteAnnounceMessage,
} from './GameVoteStatusContainer.styled';
import useVoteIsFinished from '../hooks/useVoteIsFinished';

interface GameVoteStatusContainerProps {
contentId: number;
isFetching: boolean;
}

const GameVoteStatusContainer = ({ contentId, isFetching }: GameVoteStatusContainerProps) => {
const { voteCount, memberCount, isPending } = useVoteIsFinished({
contentId,
isFetching,
});

const voteStatusText = `${memberCount ?? 0}명 중 ${voteCount ?? 0}명이 투표했어요!`;

return (
<div css={gameVoteStatusLayout}>
<span css={(theme) => voteStatusMessage(theme, isPending)}>{voteStatusText}</span>
<span css={voteAnnounceMessage}>“모두 선택하면 빠르게 결과를 확인할 수 있어요”</span>
</div>
);
};

export default GameVoteStatusContainer;
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useParams } from 'react-router-dom';

import GameVoteStatusContainer from './GameVoteStatusContainer/GameVoteStatusContainer';
import useSelectOption from './hooks/useSelectOption';
import { selectContainerLayout, selectSection } from './SelectContainer.styled';
import SelectOption from './SelectOption/SelectOption';
Expand All @@ -10,7 +11,7 @@ import useBalanceContentQuery from '@/hooks/useBalanceContentQuery';

const SelectContainer = () => {
const { roomId } = useParams();
const { balanceContent } = useBalanceContentQuery(Number(roomId));
const { balanceContent, isFetching } = useBalanceContentQuery(Number(roomId));
const { selectedOption, handleClickOption, completeSelection, cancelSelection } =
useSelectOption();

Expand All @@ -34,6 +35,7 @@ const SelectContainer = () => {
handleClickOption={handleClickOption}
/>
</section>
<GameVoteStatusContainer contentId={balanceContent.contentId} isFetching={isFetching} />
<SelectButton
contentId={balanceContent.contentId}
selectedOption={selectedOption}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect } from 'react';
import { useNavigate, useParams } from 'react-router-dom';

import useRoundIsFinishedQuery from './useVoteIsFinishedQuery';
import useVoteIsFinishedQuery from './useVoteIsFinishedQuery';

import { ROUTES } from '@/constants/routes';

Expand All @@ -13,7 +13,7 @@ interface UseRoundIsFinishedProps {
const useVoteIsFinished = ({ contentId, isFetching }: UseRoundIsFinishedProps) => {
const navigate = useNavigate();
const { roomId } = useParams();
const { isFinished } = useRoundIsFinishedQuery({
const { isFinished, memberCount, voteCount, isPending } = useVoteIsFinishedQuery({
contentId,
enabled: !!contentId && !isFetching,
});
Expand All @@ -24,7 +24,7 @@ const useVoteIsFinished = ({ contentId, isFetching }: UseRoundIsFinishedProps) =
}
}, [isFinished, navigate, roomId, isFetching]);

return { isFinished };
return { memberCount, voteCount, isPending };
};

export default useVoteIsFinished;
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ const useVoteIsFinishedQuery = ({ contentId, enabled }: UseVoteIsFinishedQueryPr
gcTime: 0,
});

return { ...voteIsFinishedQuery, isFinished: voteIsFinishedQuery.data?.isFinished };
return {
...voteIsFinishedQuery,
isFinished: voteIsFinishedQuery.data?.isFinished,
memberCount: voteIsFinishedQuery.data?.memberCount,
voteCount: voteIsFinishedQuery.data?.voteCount,
};
};

export default useVoteIsFinishedQuery;
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const useCountdown = ({ isGameStart }: UseCountdownProps) => {
};

const goToGame = () => {
navigate(ROUTES.game(Number(roomId)));
navigate(ROUTES.game(Number(roomId)), { replace: true });
};

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/styles/Theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const opacity = {
invisible: 0,
disabled: 0.6,
default: 1,
};
} as const;

export const Theme = {
color,
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/styles/emotion.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import '@emotion/react';
import { Theme } from './Theme';

type ExtendedTheme = typeof Theme;

declare module '@emotion/react' {
export interface Theme {
color: { [key: string]: string };
}
export interface Theme extends ExtendedTheme {}
}

0 comments on commit 218925d

Please sign in to comment.