Skip to content

Commit

Permalink
add Winners table
Browse files Browse the repository at this point in the history
  • Loading branch information
FinnIckler committed Dec 16, 2024
1 parent eae6e3d commit fb1d4b4
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 3 deletions.
5 changes: 3 additions & 2 deletions app/views/competitions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
media number_of_bookmarks date_range information on_the_spot_registration? on_the_spot_entry_fee_lowest_denomination
guests_per_registration_limit_enabled? guests_per_registration_limit uses_qualification? allow_registration_without_qualification
events_per_registration_limit_enabled? events_per_registration_limit guests_entry_fee_lowest_denomination all_guests_allowed?
uses_cumulative? uses_cumulative_across_rounds? uses_cutoff? uses_qualification? results_posted? competitor_count]} %>
uses_cumulative? uses_cumulative_across_rounds? uses_cutoff? uses_qualification? results_posted? competitor_count winning_results]} %>
<%= render layout: 'nav' do %>
<%= react_component("CompetitionTabs", {
tabs: @competition.tabs.as_json,
competition: @competition.as_json(options),
wcifEvents: @competition.events_wcif, wcifSchedule: @competition.schedule_wcif, locale: I18n.locale,
wcifEvents: @competition.events_wcif,
wcifSchedule: @competition.schedule_wcif, locale: I18n.locale,
userInfo: current_user.as_json({
only: %w[wca_id unconfirmed_wca_id],
methods: [],
Expand Down
12 changes: 11 additions & 1 deletion app/webpacker/components/CompetitionTabs/GeneralInfoTab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import React, { useState } from 'react';

import {
Accordion,
Button, Grid, GridColumn, GridRow, Header, Icon, List,
Button, Grid, GridColumn, GridRow, Header, Icon, List, Table,
} from 'semantic-ui-react';
import { DateTime } from 'luxon';
import _ from 'lodash';
import I18n from '../../lib/i18n';
import { countries } from '../../lib/wca-data.js.erb';
import { competitionUrl, personUrl } from '../../lib/requests/routes.js.erb';
Expand All @@ -13,6 +14,7 @@ import Markdown from '../Markdown';
import RegistrationRequirements from './Requirements';
import I18nHTMLTranslate from '../I18nHTMLTranslate';
import { getFullDateTimeString } from '../../lib/utils/dates';
import WinnerTable from './WinnerTable';

const linkToGoogleMapsPlace = (latitude, longitude) => `https://www.google.com/maps/place/${latitude},${longitude}`;

Expand Down Expand Up @@ -410,6 +412,14 @@ export default function GeneralInfoTab({
</Grid>
</GridColumn>
</GridRow>
{ competition['results_posted?']
&& (
<Grid.Row>
<GridColumn width={16}>
<WinnerTable results={competition.winning_results} competition={competition} />
</GridColumn>
</Grid.Row>
)}
</Grid>
);
}
81 changes: 81 additions & 0 deletions app/webpacker/components/CompetitionTabs/WinnerTable.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import React from 'react';
import { Segment, Table } from 'semantic-ui-react';
import _ from 'lodash';
import { countries, events } from '../../lib/wca-data.js.erb';
import I18n from '../../lib/i18n';
import { formatAttemptResult } from '../../lib/wca-live/attempts';
import { competitionAllResultsUrl, personUrl } from '../../lib/requests/routes.js.erb';
import EventIcon from '../wca/EventIcon';

export default function WinnerTable({ results, competition }) {
return (
<Segment style={{ overflowX: 'scroll' }}>
<Table striped compact="very" singleLine unstackable basic>
<Table.Header>
<Table.Row>
<Table.HeaderCell>
{I18n.t('competitions.results_table.event')}
</Table.HeaderCell>
<Table.HeaderCell>
{I18n.t('competitions.results_table.name')}
</Table.HeaderCell>
<Table.HeaderCell textAlign="right">
{I18n.t('common.best')}
</Table.HeaderCell>
<Table.HeaderCell />
<Table.HeaderCell textAlign="right">
{I18n.t('common.average')}
</Table.HeaderCell>
<Table.HeaderCell />
<Table.HeaderCell>
{I18n.t('common.user.representing')}
</Table.HeaderCell>
<Table.HeaderCell>
{I18n.t('common.solves')}
</Table.HeaderCell>
<Table.HeaderCell />
<Table.HeaderCell />
<Table.HeaderCell />
<Table.HeaderCell />
</Table.Row>
</Table.Header>
<Table.Body>
{results.map((r) => {
const attempts = [r.value1, r.value2, r.value3, r.value4, r.value5];
const bestResult = _.max(attempts);
const worstResult = _.min(attempts);
const bestResultIndex = attempts.findIndex((a) => a === bestResult);
const worstResultIndex = attempts.findIndex((a) => a === worstResult);
return (
<Table.Row>
<Table.Cell>
<a href={competitionAllResultsUrl(competition.id, r.event.id)}>
{' '}
<EventIcon id={r.event.id} />
{' '}
{events.byId[r.event.id].name}
</a>
</Table.Cell>
<Table.Cell>
<a href={personUrl(r.personId)}>{r.personName}</a>
</Table.Cell>
<Table.Cell textAlign="right">{formatAttemptResult(r.best, r.event.id)}</Table.Cell>
<Table.Cell>{r.regionalSingleRecord}</Table.Cell>
<Table.Cell textAlign="right">{formatAttemptResult(r.average, r.event.id)}</Table.Cell>
<Table.Cell>{r.regionalAverageRecord}</Table.Cell>
<Table.Cell>{countries.byIso2[r.country.iso2].name}</Table.Cell>
{attempts.map((a, i) => (
<Table.Cell>
{ r.format.expected_solve_count === 5
&& (i === bestResultIndex || i === worstResultIndex)
? `(${formatAttemptResult(a, r.event.id)})` : formatAttemptResult(a, r.event.id)}
</Table.Cell>
))}
</Table.Row>
);
})}
</Table.Body>
</Table>
</Segment>
);
}

0 comments on commit fb1d4b4

Please sign in to comment.