X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fcomponents%2Ftournament%2FScoreboard.js;h=f13adacb61bbaa7a4465f88fb8b549ea535cca40;hb=237ebc69c5eb4fbfe226c4dcdc9711d7b18ddcd2;hp=cbc73a32620db88204b5fa81f669a5db18c79702;hpb=5dacd7900839a5e270de87de8c4f51dea385c1f0;p=alttp.git diff --git a/resources/js/components/tournament/Scoreboard.js b/resources/js/components/tournament/Scoreboard.js index cbc73a3..f13adac 100644 --- a/resources/js/components/tournament/Scoreboard.js +++ b/resources/js/components/tournament/Scoreboard.js @@ -5,29 +5,57 @@ import { withTranslation } from 'react-i18next'; import Icon from '../common/Icon'; import Box from '../users/Box'; -import { calculateScores } from '../../helpers/Tournament'; +import { comparePlacement } from '../../helpers/Participant'; +import { getRunners } from '../../helpers/Tournament'; import { withUser } from '../../helpers/UserContext'; import i18n from '../../i18n'; -const getRowClassName = (tournament, score, user) => { +const getRowClassName = (tournament, participant, user) => { const classNames = ['score']; - if (score && user && score.participant && score.participant.user_id == user.id) { + if (participant && user && participant.user_id == user.id) { classNames.push('is-self'); } return classNames.join(' '); }; -const getPlacementDisplay = score => { - if (score.placement === 1) { +const getPlacementDisplay = participant => { + if (participant.placement === 1) { return ; } - if (score.placement === 2) { + if (participant.placement === 2) { return ; } - if (score.placement === 3) { + if (participant.placement === 3) { return ; } - return score.placement; + return participant.placement; +}; + +const twitchReg = /^https?:\/\/(www\.)?twitch\.tv/; +const youtubeReg = /^https?:\/\/(www\.)?youtu(\.be|be\.)/; + +const getStreamVariant = participant => { + if (!participant || !participant.user || !participant.user.stream_link) { + return 'outline-secondary'; + } + if (twitchReg.test(participant.user.stream_link)) { + return 'outline-twitch'; + } + if (youtubeReg.test(participant.user.stream_link)) { + return 'outline-youtube'; + } + return 'outline-secondary'; +}; + +const getStreamIcon = participant => { + const variant = getStreamVariant(participant); + if (variant === 'outline-twitch') { + return ; + } + if (variant === 'outline-youtube') { + return ; + } + return ; }; const Scoreboard = ({ tournament, user }) => @@ -40,28 +68,28 @@ const Scoreboard = ({ tournament, user }) => - {calculateScores(tournament).map(score => - + {getRunners(tournament).sort(comparePlacement).map(participant => + - {getPlacementDisplay(score)} + {getPlacementDisplay(participant)}
- - {score.participant.user.stream_link ? + + {participant.user.stream_link ? : null}
- {score.score} + {participant.score} )}