-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WCA Live: Podiums and Competitors Views (#10819)
* add new routes * add new controller methods * add new components * add live_urls to routes.js.erb * fix merge whoopsie * Backend cleanup * Data bindings fixes * Rename results vars in ByPerson view * Move route definition back to original place * Update app/webpacker/components/Live/ByPerson/index.jsx Co-authored-by: Kevin Matthews <[email protected]> * Destructure more heavily --------- Co-authored-by: Gregor Billing <[email protected]> Co-authored-by: Gregor Billing <[email protected]> Co-authored-by: Kevin Matthews <[email protected]>
- Loading branch information
1 parent
327985c
commit 7c579f1
Showing
11 changed files
with
225 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<% provide(:title, 'WCA Live Integration Test Page') %> | ||
|
||
<%= render layout: 'competitions/nav' do %> | ||
<%= react_component('Live/ByPerson', { allResults: @results, user: @user, competitionId: @competition_id, }) %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<% provide(:title, 'WCA Live Integration Test Page') %> | ||
|
||
<%= render layout: 'competitions/nav' do %> | ||
<%= react_component('Live/Competitors', { competitors: @competitors.as_json({ methods: [:user]}), competitionId: @competition.id, }) %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<% provide(:title, 'WCA Live Integration Test Page') %> | ||
|
||
<%= render layout: 'competitions/nav' do %> | ||
<%= react_component('Live/Podiums', { podiums: @final_rounds.as_json({ methods: [:event_id, :live_podium]}), competitors: @competitors.as_json({ methods: [:user]}), competitionId: @competition.id, }) %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import React from 'react'; | ||
import { | ||
Header, Segment, Table, | ||
} from 'semantic-ui-react'; | ||
import _ from 'lodash'; | ||
import { events } from '../../../lib/wca-data.js.erb'; | ||
import WCAQueryClientProvider from '../../../lib/providers/WCAQueryClientProvider'; | ||
import { formatAttemptResult } from '../../../lib/wca-live/attempts'; | ||
import { liveUrls } from '../../../lib/requests/routes.js.erb'; | ||
import { rankingCellStyle } from '../components/ResultsTable'; | ||
|
||
export default function Wrapper({ | ||
results, user, competitionId, | ||
}) { | ||
return ( | ||
<WCAQueryClientProvider> | ||
<PersonResults results={results} user={user} competitionId={competitionId} /> | ||
</WCAQueryClientProvider> | ||
); | ||
} | ||
|
||
function PersonResults({ | ||
results, user, competitionId, | ||
}) { | ||
const resultsByEvent = _.groupBy(results, 'event_id'); | ||
|
||
return ( | ||
<Segment> | ||
<Header> | ||
{user.name} | ||
</Header> | ||
{_.map(resultsByEvent, (eventResults, key) => ( | ||
<> | ||
<Header as="h3">{events.byId[key].name}</Header> | ||
<Table> | ||
<Table.Header> | ||
<Table.Row> | ||
<Table.HeaderCell>Round</Table.HeaderCell> | ||
<Table.HeaderCell>Rank</Table.HeaderCell> | ||
{_.times(events.byId[key].recommendedFormat().expectedSolveCount).map((num) => ( | ||
<Table.HeaderCell key={num}> | ||
{num + 1} | ||
</Table.HeaderCell> | ||
))} | ||
<Table.HeaderCell>Average</Table.HeaderCell> | ||
<Table.HeaderCell>Best</Table.HeaderCell> | ||
</Table.Row> | ||
</Table.Header> | ||
<Table.Body> | ||
{eventResults.map((result) => { | ||
const { | ||
round, | ||
attempts, | ||
ranking, | ||
average, | ||
best, | ||
} = result; | ||
|
||
return ( | ||
<Table.Row> | ||
<Table.Cell width={1}> | ||
<a href={liveUrls.roundResults(competitionId, round.id)}> | ||
Round | ||
{' '} | ||
{round.number} | ||
</a> | ||
</Table.Cell> | ||
<Table.Cell width={1} style={rankingCellStyle(result)}>{ranking}</Table.Cell> | ||
{attempts.map((a) => ( | ||
<Table.Cell> | ||
{formatAttemptResult(a.result, events.byId[key].id)} | ||
</Table.Cell> | ||
))} | ||
<Table.Cell>{formatAttemptResult(average, events.byId[key].id)}</Table.Cell> | ||
<Table.Cell>{formatAttemptResult(best, events.byId[key].id)}</Table.Cell> | ||
</Table.Row> | ||
); | ||
})} | ||
</Table.Body> | ||
</Table> | ||
</> | ||
))} | ||
</Segment> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react'; | ||
import { | ||
Input, Segment, Table, | ||
} from 'semantic-ui-react'; | ||
import WCAQueryClientProvider from '../../../lib/providers/WCAQueryClientProvider'; | ||
import { liveUrls } from '../../../lib/requests/routes.js.erb'; | ||
import useInputState from '../../../lib/hooks/useInputState'; | ||
import CountryFlag from '../../wca/CountryFlag'; | ||
|
||
export default function Wrapper({ | ||
competitionId, competitors, | ||
}) { | ||
return ( | ||
<WCAQueryClientProvider> | ||
<Competitors competitionId={competitionId} competitors={competitors} /> | ||
</WCAQueryClientProvider> | ||
); | ||
} | ||
|
||
function Competitors({ | ||
competitionId, competitors, | ||
}) { | ||
const [searchInput, setSearchInput] = useInputState(''); | ||
|
||
return ( | ||
<Segment> | ||
<Input placeholder="Search Competitor" value={searchInput} onChange={setSearchInput} icon="magnifying_glass" /> | ||
<Table basic="very" selectable> | ||
<Table.Header> | ||
<Table.HeaderCell width={1} /> | ||
<Table.HeaderCell /> | ||
</Table.Header> | ||
<Table.Body> | ||
{competitors.filter((c) => c.user.name.includes(searchInput)).map((c) => ( | ||
<Table.Row> | ||
<Table.Cell><CountryFlag iso2={c.user.country_iso2} /></Table.Cell> | ||
<Table.Cell> | ||
<a href={liveUrls.personResults(competitionId, c.id)}>{c.user.name}</a> | ||
</Table.Cell> | ||
</Table.Row> | ||
))} | ||
</Table.Body> | ||
</Table> | ||
</Segment> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react'; | ||
import { | ||
Container, | ||
Header, | ||
} from 'semantic-ui-react'; | ||
import { events } from '../../../lib/wca-data.js.erb'; | ||
import WCAQueryClientProvider from '../../../lib/providers/WCAQueryClientProvider'; | ||
import ResultsTable from '../components/ResultsTable'; | ||
|
||
export default function Wrapper({ | ||
podiums, competitionId, competitors, | ||
}) { | ||
return ( | ||
<WCAQueryClientProvider> | ||
<Podiums podiums={podiums} competitionId={competitionId} competitors={competitors} /> | ||
</WCAQueryClientProvider> | ||
); | ||
} | ||
|
||
function Podiums({ | ||
podiums, competitionId, competitors, | ||
}) { | ||
return ( | ||
<Container fluid> | ||
<Header> | ||
Podiums | ||
</Header> | ||
{podiums.map((finalRound) => ( | ||
<> | ||
<Header as="h3">{events.byId[finalRound.event_id].name}</Header> | ||
{finalRound.live_podium.length > 0 ? ( | ||
<ResultsTable | ||
results={finalRound.live_podium} | ||
competitionId={competitionId} | ||
competitors={competitors} | ||
event={events.byId[finalRound.event_id]} | ||
/> | ||
) : 'Podiums to be determined'} | ||
</> | ||
))} | ||
</Container> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters