Skip to content

Commit

Permalink
[Feat] API 받아오는거 추가#1083
Browse files Browse the repository at this point in the history
  • Loading branch information
Junho Jeon committed Nov 9, 2023
1 parent 30ce63f commit 27a6b26
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 22 deletions.
29 changes: 27 additions & 2 deletions components/tournament/TournamentCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { TournamentInfo } from 'types/modalTypes';
import { totalmem } from 'os';
import { useSetRecoilState } from 'recoil';
import { TournamentInfo , Modal } from 'types/modalTypes';
import { modalState } from 'utils/recoil/modal';
import styles from 'styles/tournament/TournamentCard.module.scss';

export default function TournamentCard({
Expand All @@ -12,8 +15,30 @@ export default function TournamentCard({
winnerImage,
endDate,
}: TournamentInfo) {
const setModal = useSetRecoilState<Modal>(modalState);

const openTournamentInfoModal = () => {
setModal({
modalName: 'TOURNAMENT-REGISTRY',
tournamentInfo: {
tournametId: tournametId,
title: title,
contents: contents,
startDate: startDate,
status: status,
type: type,
winnerId: winnerId,
winnerImage: winnerImage,
endDate: endDate,
},
});
};

return (
<div className={styles.tournamentCardContainer}>
<div
className={styles.tournamentCardContainer}
onClick={openTournamentInfoModal}
>
<div className={styles.text}>{title}</div>
</div>
);
Expand Down
103 changes: 83 additions & 20 deletions pages/tournament.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useQuery } from 'react-query';
import { useSetRecoilState } from 'recoil';
import { Modal } from 'types/modalTypes';
import { modalState } from 'utils/recoil/modal';
import { TournamentInfo } from 'types/modalTypes';
import { instance } from 'utils/axios';
import { errorState } from 'utils/recoil/error';
import TournamentCard from 'components/tournament/TournamentCard';
import styles from 'styles/tournament/TournamentContainer.module.scss';

Expand All @@ -21,7 +23,62 @@ const tempData = {
},
{
tournametId: 6,
title: '6회 마스터 토너먼트',
title: '7회 마스터 토너먼트',
contents: '블라블라 하이하이',
startDate: '2023-11-12',
status: '진행중',
type: 'master',
winnerId: 'hannkim',
winnerImage: '',
endDate: '2023-11-12',
},
{
tournametId: 6,
title: '8회 마스터 토너먼트',
contents: '블라블라 하이하이',
startDate: '2023-11-12',
status: '진행중',
type: 'master',
winnerId: 'hannkim',
winnerImage: '',
endDate: '2023-11-12',
},
{
tournametId: 6,
title: '9회 마스터 토너먼트',
contents: '블라블라 하이하이',
startDate: '2023-11-12',
status: '진행중',
type: 'master',
winnerId: 'hannkim',
winnerImage: '',
endDate: '2023-11-12',
},
{
tournametId: 6,
title: '10회 마스터 토너먼트',
contents: '블라블라 하이하이',
startDate: '2023-11-12',
status: '진행중',
type: 'master',
winnerId: 'hannkim',
winnerImage: '',
endDate: '2023-11-12',
},
{
tournametId: 6,
title: '11회 마스터 토너먼트',
contents: '블라블라 하이하이',
startDate: '2023-11-12',
status: '진행중',
type: 'master',
winnerId: 'hannkim',
winnerImage: '',
endDate: '2023-11-12',
},
{
tournametId: 6,
title: '12회 마스터 토너먼트',
contents: '블라블라 하이하이',
startDate: '2023-11-12',
status: '진행중',
Expand All @@ -35,24 +92,30 @@ const tempData = {
};

export default function Tournament() {
const setModal = useSetRecoilState<Modal>(modalState);
const setError = useSetRecoilState(errorState);

const openTorunamentInfo = useQuery<TournamentInfo>(
'openTorunamentInfo',
() =>
instance
.get('pingpong/tournaments?page=*&type=*&status=진행중')
.then((res) => res.data),
{ retry: 1, staleTime: 60000 /* 60초 */ }
);

const waitTournamentInfo = useQuery<TournamentInfo>(
'waitTournamentInfo',
() =>
instance
.get('pingpong/tournaments?page=*&type=*&status=예정')
.then((res) => res.data),
{ retry: 1, staleTime: 60000 /* 60초 */ }
);

if (openTorunamentInfo.isError || waitTournamentInfo.isError) {
setError('junhjeon');
}

const handleTournament = () => {
setModal({
modalName: 'TOURNAMENT-REGISTRY',
tournamentInfo: {
tournametId: 5,
title: '5회 루키 토너먼트',
contents: '블라블라',
startDate: '2023-11-11',
status: '종료',
type: 'rookie',
winnerId: 'hannkim',
winnerImage: '',
endDate: '2023-11-11',
},
});
};
return (
<div className={styles.pageWrap}>
<h1 className={styles.title}>Tournament</h1>
Expand Down

0 comments on commit 27a6b26

Please sign in to comment.