Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/containers/PersonalSchedule/Assignments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useNow } from '@/hooks/useNow/useNow';
import { parseActivityCodeFlexible } from '@/lib/activityCodes';
import { isActivityWithRoomOrParent } from '@/lib/typeguards';
import { byDate, roundTime } from '@/lib/utils';
import { getRoomData, getRooms } from '../../lib/activities';
import { getRoomData, hasMultipleScheduleLocations } from '../../lib/activities';
import { ExtraAssignment } from './PersonalExtraAssignment';
import { PersonalNormalAssignment } from './PersonalNormalAssignment';
import { getGroupedAssignmentsByDate } from './utils';
Expand All @@ -21,7 +21,7 @@ const key = (compId: string, id) => `${compId}-${id}`;
export function Assignments({ wcif, person, showStationNumber }: AssignmentsProps) {
const { t } = useTranslation();

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

const { collapsedDates, setCollapsedDates, toggleDate } = useCollapse(
key(wcif.id, person.registrantId),
Expand Down
9 changes: 7 additions & 2 deletions src/containers/Schedule/Schedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { Competition } from '@wca/helpers';
import { useCallback, useEffect, useMemo } from 'react';
import { ActivityRow } from '@/components';
import { useCollapse } from '@/hooks/UseCollapse';
import { getRoomData, getRooms, getScheduledDays, getVenueForActivity } from '@/lib/activities';
import {
getRoomData,
getScheduledDays,
getVenueForActivity,
hasMultipleScheduleLocations,
} from '@/lib/activities';
import { ActivityWithRoomOrParent } from '@/lib/types';

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

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

return (
<div>
Expand Down
81 changes: 81 additions & 0 deletions src/lib/activities.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Competition } from '@wca/helpers';
import { hasMultipleScheduleLocations } from './activities';

const baseCompetition = {
formatVersion: '1.0',
id: 'TestComp2026',
name: 'Test Comp 2026',
shortName: 'Test Comp',
events: [],
persons: [],
competitorLimit: 0,
extensions: [],
} as const;

describe('hasMultipleScheduleLocations', () => {
it('returns false for a single room without stage metadata', () => {
const wcif = {
...baseCompetition,
schedule: {
numberOfDays: 1,
startDate: '2026-03-15',
venues: [
{
id: 1,
name: 'Venue',
timezone: 'America/Los_Angeles',
rooms: [
{
id: 10,
name: 'Main Room',
color: '#123456',
activities: [],
extensions: [],
},
],
},
],
},
} as unknown as Competition;

expect(hasMultipleScheduleLocations(wcif)).toBe(false);
});

it('returns true for a single room with multiple stages in the natshelper extension', () => {
const wcif = {
...baseCompetition,
schedule: {
numberOfDays: 1,
startDate: '2026-03-15',
venues: [
{
id: 1,
name: 'Venue',
timezone: 'America/Los_Angeles',
rooms: [
{
id: 10,
name: 'Main Room',
color: '#123456',
activities: [],
extensions: [
{
id: 'org.cubingusa.natshelper.v1.Room',
data: {
stages: [
{ id: 1, name: 'Stage A', color: '#ff0000' },
{ id: 2, name: 'Stage B', color: '#00ff00' },
],
},
},
],
},
],
},
],
},
} as unknown as Competition;

expect(hasMultipleScheduleLocations(wcif)).toBe(true);
});
});
10 changes: 10 additions & 0 deletions src/lib/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ export const getRooms = (
})),
);

export const hasMultipleScheduleLocations = (wcif: Competition): boolean => {
const rooms = getRooms(wcif);

if (rooms.length > 1) {
return true;
}

return rooms.some((room) => (getNatsHelperRoomExtension(room)?.stages?.length || 0) > 1);
};

/**
* Returns the activity's child activities with a reference to the parent activity
*/
Expand Down
Loading