-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathActivityRow.tsx
More file actions
55 lines (51 loc) · 1.74 KB
/
ActivityRow.tsx
File metadata and controls
55 lines (51 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { Activity, Room, Venue } from '@wca/helpers';
import classNames from 'classnames';
import { useMemo } from 'react';
import { Link, useParams } from 'react-router-dom';
import { Stage } from '@/extensions/org.cubingusa.natshelper.v1/types';
import { useNow } from '@/hooks/useNow';
import { activityCodeToName } from '@/lib/activityCodes';
import { formatTimeRange } from '@/lib/time';
import { RoomPill } from '../Pill';
interface ActivityRowProps {
activity: Activity;
stage?: Pick<Stage | Room, 'name' | 'color'>;
timeZone: Venue['timezone'];
showRoom?: boolean;
}
export function ActivityRow({ activity, stage, timeZone, showRoom = true }: ActivityRowProps) {
const { competitionId } = useParams();
const now = useNow();
const isOver = useMemo(
() => new Date(activity.endTime).getTime() < now.getTime(),
[activity.endTime, now],
);
const activityName = activity.activityCode.startsWith('other')
? activity.name
: activityCodeToName(activity.activityCode);
return (
<Link
key={activity.id}
className={classNames(
'flex flex-col w-full p-2 type-body even:table-bg-row-alt hover:table-bg-row-hover',
{
'opacity-50': isOver,
},
)}
to={`/competitions/${competitionId}/activities/${activity.id}`}>
<span className="type-body">{activityName}</span>
<span className="flex justify-between type-meta">
{showRoom && stage && (
<RoomPill
className="px-1 mr-2 rounded"
style={{
backgroundColor: `${stage.color}70`,
}}>
{stage.name}
</RoomPill>
)}
<span>{formatTimeRange(activity.startTime, activity.endTime, 5, timeZone)}</span>
</span>
</Link>
);
}