Skip to content

Commit

Permalink
[🚚change]: λ©”μΈνŽ˜μ΄μ§€ λ‚΄ μƒμˆ˜ ν΄λ”μƒμ„±ν•˜μ—¬ 이동, νƒ€μž… 이름 λͺ…μ‹œμ μœΌλ‘œ λ³€κ²½
Browse files Browse the repository at this point in the history
  • Loading branch information
loevray committed Apr 17, 2024
1 parent f22fbd2 commit fa55ae9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
13 changes: 7 additions & 6 deletions src/pages/MainPage/GameModeCheckBox.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as Checkbox from '@radix-ui/react-checkbox';
import { CheckIcon } from '@radix-ui/react-icons';
import { Dispatch, SetStateAction } from 'react';
import { gameModeList, mappedGameModeList, TestType } from './MainPage';
import { GAME_MODE_LIST, MAPPED_GAME_MODE_LIST } from './constants/gameMode';
import { CheckedGameModeType } from './MainPage';

interface GameModeCheckBoxProps {
setCheckedGameMode: Dispatch<SetStateAction<TestType>>;
checkedGameMode: TestType;
setCheckedGameMode: Dispatch<SetStateAction<CheckedGameModeType>>;
checkedGameMode: CheckedGameModeType;
}

const GameModeCheckBox = ({
Expand All @@ -14,14 +15,14 @@ const GameModeCheckBox = ({
}: GameModeCheckBoxProps) => {
return (
<form className='flex gap-[3rem]'>
{gameModeList.map((mode, i) => {
{GAME_MODE_LIST.map((mode, i) => {
//맀 λ Œλ”λ§μ‹œ μƒμ„±λ˜λ―€λ‘œ map λ°”κΉ₯으둜 λΊ€λ‹€?
const onCheckedChange = () => {
setCheckedGameMode((prevState) => {
const isNewMode = !prevState[mode];
if (mode === 'ALL') {
const newState = { ...prevState };
let checkGameModeState: keyof TestType;
let checkGameModeState: keyof CheckedGameModeType;
for (checkGameModeState in prevState) {
newState[checkGameModeState] = isNewMode;
}
Expand All @@ -46,7 +47,7 @@ const GameModeCheckBox = ({
<label
className='cursor-pointer text-[2rem] font-bold'
htmlFor={`c${i}`}>
{mappedGameModeList[mode]}
{MAPPED_GAME_MODE_LIST[mode]}
</label>
</div>
);
Expand Down
8 changes: 4 additions & 4 deletions src/pages/MainPage/MainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import UserList from './UserList';

export type FilteredGameModeType = GameModeType | 'ALL';

export type TestType = {
export type CheckedGameModeType = {
[key in FilteredGameModeType]: boolean;
};

Expand All @@ -31,18 +31,18 @@ const MainPage = () => {
const { data: userData, isPending, error } = useAuthCheck();
const { roomInfo, setRoomInfo } = useRoomInfoStore();

const [checkedGameMode, setCheckedGameMode] = useState<TestType>({
const [checkedGameMode, setCheckedGameMode] = useState<CheckedGameModeType>({
ALL: true,
SENTENCE: true,
CODE: true,
WORD: true,
});

const checkedGameModeList = (
Object.entries(checkedGameMode) as EntriesType<TestType>
Object.entries(checkedGameMode) as EntriesType<CheckedGameModeType>
)
.filter(([mode, state]) => mode !== 'ALL' && state)
.map(([mode]) => mode) as Exclude<keyof TestType, 'ALL'>[];
.map(([mode]) => mode) as Exclude<keyof CheckedGameModeType, 'ALL'>[];

const { setDidAdminStart } = useGameWaitingRoomStore();
useEffect(() => {
Expand Down
15 changes: 15 additions & 0 deletions src/pages/MainPage/constants/gameMode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { FilteredGameModeType } from '../MainPage';

export const GAME_MODE_LIST: FilteredGameModeType[] = [
'ALL',
'SENTENCE',
'CODE',
'WORD',
];

export const MAPPED_GAME_MODE_LIST = {
ALL: '전체',
SENTENCE: 'λ¬Έμž₯',
CODE: 'μ½”λ“œ',
WORD: '단어',
};

0 comments on commit fa55ae9

Please sign in to comment.