-
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.
- Loading branch information
1 parent
bd209b9
commit e3b564a
Showing
10 changed files
with
513 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import dynamic from 'next/dynamic'; | ||
import { | ||
SVGViewer as StaticSVGViewer, | ||
SingleEliminationBracket as StaticSingleEliminationBracket, | ||
} from '@g-loot/react-tournament-brackets'; | ||
import { Match } from '@g-loot/react-tournament-brackets/dist/src/types'; | ||
import React from 'react'; | ||
import TournamentEditMatch from './TournamentEditMatch'; | ||
|
||
if (typeof window !== 'undefined' && typeof window.navigator !== 'undefined') { | ||
import('@g-loot/react-tournament-brackets'); | ||
} | ||
|
||
const SingleEliminationBracket = dynamic< | ||
React.ComponentProps<typeof StaticSingleEliminationBracket> | ||
>( | ||
() => { | ||
return import('@g-loot/react-tournament-brackets').then( | ||
(mod) => mod.SingleEliminationBracket | ||
); | ||
}, | ||
{ ssr: false } | ||
); | ||
|
||
const SVGViewer = dynamic<React.ComponentProps<typeof StaticSVGViewer>>( | ||
() => { | ||
return import('@g-loot/react-tournament-brackets').then( | ||
(mod) => mod.SVGViewer | ||
); | ||
}, | ||
{ ssr: false } | ||
); | ||
|
||
interface TournamentEditBraketProps { | ||
singleEliminationBracketMatchs: Match[]; | ||
containerSize: { width: number | undefined; height: number | undefined }; | ||
} | ||
|
||
export default function TournamentEditBraket({ | ||
singleEliminationBracketMatchs, | ||
containerSize, | ||
}: TournamentEditBraketProps) { | ||
if (singleEliminationBracketMatchs.length === 0) { | ||
return <h1 style={{ color: 'white' }}>Loading...</h1>; | ||
} | ||
|
||
return ( | ||
<SingleEliminationBracket | ||
matches={singleEliminationBracketMatchs} | ||
matchComponent={TournamentEditMatch} | ||
options={{ | ||
style: { | ||
width: 230, | ||
boxHeight: 120, | ||
roundHeader: { | ||
isShown: false, | ||
fontColor: '#FFFFFF', | ||
}, | ||
connectorColor: '#FFFFFF', | ||
connectorColorHighlight: '#da96c6', | ||
}, | ||
}} | ||
svgWrapper={({ children, ...props }) => ( | ||
<SVGViewer | ||
background={'rgba(0, 0, 0, 0)'} | ||
SVGBackground={'rgba(0, 0, 0, 0)'} | ||
width={containerSize.width} | ||
height={containerSize.height} | ||
{...props} | ||
> | ||
{children} | ||
</SVGViewer> | ||
)} | ||
/> | ||
); | ||
} |
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,208 @@ | ||
import { | ||
Match, | ||
MatchComponentProps, | ||
Participant, | ||
} from '@g-loot/react-tournament-brackets/dist/src/types'; | ||
import { useContext, useRef, useState } from 'react'; | ||
import { TournamentIdContext } from 'components/modal/admin/AdminEditTournamentBraket'; | ||
import PlayerImage from 'components/PlayerImage'; | ||
import useTournamentMatchEditor from 'hooks/tournament/useTournamentMatchEditor'; | ||
import styles from 'styles/admin/tournament/TournamentEditMatch.module.scss'; | ||
|
||
interface TournamentMatchPartyProps { | ||
party: Participant; | ||
teamNameFallback: string; | ||
resultFallback: (participant: Participant) => string; | ||
onMouseEnter: (partyId: string | number) => void; | ||
} | ||
|
||
function TournamentMatchParty({ | ||
party, | ||
teamNameFallback, | ||
onMouseEnter, | ||
resultFallback, | ||
}: TournamentMatchPartyProps) { | ||
return ( | ||
<div | ||
className={styles.tournamentPartyWrapper} | ||
onMouseEnter={() => onMouseEnter(party.id)} | ||
> | ||
<PlayerImage | ||
src={party.picture ?? '/image/match_qustion.png'} | ||
styleName={`tournament`} | ||
size={1} | ||
/> | ||
|
||
<div className={styles.partyName}>{party.name || teamNameFallback}</div> | ||
<div className={styles.score}> | ||
{party.resultText ?? resultFallback(party)} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
interface TournamentMatchProps { | ||
topParty: Participant; | ||
bottomParty: Participant; | ||
teamNameFallback: string; | ||
resultFallback: (participant: Participant) => string; | ||
onMouseEnter: (partyId: string | number) => void; | ||
} | ||
|
||
function TournamentMatch({ | ||
topParty, | ||
bottomParty, | ||
teamNameFallback, | ||
onMouseEnter, | ||
resultFallback, | ||
}: TournamentMatchProps) { | ||
return ( | ||
<> | ||
<TournamentMatchParty | ||
party={topParty} | ||
teamNameFallback={teamNameFallback} | ||
onMouseEnter={onMouseEnter} | ||
resultFallback={resultFallback} | ||
></TournamentMatchParty> | ||
<TournamentMatchParty | ||
party={bottomParty} | ||
teamNameFallback={teamNameFallback} | ||
onMouseEnter={onMouseEnter} | ||
resultFallback={resultFallback} | ||
></TournamentMatchParty> | ||
</> | ||
); | ||
} | ||
|
||
interface TournamentEditMatchPartyProps { | ||
party: Participant; | ||
handleScoreInputChange: (event: React.ChangeEvent<HTMLInputElement>) => void; | ||
} | ||
|
||
function TournamentEditMatchParty({ | ||
party, | ||
handleScoreInputChange, | ||
}: TournamentEditMatchPartyProps) { | ||
const inputRef = useRef<HTMLInputElement>(null); | ||
|
||
return ( | ||
<div className={styles.tournamentPartyWrapper}> | ||
<PlayerImage | ||
src={party.picture ?? '/image/match_qustion.png'} | ||
styleName={`tournament`} | ||
size={1} | ||
/> | ||
|
||
<div className={styles.partyName}>{party.name}</div> | ||
<input | ||
ref={inputRef} | ||
className={styles.scoreInput} | ||
name={`team-${party.id}-score`} | ||
value={party.resultText ?? ''} | ||
onChange={handleScoreInputChange} | ||
onClick={() => { | ||
inputRef.current?.focus(); | ||
}} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
interface TournamentMatchEditorProps { | ||
topParty: Participant; | ||
bottomParty: Participant; | ||
unsetEditor: () => void; | ||
handleScoreInputChange: (event: React.ChangeEvent<HTMLInputElement>) => void; | ||
putHandler: () => void; | ||
} | ||
|
||
function TournamentMatchEditor({ | ||
topParty, | ||
bottomParty, | ||
unsetEditor, | ||
handleScoreInputChange, | ||
putHandler, | ||
}: TournamentMatchEditorProps) { | ||
return ( | ||
<> | ||
<TournamentEditMatchParty | ||
party={topParty} | ||
handleScoreInputChange={handleScoreInputChange} | ||
/> | ||
<TournamentEditMatchParty | ||
party={bottomParty} | ||
handleScoreInputChange={handleScoreInputChange} | ||
/> | ||
<div className={styles.buttonsContainer}> | ||
<button onClick={unsetEditor}>취소</button> | ||
<button onClick={putHandler}>수정하기</button> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
export default function TournamentEditMatch({ | ||
match, | ||
onMatchClick, | ||
onPartyClick, | ||
onMouseEnter, | ||
onMouseLeave, | ||
topWon, | ||
bottomWon, | ||
topHovered, | ||
bottomHovered, | ||
topText, | ||
bottomText, | ||
connectorColor, | ||
computedStyles, | ||
teamNameFallback, | ||
resultFallback, | ||
}: MatchComponentProps) { | ||
const tournamentId = useContext(TournamentIdContext); | ||
const { | ||
isEditor, | ||
topParty, | ||
bottomParty, | ||
setEditor, | ||
unsetEditor, | ||
handleScoreInputChange, | ||
putHandler, | ||
} = useTournamentMatchEditor(match, tournamentId); | ||
return ( | ||
<> | ||
<div | ||
className={ | ||
match.isModifiable && isEditor === false | ||
? styles.tournamentEditMatchContainer | ||
: styles.tournamentMatchContainer | ||
} | ||
> | ||
{match.isModifiable && isEditor === false && ( | ||
<button | ||
className={styles.tournamentEditMatchButton} | ||
onClick={setEditor} | ||
> | ||
수정하기 | ||
</button> | ||
)} | ||
{isEditor === true ? ( | ||
<TournamentMatchEditor | ||
topParty={topParty} | ||
bottomParty={bottomParty} | ||
unsetEditor={unsetEditor} | ||
handleScoreInputChange={handleScoreInputChange} | ||
putHandler={putHandler} | ||
/> | ||
) : ( | ||
<TournamentMatch | ||
topParty={topParty} | ||
bottomParty={bottomParty} | ||
teamNameFallback={teamNameFallback} | ||
onMouseEnter={onMouseEnter} | ||
resultFallback={resultFallback} | ||
/> | ||
)} | ||
</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
Oops, something went wrong.