Skip to content

Commit

Permalink
refactor: 닉네임 설정 화면 UX 개선 및 리팩토링 #252
Browse files Browse the repository at this point in the history
[REFACTOR] 닉네임 설정 화면 UX 개선 및 리팩토링
  • Loading branch information
rbgksqkr authored Sep 9, 2024
2 parents dd8d462 + 52f43d5 commit abd80b7
Show file tree
Hide file tree
Showing 20 changed files with 170 additions and 63 deletions.
15 changes: 9 additions & 6 deletions frontend/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import type { Preview } from '@storybook/react';
import { RecoilRoot } from 'recoil';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { MemoryRouter } from 'react-router-dom';
import { Global, ThemeProvider } from '@emotion/react';
Expand Down Expand Up @@ -32,12 +33,14 @@ const preview: Preview = {
decorators: [
(Story) => (
<QueryClientProvider client={queryClient}>
<ThemeProvider theme={Theme}>
<MemoryRouter initialEntries={['/']}>
<Global styles={GlobalStyle} />
<Story />
</MemoryRouter>
</ThemeProvider>
<RecoilRoot>
<ThemeProvider theme={Theme}>
<MemoryRouter initialEntries={['/']}>
<Global styles={GlobalStyle} />
<Story />
</MemoryRouter>
</ThemeProvider>
</RecoilRoot>
</QueryClientProvider>
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { useEffect, useState } from 'react';
import { useNavigate, useParams } from 'react-router-dom';

import { fetchRoundVoteIsFinished } from '@/apis/balanceContent';
import { POLLING_DELAY } from '@/constants/config';
import { QUERY_KEYS } from '@/constants/queryKeys';
import { ROUTES } from '@/constants/routes';
import { POLLING_DELAY } from '@/constants/time';

interface UseRoundIsFinishedQueryProps {
contentId?: number;
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Timer/Timer.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useRef, useState } from 'react';

import { convertMsecToSecond } from './Timer.util';

import { ONE_SECOND } from '@/constants/time';
import { POLLING_DELAY } from '@/constants/config';
import useBalanceContentQuery from '@/hooks/useBalanceContentQuery';

const INITIAL_WIDTH = 100;
Expand Down Expand Up @@ -33,7 +33,7 @@ const useRoundTimer = (roomId: number) => {
timeout.current = setInterval(() => {
setLeftRoundTime((prev) => prev - 1);
setBarWidthPercent((prevWidth) => (prevWidth > 0 ? prevWidth - DECREASE_RATE : 0));
}, ONE_SECOND);
}, POLLING_DELAY);

return () => {
clearInterval(timeout.current);
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Timer/Timer.util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ONE_SECOND } from '@/constants/time';
import { POLLING_DELAY } from '@/constants/config';

export const formatLeftRoundTime = (leftRoundTime: number) => {
const minutes = Math.floor(leftRoundTime / 60);
Expand All @@ -11,6 +11,6 @@ export const formatLeftRoundTime = (leftRoundTime: number) => {
};

export const convertMsecToSecond = (msec: number) => {
const UNIT_MSEC = ONE_SECOND;
const UNIT_MSEC = POLLING_DELAY;
return msec / UNIT_MSEC;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { userEvent } from '@testing-library/user-event';

import RoomSettingModal from './RoomSettingModal';

import { ONE_SECOND } from '@/constants/time';
import { POLLING_DELAY } from '@/constants/config';
import ROOM_INFO from '@/mocks/data/roomInfo.json';
import { useGetRoomInfo } from '@/pages/ReadyPage/useGetRoomInfo';
import { customRender, wrapper } from '@/utils/test-utils';
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('RoomSettingModal 방 설정 모달 테스트', () => {
expect(result.current.roomSetting).toEqual(ROOM_INFO.roomSetting);
});

await clickButton(`${TIME_LIMIT / ONE_SECOND}초`);
await clickButton(`${TIME_LIMIT / POLLING_DELAY}초`);
await clickButton('적용');

await waitFor(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from './RoomSettingModal.styled';
import Modal from '../Modal/Modal';

import { ONE_SECOND } from '@/constants/time';
import { POLLING_DELAY } from '@/constants/config';

const TOTAL_ROUND_LIST = [5, 7, 10];
const TIMER_PER_ROUND_LIST = [5000, 10000, 15000];
Expand Down Expand Up @@ -58,7 +58,7 @@ const RoomSettingModal = ({ isOpen, onClose }: RoomSettingModalProps) => {
onClick={handleClickTimeLimit}
value={timeLimit}
>
{timeLimit / ONE_SECOND}
{timeLimit / POLLING_DELAY}
</button>
</li>
))}
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/constants/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const NICKNAME_MAX_LENGTH = 12;
export const POLLING_DELAY = 1000;
3 changes: 0 additions & 3 deletions frontend/src/constants/time.ts

This file was deleted.

4 changes: 2 additions & 2 deletions frontend/src/hooks/useMyGameStatusQuery.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useQuery } from '@tanstack/react-query';

import { checkMyGameStatus } from '@/apis/balanceContent';
import { POLLING_DELAY } from '@/constants/config';
import { QUERY_KEYS } from '@/constants/queryKeys';
import { ONE_SECOND } from '@/constants/time';

interface useMyGameStatusQueryProps {
currentRound: number | undefined;
Expand All @@ -22,7 +22,7 @@ const useMyGameStatusQuery = ({ roomId, currentRound }: useMyGameStatusQueryProp
});
},
enabled: !!currentRound,
refetchInterval: ONE_SECOND,
refetchInterval: POLLING_DELAY,
gcTime: 0,
});

Expand Down
6 changes: 5 additions & 1 deletion frontend/src/mocks/data/roomInfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,9 @@
"nickname": "프콩",
"isMaster": false
}
]
],
"master": {
"memberId": 2,
"nickname": "든콩"
}
}
6 changes: 3 additions & 3 deletions frontend/src/mocks/handlers/balanceContentHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import BALANCE_CONTENT from '../data/balanceContent.json';
import MY_GAME_STATUS from '../data/myGameStatus.json';
import ROUND_VOTE_IS_FINISHED from '../data/roundVoteIsFinished.json';

import { ONE_SECOND } from '@/constants/time';
import { POLLING_DELAY } from '@/constants/config';
import { MOCK_API_URL } from '@/constants/url';
import { BalanceContent } from '@/types/balanceContent';

Expand All @@ -15,10 +15,10 @@ const fetchBalanceContentHandler = () => {
const fetchIsFinishedHandler = () => {
setTimeout(() => {
ROUND_VOTE_IS_FINISHED.isFinished = true;
}, 10 * ONE_SECOND);
}, 10 * POLLING_DELAY);
setTimeout(() => {
ROUND_VOTE_IS_FINISHED.isFinished = false;
}, 12 * ONE_SECOND);
}, 12 * POLLING_DELAY);

return HttpResponse.json(ROUND_VOTE_IS_FINISHED);
};
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/GameResultPage/hooks/useCheckRoomReset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { useEffect } from 'react';
import { useNavigate, useParams } from 'react-router-dom';

import { isRoomInitial } from '@/apis/room';
import { POLLING_DELAY } from '@/constants/config';
import { QUERY_KEYS } from '@/constants/queryKeys';
import { ROUTES } from '@/constants/routes';
import { ONE_SECOND } from '@/constants/time';

export const useIsRoomInitial = () => {
const { roomId } = useParams();
const navigate = useNavigate();
const { data } = useQuery({
queryKey: [QUERY_KEYS.isRoomInitial, Number(roomId)],
queryFn: async () => await isRoomInitial(Number(roomId)),
refetchInterval: ONE_SECOND,
refetchInterval: POLLING_DELAY,
gcTime: 0,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { css } from '@emotion/react';

import { Theme } from '@/styles/Theme';

export const nicknameInputContainer = css`
display: flex;
align-items: center;
width: 100%;
height: 4.8rem;
padding: 0 1rem;
border-radius: ${Theme.borderRadius.radius10};
background-color: ${Theme.color.gray200};
`;

export const nicknameInput = css`
width: 100%;
border: 0;
background-color: ${Theme.color.gray200};
outline: none;
`;

export const nicknameLengthText = css`
color: ${Theme.color.gray500};
`;
38 changes: 38 additions & 0 deletions frontend/src/pages/NicknamePage/NicknameInput/NicknameInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { RefObject } from 'react';

import useNicknameInput from './hooks/useNicknameInput';
import { nicknameInput, nicknameInputContainer, nicknameLengthText } from './NicknameInput.styled';
import createRandomNickname from '../createRandomNickname';

import { NICKNAME_MAX_LENGTH } from '@/constants/config';

interface NicknameInputProps {
nicknameInputRef: RefObject<HTMLInputElement>;
handleMakeOrEnterRoom: () => void;
}

const NicknameInput = ({ nicknameInputRef, handleMakeOrEnterRoom }: NicknameInputProps) => {
const { nickname, handleChangeInput, handleKeyDown } = useNicknameInput({
handleMakeOrEnterRoom,
});
const randomNickname = createRandomNickname();

return (
<div css={nicknameInputContainer}>
<input
ref={nicknameInputRef}
css={nicknameInput}
placeholder={randomNickname}
maxLength={NICKNAME_MAX_LENGTH}
value={nickname}
onChange={handleChangeInput}
onKeyDown={handleKeyDown}
/>
<span css={nicknameLengthText}>
{nickname.length}/{NICKNAME_MAX_LENGTH}
</span>
</div>
);
};

export default NicknameInput;
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ChangeEvent, useState } from 'react';

import { NICKNAME_MAX_LENGTH } from '@/constants/config';

interface UseNicknameInputProps {
handleMakeOrEnterRoom: () => void;
}

const useNicknameInput = ({ handleMakeOrEnterRoom }: UseNicknameInputProps) => {
const [nickname, setNickname] = useState('');

const handleChangeInput = (e: ChangeEvent<HTMLInputElement>) => {
if (e.target.value.length <= NICKNAME_MAX_LENGTH) {
setNickname(e.target.value);
}
};

const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
if (event.key === 'Enter') {
handleMakeOrEnterRoom();
}
};

return { nickname, handleChangeInput, handleKeyDown };
};

export default useNicknameInput;
14 changes: 12 additions & 2 deletions frontend/src/pages/NicknamePage/NicknamePage.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ export const profileImg = css`
width: 60%;
`;

export const nicknameBox = css`
export const nicknameContainer = css`
display: flex;
flex-direction: column;
gap: 1.6rem;
width: 26.8rem;
margin: 2rem 0;
`;

export const nicknameTitle = css`
font-weight: 600;
font-size: 1.6rem;
`;
Expand All @@ -44,6 +49,11 @@ export const nicknameInput = css`
background-color: ${Theme.color.gray200};
outline: none;
`;

export const nicknameLengthText = css`
color: ${Theme.color.gray500};
`;

export const noVoteTextContainer = css`
display: flex;
flex-direction: column;
Expand All @@ -61,4 +71,4 @@ export const noVoteText = css`
export const angryImage = css`
width: 16rem;
height: 14rem;
`;
`;
Loading

0 comments on commit abd80b7

Please sign in to comment.