diff --git a/src/containers/PersonalSchedule/Assignments.tsx b/src/containers/PersonalSchedule/Assignments.tsx index da559d5..63df975 100644 --- a/src/containers/PersonalSchedule/Assignments.tsx +++ b/src/containers/PersonalSchedule/Assignments.tsx @@ -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'; @@ -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), diff --git a/src/containers/Schedule/Schedule.tsx b/src/containers/Schedule/Schedule.tsx index 2c37f38..542f95c 100644 --- a/src/containers/Schedule/Schedule.tsx +++ b/src/containers/Schedule/Schedule.tsx @@ -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`; @@ -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 (
diff --git a/src/lib/activities.test.ts b/src/lib/activities.test.ts new file mode 100644 index 0000000..48810f2 --- /dev/null +++ b/src/lib/activities.test.ts @@ -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); + }); +}); diff --git a/src/lib/activities.ts b/src/lib/activities.ts index 8fb068b..f172122 100644 --- a/src/lib/activities.ts +++ b/src/lib/activities.ts @@ -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 */