Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | 1x 47x 1x 10x 10x 1x 18x 18x 18x 15x 5x 5x 5x 18x 15x 15x 18x 15x 5x 5x 5x 18x 5x 5x 15x 15x 15x 15x 15x 18x 18x 18x 18x 47x 47x 47x 47x 47x 18x 27x 10x 18x 10x 10x 10x 10x 10x 18x 1x 17x 27x 47x 26x 15x 15x 15x | /**
* EventProgram Component (Story 4.1.4)
* Vertical timeline showing session schedule grouped by time slots
* Story 5.9 - Task 8b: Added materials display for archived events
*/
import type { SessionUI, SessionMaterial, SessionSpeaker } from '@/types/event.types';
import { format } from 'date-fns';
import {
Clock,
MapPin,
FileText,
Video,
Presentation,
Download,
Coffee,
UtensilsCrossed,
Mic2,
Wine,
} from 'lucide-react';
import { useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { SpeakerDisplay } from './SpeakerDisplay';
import { SessionQnaThread } from './SessionQnaThread';
import { eventApiClient } from '@/services/eventApiClient';
const STRUCTURAL_TYPES = new Set(['moderation', 'break', 'lunch', 'aperitif']);
const isStructuralSession = (session: SessionUI) => STRUCTURAL_TYPES.has(session.sessionType ?? '');
const StructuralIcon = ({ sessionType }: { sessionType: string | null | undefined }) => {
switch (sessionType) {
case 'break':
return <Coffee className="h-5 w-5 text-zinc-500" />;
case 'lunch':
return <UtensilsCrossed className="h-5 w-5 text-zinc-500" />;
case 'aperitif':
return <Wine className="h-5 w-5 text-zinc-500" />;
default:
return <Mic2 className="h-5 w-5 text-zinc-500" />;
}
};
interface EventProgramProps {
sessions: SessionUI[];
isArchived?: boolean; // Story 5.9 - Show materials only for archived events
eventCode: string; // Story 5.9 - Required for material download API
/**
* Mount the per-session Q&A thread on each timeline card (Story 7.5). Same gate as SessionCards
* — the timeline (EventProgram) is what renders in the AGENDA phase, so without this the Q&A
* would be invisible once the agenda is published. SessionQnaThread self-gates on the 404.
*/
showQna?: boolean;
}
export const EventProgram = ({
sessions,
isArchived = false,
eventCode,
showQna = false,
}: EventProgramProps) => {
const { t } = useTranslation('events');
const [downloadingMaterials, setDownloadingMaterials] = useState<Set<string>>(new Set());
// Helper: Get type label for display (Story 5.9 - Task 8b)
const getMaterialTypeLabel = (type: string): string => {
switch (type) {
case 'PRESENTATION':
return t('public.program.materialTypes.presentation', 'Presentation');
case 'DOCUMENT':
return t('public.program.materialTypes.document', 'Document');
case 'VIDEO':
return t('public.program.materialTypes.video', 'Video');
case 'OTHER':
default:
return t('public.program.materialTypes.other', 'Other');
}
};
// Helper: Format file size in MB (Story 5.9 - Task 8b)
const formatFileSize = (bytes: number): string => {
const mb = bytes / (1024 * 1024);
return `${mb.toFixed(1)} MB`;
};
// Helper: Get material type icon (Story 5.9 - Task 8b)
const getMaterialTypeIcon = (type: string) => {
switch (type) {
case 'PRESENTATION':
return <Presentation className="h-4 w-4" />;
case 'VIDEO':
return <Video className="h-4 w-4" />;
case 'DOCUMENT':
case 'OTHER':
default:
return <FileText className="h-4 w-4" />;
}
};
// Helper: Group materials by type (Story 5.9 - Task 8b)
const groupMaterialsByType = (materials: SessionMaterial[] | undefined) => {
Iif (!materials || materials.length === 0) return {};
return materials.reduce(
(acc, material) => {
const type = material.materialType || 'OTHER';
Eif (!acc[type]) {
acc[type] = [];
}
acc[type].push(material);
return acc;
},
{} as Record<string, SessionMaterial[]>
);
};
/**
* Handle material download (Story 5.9 - Fix AccessDenied error)
* Fetches presigned download URL from backend instead of using cloudFrontUrl directly
*/
const handleMaterialDownload = async (sessionSlug: string, materialId: string) => {
try {
// Mark material as downloading
setDownloadingMaterials((prev) => new Set(prev).add(materialId));
// Fetch presigned URL from backend
const downloadUrl = await eventApiClient.getMaterialDownloadUrl(
eventCode,
sessionSlug,
materialId
);
// Trigger download by opening presigned URL in new tab
window.open(downloadUrl, '_blank');
} catch (error) {
console.error('Failed to download material:', error);
alert(t('errors.materialDownloadFailed', 'Failed to download material. Please try again.'));
} finally {
// Clear downloading state
setDownloadingMaterials((prev) => {
const next = new Set(prev);
next.delete(materialId);
return next;
});
}
};
// Group sessions by start time
const timeSlots = useMemo(() => {
const slotMap = new Map<string, SessionUI[]>();
sessions.forEach((session) => {
try {
Iif (!session.startTime) {
console.warn('Session missing start time:', session.sessionSlug);
return;
}
const timeKey = format(new Date(session.startTime), 'HH:mm');
const existing = slotMap.get(timeKey) || [];
slotMap.set(timeKey, [...existing, session]);
} catch (error) {
console.warn('Invalid session time:', session.sessionSlug, error);
}
});
// Convert map to sorted array
return Array.from(slotMap.entries())
.map(([time, sessions]) => ({ time, sessions }))
.sort((a, b) => a.time.localeCompare(b.time));
}, [sessions]);
const formatSessionDuration = (
startTime: string | null | undefined,
endTime: string | null | undefined
): string => {
Iif (!startTime || !endTime) {
return ''; // Session not yet assigned to time slot
}
try {
const start = new Date(startTime);
const end = new Date(endTime);
return `${format(start, 'HH:mm')} - ${format(end, 'HH:mm')}`;
} catch {
return '';
}
};
if (sessions.length === 0) {
return null;
}
return (
<div className="py-12">
<h2 className="text-3xl font-light mb-8 text-zinc-100">{t('public.program.title')}</h2>
<div className="relative">
{/* Vertical timeline line */}
<div className="absolute left-[31px] top-0 bottom-0 w-px bg-zinc-800" />
{/* Timeline items */}
<div className="space-y-8">
{timeSlots.map((slot, slotIndex) => (
<div key={slot.time} className="relative">
{/* Time indicator */}
<div className="flex items-start gap-6">
<div className="flex items-center justify-center w-16 h-16 rounded-full bg-zinc-900 border-2 border-blue-400 flex-shrink-0 relative z-10">
<span className="text-sm font-medium text-blue-400">{slot.time}</span>
</div>
{/* Sessions at this time */}
<div className="flex-1 pt-2 space-y-4">
{slot.sessions.map((session) =>
isStructuralSession(session) ? (
/* Structural session — compact icon strip */
<div
key={session.sessionSlug}
className="flex items-center gap-4 px-5 py-3 rounded-lg bg-zinc-800/30 border border-zinc-700/40 text-zinc-500"
>
<StructuralIcon sessionType={session.sessionType} />
<span className="font-medium text-zinc-400 flex-1">{session.title}</span>
<span className="flex items-center gap-1.5 text-sm shrink-0">
<Clock className="h-4 w-4" />
{formatSessionDuration(session.startTime, session.endTime)}
</span>
</div>
) : (
<div
key={session.sessionSlug}
className="bg-zinc-700 border border-zinc-600 rounded-lg p-6 hover:border-zinc-500 transition-colors"
>
<div className="flex items-start justify-between gap-4 mb-3">
<h3 className="text-xl font-light text-zinc-100">{session.title}</h3>
<span className="text-xs px-2 py-1 rounded bg-blue-400/10 text-blue-400 border border-blue-400/20 whitespace-nowrap">
{session.sessionType}
</span>
</div>
{session.description && (
<p className="text-sm text-zinc-300 mb-4">{session.description}</p>
)}
{/* In-card session start/end time intentionally omitted on the public
timeline — the time circle at the left of the row already shows it,
and individual slot times are not advertised to attendees. */}
{session.room && (
<div className="flex flex-wrap gap-4 text-sm text-zinc-300">
<span className="flex items-center gap-1.5">
<MapPin className="h-4 w-4" />
{session.room}
</span>
</div>
)}
<div className="mt-4 pt-4 border-t border-zinc-600">
{session.speakers && session.speakers.length > 0 ? (
<div>
<p className="text-xs text-zinc-500 mb-2">
{t('common:role.speaker')}:
</p>
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
{session.speakers.map((speaker: SessionSpeaker) => (
<SpeakerDisplay
key={speaker.username}
speaker={speaker}
size="small"
showProfilePicture={true}
/>
))}
</div>
</div>
) : (
<p className="text-sm text-zinc-400">
{t('public.speakers.speakerTBA')}
</p>
)}
</div>
{/* Materials Section - Only for archived events (Story 5.9 - Task 8b) */}
{isArchived && session.materials && session.materials.length > 0 && (
<div className="mt-4 pt-4 border-t border-zinc-600">
<p className="text-xs text-zinc-500 mb-3">
{t('public.program.materials', 'Materials')}:
</p>
<div className="space-y-4">
{Object.entries(groupMaterialsByType(session.materials)).map(
([type, materials]) => (
<div key={type}>
{/* Material Type Heading */}
<p className="text-xs font-medium text-zinc-400 mb-2 capitalize">
{getMaterialTypeLabel(type)}
</p>
<div className="space-y-2">
{materials.map((material) => {
const isDownloading = downloadingMaterials.has(material.id);
return (
<button
key={material.id}
onClick={() =>
handleMaterialDownload(
session.sessionSlug,
material.id
)
}
disabled={isDownloading}
aria-label={t('materials.downloadAriaLabel', {
fileName: material.fileName,
})}
className="flex items-center gap-2 p-2 rounded bg-zinc-800/50 hover:bg-zinc-800 transition-colors text-sm text-zinc-300 hover:text-blue-400 no-underline w-full text-left disabled:opacity-50 disabled:cursor-not-allowed"
>
{getMaterialTypeIcon(material.materialType)}
<span className="flex-1">{material.fileName}</span>
<span className="text-xs text-zinc-500">
{formatFileSize(material.fileSize)}
</span>
{isDownloading ? (
<span className="h-4 w-4 animate-spin">⏳</span>
) : (
<Download className="h-4 w-4" />
)}
</button>
);
})}
</div>
</div>
)
)}
</div>
</div>
)}
{/* Story 7.5: per-session Q&A on the timeline card (the timeline is what
renders in the AGENDA phase). Collapsed by default; renders nothing when
no Q&A window exists for the session (404 self-gate). */}
{showQna && eventCode && (
<div className="mt-4">
<SessionQnaThread
eventCode={eventCode}
sessionSlug={session.sessionSlug}
/>
</div>
)}
</div>
)
)}
</div>
</div>
{/* Connecting line between slots (except last) */}
{slotIndex < timeSlots.length - 1 && (
<div className="absolute left-[31px] top-16 w-px h-8 bg-zinc-800" />
)}
</div>
))}
</div>
</div>
</div>
);
};
|