X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fcomponents%2Ftournament%2FScoreboard.js;h=27bb0873a4d7c75d4de6a3b15f25f1d514a07713;hb=4c5a82cb876e96c72c50e8bc12bd8a43a9afe847;hp=40ad82ff300724acda076a5f7038d1546b723c5e;hpb=d32516335ea2534e15256c948e9c38d3de40794b;p=alttp.git diff --git a/resources/js/components/tournament/Scoreboard.js b/resources/js/components/tournament/Scoreboard.js index 40ad82f..27bb087 100644 --- a/resources/js/components/tournament/Scoreboard.js +++ b/resources/js/components/tournament/Scoreboard.js @@ -1,14 +1,13 @@ import PropTypes from 'prop-types'; import React from 'react'; import { Button, Table } from 'react-bootstrap'; -import { withTranslation } from 'react-i18next'; +import { useTranslation } from 'react-i18next'; import Icon from '../common/Icon'; import Box from '../users/Box'; import { comparePlacement } from '../../helpers/Participant'; import { getRunners } from '../../helpers/Tournament'; -import { withUser } from '../../helpers/UserContext'; -import i18n from '../../i18n'; +import { useUser } from '../../hooks/user'; const getRowClassName = (tournament, participant, user) => { const classNames = ['score']; @@ -31,48 +30,77 @@ const getPlacementDisplay = participant => { return participant.placement; }; -const Scoreboard = ({ tournament, user }) => - - - - - - - - - - {getRunners(tournament).sort(comparePlacement).map(participant => - - - - - - )} - -
{i18n.t('participants.placementShort')}{i18n.t('participants.participant')}{i18n.t('participants.scoreShort')}
- {getPlacementDisplay(participant)} - -
- - {participant.user.stream_link ? - - : null} -
-
{participant.score}
; +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 }) => { + const { t } = useTranslation(); + const { user } = useUser(); + + return + + + + + + + + + {getRunners(tournament).sort(comparePlacement).map(participant => + + + + + + )} + +
{t('participants.placementShort')}{t('participants.participant')}{t('participants.scoreShort')}
+ {getPlacementDisplay(participant)} + +
+ + {participant.user.stream_link ? + + : null} +
+
{participant.score}
; +}; Scoreboard.propTypes = { tournament: PropTypes.shape({ }), - user: PropTypes.shape({ - }), }; -export default withTranslation()(withUser(Scoreboard)); +export default Scoreboard;