-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/관리자-토너먼트-페이지-api-연동-#1131
- Loading branch information
Showing
9 changed files
with
147 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Match } from '@g-loot/react-tournament-brackets/dist/src/types'; | ||
import { useCallback, useEffect, useState, useRef } from 'react'; | ||
import { TournamentGame } from 'types/tournamentTypes'; | ||
import { convertTournamentGamesToBracketMatchs } from 'utils/handleTournamentGame'; | ||
import { mockInstance } from 'utils/mockAxios'; | ||
import TournamentBraket from 'components/tournament/TournamentBraket'; | ||
import useComponentSize from 'hooks/util/useComponentSize'; | ||
import styles from 'styles/tournament-record/UserTournamentBracket.module.scss'; | ||
|
||
interface UserTournamentBracketProps { | ||
tournamentId: number | undefined; | ||
} | ||
|
||
export default function UserTournamentBraket({ | ||
tournamentId, | ||
}: UserTournamentBracketProps) { | ||
const [ref, size] = useComponentSize<HTMLDivElement>(); | ||
|
||
const [bracketMatchs, setBracketMatchs] = useState<Match[]>([]); | ||
const [isLoading, setIsLoading] = useState(false); | ||
|
||
// const putHandler = async () => { | ||
// await instanceInManage.put( | ||
// `/pingpong/admin/tournaments/${tournamentId}}/games`, | ||
// { | ||
// games: tournament | ||
// } | ||
// ); | ||
// }; | ||
|
||
const fetchTournamentGames = useCallback(async () => { | ||
console.log('Fetching more data...'); | ||
try { | ||
const res = await mockInstance.get(`/tournament/${tournamentId}/games`); | ||
setIsLoading(false); | ||
const data: TournamentGame[] = res.data.games; | ||
const bracketMatchs = convertTournamentGamesToBracketMatchs(data); | ||
setBracketMatchs(bracketMatchs); | ||
return data; | ||
} catch (error) { | ||
setIsLoading(false); | ||
console.error('Error fetching data:', error); | ||
} | ||
}, [tournamentId]); | ||
|
||
useEffect(() => { | ||
setIsLoading(true); | ||
const identifier = setTimeout(() => { | ||
console.log('fetching tournament game data..'); | ||
fetchTournamentGames(); | ||
}, 500); | ||
return () => clearTimeout(identifier); | ||
}, [tournamentId, fetchTournamentGames]); | ||
|
||
return ( | ||
<div ref={ref} className={styles.bracketContainer}> | ||
{isLoading ? ( | ||
<div className={styles.loadingAnimation} /> | ||
) : ( | ||
<TournamentBraket | ||
singleEliminationBracketMatchs={bracketMatchs} | ||
containerSize={size} | ||
/> | ||
)} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { useState, useLayoutEffect, useRef } from 'react'; | ||
|
||
interface Size { | ||
width: number | undefined; | ||
height: number | undefined; | ||
} | ||
|
||
export default function useComponentSize<T extends HTMLElement>(): [ | ||
React.RefObject<T>, | ||
Size | ||
] { | ||
const ref = useRef<T>(null); | ||
const [size, setSize] = useState<Size>({ | ||
width: undefined, | ||
height: undefined, | ||
}); | ||
|
||
useLayoutEffect(() => { | ||
if (ref.current) { | ||
setSize({ | ||
width: ref.current.offsetWidth, | ||
height: ref.current.offsetHeight, | ||
}); | ||
} | ||
}, []); | ||
|
||
return [ref, size]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
styles/tournament-record/UserTournamentBracket.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
@import 'styles/common.scss'; | ||
|
||
.bracketContainer { | ||
display: flex; | ||
width: 100%; | ||
height: 30rem; | ||
margin-top: 1rem; | ||
overflow: hidden; | ||
background-color: rgba(112, 0, 225, 0.17); | ||
border: 1px solid #c67dff; | ||
border-radius: 26px; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
@keyframes Rotate { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
|
||
.loadingAnimation { | ||
width: 3rem; | ||
height: 3rem; | ||
border: 0.3rem solid rgb(167, 167, 167); | ||
border-top-color: transparent; | ||
border-left-color: transparent; | ||
border-radius: 50%; | ||
animation: Rotate 0.8s infinite linear; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters