Skip to content

Commit

Permalink
add highlights
Browse files Browse the repository at this point in the history
  • Loading branch information
FinnIckler committed Dec 13, 2024
1 parent 956bed7 commit ab51c84
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 31 deletions.
4 changes: 4 additions & 0 deletions app/models/competition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2212,6 +2212,10 @@ def serializable_hash(options = nil)
)
end

def competitor_count
competitors.count
end

def to_ics
cal = Icalendar::Calendar.new
wcif_ids = rounds.to_h { |r| [r.wcif_id, r.to_string_map] }
Expand Down
6 changes: 4 additions & 2 deletions app/views/competitions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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?]} %>
uses_cumulative? uses_cumulative_across_rounds? uses_cutoff? uses_qualification? results_posted? competitor_count]} %>
<%= render layout: 'nav' do %>
<%= react_component("CompetitionTabs", {
tabs: @competition.tabs.as_json,
Expand All @@ -19,6 +19,8 @@
only: %w[wca_id unconfirmed_wca_id],
methods: [],
include: [],
})
}),
winners: winners(@competition, @competition.main_event),
records: records(@competition),
}) %>
<% end %>
60 changes: 33 additions & 27 deletions app/webpacker/components/CompetitionTabs/GeneralInfoTab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ const linkToGoogleMapsPlace = (latitude, longitude) => `https://www.google.com/m
export default function GeneralInfoTab({
competition,
userInfo,
records,
winners,
}) {
const [showRegistrationRequirements, setShowRegistrationRequirements] = useState(!competition['is_probably_over?']);
const [showHighlights, setShowHighlights] = useState(false);
const [showHighlights, setShowHighlights] = useState(true);

return (
<Grid>
Expand Down Expand Up @@ -243,7 +245,7 @@ export default function GeneralInfoTab({
<Grid.Column width={4} textAlign="right">
<Header as="h5">{I18n.t('competitions.nav.menu.competitors')}</Header>
</Grid.Column>
<Grid.Column width={12}>{competition.competitors.length}</Grid.Column>
<Grid.Column width={12}>{competition.competitor_count}</Grid.Column>
</Grid.Row>
)}
{(competition.media.accepted ?? []).map((mediaType) => (
Expand Down Expand Up @@ -360,32 +362,36 @@ export default function GeneralInfoTab({
</div>
</Grid.Column>
</Grid.Row>
{competition['results_posted?'] && (competition.main_event_id || records) && (
<Grid.Row>
<Grid.Column width={2} textAlign="right">
<Header as="h5">{I18n.t('competitions.competition_info.highlights')}</Header>
</Grid.Column>
<Grid.Column width={14}>
<div>
{showHighlights ? (
<>
<Button onClick={() => setShowHighlights(false)}>
{I18n.t('competitions.competition_info.hide_highlights')}
</Button>
<div>
{competition.main_event_id && <Markdown md={winners} id="competition-info-winners" /> }
<br />
{records && <Markdown md={records} id="competition-info-records" />}
</div>
</>
) : (
<Button onClick={() => setShowHighlights(true)}>
{I18n.t('competitions.competition_info.click_to_display_highlights_html', {
link_here: I18n.t('common.here'),
})}
</Button>
)}
</div>
</Grid.Column>
</Grid.Row>
)}
</Grid>

{competition.userCanViewResults && (competition.main_event_id || records) && (
<dl className="dl-horizontal">
<dt>{I18n.t('competitions.competition_info.highlights')}</dt>
<dd>
<div>
{showHighlights ? (
<>
<Button onClick={() => setShowHighlights(false)}>
{I18n.t('competitions.competition_info.hide_highlights')}
</Button>
<div>
{competition.main_event_id && <p>{winners(competition, competition.mainEvent)}</p>}
{records && <p>{records}</p>}
</div>
</>
) : (
<button onClick={() => setShowHighlights(true)}>
{I18n.t('competitions.competition_info.click_to_display_highlights_html')}
</button>
)}
</div>
</dd>
</dl>
)}
</GridColumn>
</GridRow>
</Grid>
Expand Down
15 changes: 13 additions & 2 deletions app/webpacker/components/CompetitionTabs/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,21 @@ const tabIndexFromSlug = (panes) => {
};

export default function Wrapper({
tabs, competition, wcifEvents, wcifSchedule, locale, userInfo,
tabs, competition, wcifEvents, wcifSchedule, locale, userInfo, records, winners,
}) {
const panes = useMemo(() => {
const p = [{ slug: 'general-info', menuItem: 'General Info', render: () => <GeneralInfoTab competition={competition} userInfo={userInfo} /> }];
const p = [{
slug: 'general-info',
menuItem: 'General Info',
render: () => (
<GeneralInfoTab
competition={competition}
userInfo={userInfo}
records={records}
winners={winners}
/>
),
}];
if (competition['has_rounds?']) {
p.push({
slug: 'competition-events',
Expand Down

0 comments on commit ab51c84

Please sign in to comment.