Skip to content

Commit 474e75f

Browse files
committed
fix: show stages for single-room competitions
1 parent 0497f9e commit 474e75f

4 files changed

Lines changed: 100 additions & 4 deletions

File tree

‎src/containers/PersonalSchedule/Assignments.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useNow } from '@/hooks/useNow/useNow';
66
import { parseActivityCodeFlexible } from '@/lib/activityCodes';
77
import { isActivityWithRoomOrParent } from '@/lib/typeguards';
88
import { byDate, roundTime } from '@/lib/utils';
9-
import { getRoomData, getRooms } from '../../lib/activities';
9+
import { getRoomData, hasMultipleScheduleLocations } from '../../lib/activities';
1010
import { ExtraAssignment } from './PersonalExtraAssignment';
1111
import { PersonalNormalAssignment } from './PersonalNormalAssignment';
1212
import { getGroupedAssignmentsByDate } from './utils';
@@ -21,7 +21,7 @@ const key = (compId: string, id) => `${compId}-${id}`;
2121
export function Assignments({ wcif, person, showStationNumber }: AssignmentsProps) {
2222
const { t } = useTranslation();
2323

24-
const showRoom = useMemo(() => wcif && getRooms(wcif).length > 1, [wcif]);
24+
const showRoom = useMemo(() => hasMultipleScheduleLocations(wcif), [wcif]);
2525

2626
const { collapsedDates, setCollapsedDates, toggleDate } = useCollapse(
2727
key(wcif.id, person.registrantId),

‎src/containers/Schedule/Schedule.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { Competition } from '@wca/helpers';
22
import { useCallback, useEffect, useMemo } from 'react';
33
import { ActivityRow } from '@/components';
44
import { useCollapse } from '@/hooks/UseCollapse';
5-
import { getRoomData, getRooms, getScheduledDays, getVenueForActivity } from '@/lib/activities';
5+
import {
6+
getRoomData,
7+
getScheduledDays,
8+
getVenueForActivity,
9+
hasMultipleScheduleLocations,
10+
} from '@/lib/activities';
611
import { ActivityWithRoomOrParent } from '@/lib/types';
712

813
const key = (compId: string) => `${compId}-schedule`;
@@ -85,7 +90,7 @@ export const ScheduleContainer = ({ wcif }: ScheduleContainerProps) => {
8590
// eslint-disable-next-line react-hooks/exhaustive-deps
8691
}, [scheduleDays]);
8792

88-
const showRoom = useMemo(() => wcif && getRooms(wcif).length > 1, [wcif]);
93+
const showRoom = useMemo(() => hasMultipleScheduleLocations(wcif), [wcif]);
8994

9095
return (
9196
<div>

‎src/lib/activities.test.ts‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { Competition } from '@wca/helpers';
2+
import { hasMultipleScheduleLocations } from './activities';
3+
4+
const baseCompetition = {
5+
formatVersion: '1.0',
6+
id: 'TestComp2026',
7+
name: 'Test Comp 2026',
8+
shortName: 'Test Comp',
9+
events: [],
10+
persons: [],
11+
competitorLimit: 0,
12+
extensions: [],
13+
} as const;
14+
15+
describe('hasMultipleScheduleLocations', () => {
16+
it('returns false for a single room without stage metadata', () => {
17+
const wcif = {
18+
...baseCompetition,
19+
schedule: {
20+
numberOfDays: 1,
21+
startDate: '2026-03-15',
22+
venues: [
23+
{
24+
id: 1,
25+
name: 'Venue',
26+
timezone: 'America/Los_Angeles',
27+
rooms: [
28+
{
29+
id: 10,
30+
name: 'Main Room',
31+
color: '#123456',
32+
activities: [],
33+
extensions: [],
34+
},
35+
],
36+
},
37+
],
38+
},
39+
} as unknown as Competition;
40+
41+
expect(hasMultipleScheduleLocations(wcif)).toBe(false);
42+
});
43+
44+
it('returns true for a single room with multiple stages in the natshelper extension', () => {
45+
const wcif = {
46+
...baseCompetition,
47+
schedule: {
48+
numberOfDays: 1,
49+
startDate: '2026-03-15',
50+
venues: [
51+
{
52+
id: 1,
53+
name: 'Venue',
54+
timezone: 'America/Los_Angeles',
55+
rooms: [
56+
{
57+
id: 10,
58+
name: 'Main Room',
59+
color: '#123456',
60+
activities: [],
61+
extensions: [
62+
{
63+
id: 'org.cubingusa.natshelper.v1.Room',
64+
data: {
65+
stages: [
66+
{ id: 1, name: 'Stage A', color: '#ff0000' },
67+
{ id: 2, name: 'Stage B', color: '#00ff00' },
68+
],
69+
},
70+
},
71+
],
72+
},
73+
],
74+
},
75+
],
76+
},
77+
} as unknown as Competition;
78+
79+
expect(hasMultipleScheduleLocations(wcif)).toBe(true);
80+
});
81+
});

‎src/lib/activities.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ export const getRooms = (
3131
})),
3232
);
3333

34+
export const hasMultipleScheduleLocations = (wcif: Competition): boolean => {
35+
const rooms = getRooms(wcif);
36+
37+
if (rooms.length > 1) {
38+
return true;
39+
}
40+
41+
return rooms.some((room) => (getNatsHelperRoomExtension(room)?.stages?.length || 0) > 1);
42+
};
43+
3444
/**
3545
* Returns the activity's child activities with a reference to the parent activity
3646
*/

0 commit comments

Comments
 (0)