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

Feature/#160 경찰 이미 스킬 사용했을 때는 토스트, 아직 결과가 안왔을 때는 모달 안띄운다 #161

Merged
merged 2 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 1 addition & 4 deletions src/components/job/PoliceNight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { middle } from '../../pages/Night';
import { VariablesCSS } from '../../styles/VariablesCSS';
import { Player } from '../../type';
import InvestResult from '../modal/InvestResult';
import ModalContainer from '../modal/ModalContainer';
import PlayerGrid from '../player/PlayerGrid';
import PlayerNight from '../player/PlayerNight';

Expand Down Expand Up @@ -48,9 +47,7 @@ export const PoliceNight = (props: PropsType) => {
</PlayerGrid>
</div>
{/* 경찰: 조사하기 */}
<ModalContainer isOpen={openModal}>
<InvestResult target={players[check - 1]?.name} />
</ModalContainer>
{openModal && <InvestResult target={players[check - 1]?.name} isOpen={openModal} />}
</>
);
};
Expand Down
38 changes: 27 additions & 11 deletions src/components/modal/InvestResult.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,49 @@
/** @jsxImportSource @emotion/react */
import { css } from '@emotion/react';
import { useEffect, useState } from 'react';
import { Toaster } from 'react-hot-toast';

import { postSkill } from '../../axios/http';
import { VariablesCSS } from '../../styles/VariablesCSS';
import { Job, SkillResponse } from '../../type';
import PlayerInvest from '../player/PlayerInvest';
import { notifyUseToast } from '../toast/NotifyToast';
import ModalContainer from './ModalContainer';

interface PropsType {
target: string;
isOpen: boolean;
}
export default function InvestResult(props: PropsType) {
const { target } = props;
export default function InvestResult({ target, isOpen }: PropsType) {
const [jobResult, setJobResult] = useState<Job>(null);

const [jobResult, setJobResult] = useState<Job>('CITIZEN');
useEffect(() => {
(async () => {
const skillResponse: SkillResponse = await postSkill({ target: target });
setJobResult(skillResponse.result);
try {
const skillResponse: SkillResponse = await postSkill({ target: target });
setJobResult(skillResponse.result);
} catch (error: any) {
console.log(jobResult);

notifyUseToast(error.response.data.message, 'LOBBY');
}
})();
}, [target]);

return (
<div css={container}>
<PlayerInvest job={jobResult} name={target} />
<p css={description(jobResult)}>
{jobResult === 'MAFIA' ? '마피아가 맞습니다' : '마피아가 아닙니다'}
</p>
</div>
<>
{jobResult && (
<ModalContainer isOpen={isOpen}>
<div css={container}>
<PlayerInvest job={jobResult} name={target} />
<p css={description(jobResult)}>
{jobResult === 'MAFIA' ? '마피아가 맞습니다' : '마피아가 아닙니다'}
</p>
</div>
</ModalContainer>
)}
<Toaster />
</>
);
}

Expand Down
4 changes: 4 additions & 0 deletions src/pages/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ export default function Game() {
// 방 정보 저장 (방 상태가 바뀔때만 작동?)
useEffect(() => {
(async () => {
if (gamesStatus.statusType == 'WAIT') {
setMyJobRecoilState(null);
}

// 방 정보 불러오기
const roomInfoResponse = await getGamesInfo();
setRoomsInfoState(roomInfoResponse);
Expand Down
Loading