X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;ds=sidebyside;f=resources%2Fjs%2Fcomponents%2Ftournament%2FScoreboard.js;h=f13adacb61bbaa7a4465f88fb8b549ea535cca40;hb=7dbb5572dc613186d45fd08275cac81249af06aa;hp=008974b7cc76ce1b8f362707f0dfb6fdcead4ee0;hpb=1c3b922ba7143a548c8a7526f5e4384f336e2f1e;p=alttp.git
diff --git a/resources/js/components/tournament/Scoreboard.js b/resources/js/components/tournament/Scoreboard.js
index 008974b..f13adac 100644
--- a/resources/js/components/tournament/Scoreboard.js
+++ b/resources/js/components/tournament/Scoreboard.js
@@ -1,25 +1,95 @@
import PropTypes from 'prop-types';
import React from 'react';
-import { Table } from 'react-bootstrap';
+import { Button, Table } from 'react-bootstrap';
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 Scoreboard = ({ tournament }) =>
-
+const getRowClassName = (tournament, participant, user) => {
+ const classNames = ['score'];
+ if (participant && user && participant.user_id == user.id) {
+ classNames.push('is-self');
+ }
+ return classNames.join(' ');
+};
+
+const getPlacementDisplay = participant => {
+ if (participant.placement === 1) {
+ return ;
+ }
+ if (participant.placement === 2) {
+ return ;
+ }
+ if (participant.placement === 3) {
+ return ;
+ }
+ 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 }) =>
+
+ {i18n.t('participants.placementShort')} |
{i18n.t('participants.participant')} |
- {i18n.t('participants.score')} |
+ {i18n.t('participants.scoreShort')} |
- {calculateScores(tournament).map(score =>
-
- |
- {score.score} |
+ {getRunners(tournament).sort(comparePlacement).map(participant =>
+
+
+ {getPlacementDisplay(participant)}
+ |
+
+
+
+ {participant.user.stream_link ?
+
+ : null}
+
+ |
+ {participant.score} |
)}
@@ -28,6 +98,8 @@ const Scoreboard = ({ tournament }) =>
Scoreboard.propTypes = {
tournament: PropTypes.shape({
}),
+ user: PropTypes.shape({
+ }),
};
-export default withTranslation()(Scoreboard);
+export default withTranslation()(withUser(Scoreboard));