From: Daniel Karbach Date: Wed, 23 Mar 2022 15:46:54 +0000 (+0100) Subject: show placement on scoreboard X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=6c3125ca01833f7cec3659353840dbe1ddfb0fc6;p=alttp.git show placement on scoreboard --- diff --git a/resources/js/components/tournament/Scoreboard.js b/resources/js/components/tournament/Scoreboard.js index e142a80..ea6a666 100644 --- a/resources/js/components/tournament/Scoreboard.js +++ b/resources/js/components/tournament/Scoreboard.js @@ -6,19 +6,45 @@ import { withTranslation } from 'react-i18next'; import Icon from '../common/Icon'; import Box from '../users/Box'; import { calculateScores } from '../../helpers/Tournament'; +import { withUser } from '../../helpers/UserContext'; import i18n from '../../i18n'; -const Scoreboard = ({ tournament }) => - +const getRowClassName = (tournament, score, user) => { + const classNames = ['score']; + if (score && user && score.participant && score.participant.user_id == user.id) { + classNames.push('is-self'); + } + return classNames.join(' '); +}; + +const getPlacementDisplay = score => { + if (score.placement === 1) { + return ; + } + if (score.placement === 2) { + return ; + } + if (score.placement === 3) { + return ; + } + return score.placement; +}; + +const Scoreboard = ({ tournament, user }) => +
+ - + {calculateScores(tournament).map(score => - + + - + )} @@ -44,6 +70,8 @@ const Scoreboard = ({ tournament }) => Scoreboard.propTypes = { tournament: PropTypes.shape({ }), + user: PropTypes.shape({ + }), }; -export default withTranslation()(Scoreboard); +export default withTranslation()(withUser(Scoreboard)); diff --git a/resources/js/helpers/Tournament.js b/resources/js/helpers/Tournament.js index 38750e7..7dffebb 100644 --- a/resources/js/helpers/Tournament.js +++ b/resources/js/helpers/Tournament.js @@ -32,7 +32,21 @@ export const calculateScores = tournament => { } } }); - return scores.sort(compareScore).reverse(); + const sorted = scores.sort(compareScore); + let placement = scores.length; + let skipped = 0; + let lastScore = sorted[0].score; + for (let i = 0; i < sorted.length; ++i) { + if (sorted[i].score > lastScore) { + placement -= skipped; + skipped = 1; + lastScore = sorted[i].score; + } else { + ++skipped; + } + sorted[i].placement = placement; + } + return sorted.reverse(); }; export const compareScore = (a, b) => { diff --git a/resources/js/i18n/de.js b/resources/js/i18n/de.js index 79bc221..9a7bb04 100644 --- a/resources/js/i18n/de.js +++ b/resources/js/i18n/de.js @@ -109,6 +109,8 @@ export default { empty: 'Noch keine Teilnehmer eingetragen', heading: 'Teilnehmer', participant: 'Teilnehmer', + placement: 'Platzierung', + placementShort: '#', roleNames: { admin: 'Administrator', runner: 'Runner', @@ -116,6 +118,7 @@ export default { roles: 'Teilnahme als', tournament: 'Turnier', score: 'Punktzahl', + scoreShort: 'Punkte', }, protocol: { description: { diff --git a/resources/js/i18n/en.js b/resources/js/i18n/en.js index 8cf2806..9f64901 100644 --- a/resources/js/i18n/en.js +++ b/resources/js/i18n/en.js @@ -109,6 +109,8 @@ export default { empty: 'No participants on record', heading: 'Participants', participant: 'Participant', + placement: 'Placement', + placementShort: '#', roleNames: { admin: 'Administrator', runner: 'Runner', @@ -116,6 +118,7 @@ export default { roles: 'Participated as', tournament: 'Tournament', score: 'Score', + scoreShort: 'Score', }, protocol: { description: { diff --git a/resources/sass/app.scss b/resources/sass/app.scss index b19f13e..8cd0fb1 100644 --- a/resources/sass/app.scss +++ b/resources/sass/app.scss @@ -16,4 +16,5 @@ @import 'participants'; @import 'results'; @import 'rounds'; +@import 'tournaments'; @import 'users'; diff --git a/resources/sass/tournaments.scss b/resources/sass/tournaments.scss new file mode 100644 index 0000000..617125f --- /dev/null +++ b/resources/sass/tournaments.scss @@ -0,0 +1,7 @@ +.scoreboard { + .score { + &.is-self { + outline: medium double $secondary; + } + } +}
{i18n.t('participants.placementShort')} {i18n.t('participants.participant')}{i18n.t('participants.score')}{i18n.t('participants.scoreShort')}
+ {getPlacementDisplay(score)} +
@@ -35,7 +61,7 @@ const Scoreboard = ({ tournament }) => : null}
{score.score}{score.score}