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 | 1x 30x 1x 21x 21x 21x 21x 21x 30x 21x 18x 1x 21x 2x 2x 21x 35x 35x 35x 21x 1x 1x 21x 1x 1x 21x 21x 1x 1x 1x 1x 1x 21x 21x 2x 19x 1x 2x 8x 2x 35x 34x 1x 1x 1x | /**
* SessionCards Component (Story 4.1.4)
* Displays sessions in grid/list view with filtering capabilities
* Hover to expand session description
*
* Structural sessions (moderation, break, lunch) are excluded from this view.
* Materials are shown when showMaterials=true (EVENT_COMPLETED / ARCHIVE phases).
*/
import { useState, useMemo } from 'react';
import { Button } from '@/components/public/ui/button';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/public/ui/card';
import { Badge } from '@/components/public/ui/badge';
import {
LayoutGrid,
List,
Clock,
MapPin,
Users,
FileText,
Video,
Presentation,
Download,
} from 'lucide-react';
import type { SessionUI, SessionMaterial } from '@/types/event.types';
import { format } from 'date-fns';
import { useTranslation } from 'react-i18next';
import { SessionQnaThread } from '@/components/public/Event/SessionQnaThread';
import { SpeakerDisplay } from './SpeakerDisplay';
import { eventApiClient } from '@/services/eventApiClient';
const STRUCTURAL_TYPES = new Set(['moderation', 'break', 'lunch', 'aperitif']);
const isStructuralSession = (session: SessionUI) => STRUCTURAL_TYPES.has(session.sessionType ?? '');
interface Topic {
id: string;
name: string;
color?: string;
}
interface SessionCardsProps {
sessions: SessionUI[];
topics?: Topic[];
/** Show session materials download links (true in POST_EVENT / ARCHIVE phases) */
showMaterials?: boolean;
/**
* Mount the per-session Q&A thread (Story 7.5). Decoupled from `showMaterials` so Q&A can
* appear PRE-event (SPEAKERS_PUBLISHED trigger / manual organizer open), not only post-event.
* Computed by `showSessionQna()` in homePagePhase.ts.
*/
showQna?: boolean;
/** Required when showMaterials or showQna is true — used for the download / Q&A APIs */
eventCode?: string;
}
export const SessionCards = ({
sessions,
topics = [],
showMaterials = false,
showQna = false,
eventCode,
}: SessionCardsProps) => {
const { t } = useTranslation('events');
const [viewMode, setViewMode] = useState<'grid' | 'list'>('grid');
const [selectedTopics, setSelectedTopics] = useState<string[]>([]);
const [downloadingMaterials, setDownloadingMaterials] = useState<Set<string>>(new Set());
// Exclude structural sessions (moderation, break, lunch)
const contentSessions = useMemo(
() => sessions.filter((s) => !isStructuralSession(s)),
[sessions]
);
// Filter by selected topics
const filteredSessions = useMemo(() => {
if (selectedTopics.length === 0) return contentSessions;
// Note: Session type doesn't have topicIds in current schema,
// so filtering is disabled until topics are fully integrated
return contentSessions;
}, [contentSessions, selectedTopics]);
const toggleTopic = (topicId: string) => {
setSelectedTopics((prev) =>
prev.includes(topicId) ? prev.filter((id) => id !== topicId) : [...prev, topicId]
);
};
const formatSessionTime = (
startTime: string | null | undefined,
endTime: string | null | undefined
) => {
Iif (!startTime || !endTime) return '';
try {
return `${format(new Date(startTime), 'HH:mm')} - ${format(new Date(endTime), 'HH:mm')}`;
} catch {
return '';
}
};
// Materials helpers (mirrors EventProgram)
const getMaterialTypeIcon = (type: string) => {
switch (type) {
case 'PRESENTATION':
return <Presentation className="h-4 w-4" />;
case 'VIDEO':
return <Video className="h-4 w-4" />;
default:
return <FileText className="h-4 w-4" />;
}
};
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');
default:
return t('public.program.materialTypes.other', 'Other');
}
};
const formatFileSize = (bytes: number): string => `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
const groupMaterialsByType = (materials: SessionMaterial[] | undefined) => {
Iif (!materials || materials.length === 0) return {} as Record<string, SessionMaterial[]>;
return materials.reduce(
(acc, m) => {
const type = m.materialType || 'OTHER';
acc[type] = acc[type] ? [...acc[type], m] : [m];
return acc;
},
{} as Record<string, SessionMaterial[]>
);
};
const handleMaterialDownload = async (sessionSlug: string, materialId: string) => {
if (!eventCode) return;
try {
setDownloadingMaterials((prev) => new Set(prev).add(materialId));
const downloadUrl = await eventApiClient.getMaterialDownloadUrl(
eventCode,
sessionSlug,
materialId
);
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 {
setDownloadingMaterials((prev) => {
const next = new Set(prev);
next.delete(materialId);
return next;
});
}
};
if (contentSessions.length === 0) {
return null;
}
return (
<div className="py-12" data-testid="sessions-section">
<div className="flex items-center justify-between mb-6">
<h2 className="text-3xl font-light text-zinc-100">{t('common:labels.sessions')}</h2>
<div className="flex gap-2">
<Button
variant={viewMode === 'grid' ? 'default' : 'outline'}
size="icon"
onClick={() => setViewMode('grid')}
aria-label={t('common:labels.gridView')}
className="border-zinc-800"
>
<LayoutGrid className="h-4 w-4" />
</Button>
<Button
variant={viewMode === 'list' ? 'default' : 'outline'}
size="icon"
onClick={() => setViewMode('list')}
aria-label={t('common:labels.listView')}
className="border-zinc-800"
>
<List className="h-4 w-4" />
</Button>
</div>
</div>
{/* Topic filters */}
{topics.length > 0 && (
<div className="flex flex-wrap gap-2 mb-6">
{topics.map((topic) => (
<Badge
key={topic.id}
className={`cursor-pointer transition-colors ${
selectedTopics.includes(topic.id)
? 'bg-blue-400 text-zinc-950 hover:bg-blue-500'
: 'bg-zinc-800 text-zinc-300 hover:bg-zinc-700'
}`}
onClick={() => toggleTopic(topic.id)}
>
{topic.name}
</Badge>
))}
</div>
)}
{/* Sessions grid/list */}
<div className={viewMode === 'grid' ? 'grid grid-cols-1 md:grid-cols-2 gap-6' : 'space-y-4'}>
{filteredSessions.map((session) => (
<Card
key={session.sessionSlug}
data-testid="session-card"
className="group bg-zinc-700 border-zinc-600 hover:border-zinc-500 transition-colors"
>
<CardHeader>
<div className="flex items-start justify-between gap-4">
<CardTitle
className="font-light text-xl text-zinc-100"
data-testid="session-card-title"
>
{session.title}
</CardTitle>
<Badge
variant="outline"
className="bg-blue-400/10 text-blue-400 border-blue-400/20"
>
{session.sessionType}
</Badge>
</div>
</CardHeader>
<CardContent className="space-y-4">
{session.description && (
<p className="text-sm text-zinc-400" data-testid="session-card-description">
{session.description}
</p>
)}
<div className="flex flex-wrap gap-4 text-sm text-zinc-400">
{session.startTime && session.endTime && (
<span className="flex items-center gap-1.5">
<Clock className="h-4 w-4" />
{formatSessionTime(session.startTime, session.endTime)}
</span>
)}
{session.room && (
<span className="flex items-center gap-1.5">
<MapPin className="h-4 w-4" />
{session.room}
</span>
)}
{session.capacity && (
<span className="flex items-center gap-1.5">
<Users className="h-4 w-4" />
{t('public.sessions.seats', { count: session.capacity })}
</span>
)}
</div>
<div className="pt-2 border-t border-zinc-800">
{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-2">
{session.speakers.map((speaker) => (
<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 — shown in POST_EVENT / ARCHIVE phases */}
{showMaterials && session.materials && session.materials.length > 0 && (
<div className="pt-2 border-t border-zinc-800" data-testid="session-materials">
<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}>
<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,
})}
data-testid="material-download"
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 thread. Decoupled from materials so it also shows
pre-event (SPEAKERS_PUBLISHED trigger / manual open). The component renders
nothing when no Q&A window exists for the session (404 self-gate). */}
{showQna && eventCode && (
<SessionQnaThread eventCode={eventCode} sessionSlug={session.sessionSlug} />
)}
</CardContent>
</Card>
))}
</div>
{filteredSessions.length === 0 && selectedTopics.length > 0 && (
<div className="text-center py-12">
<p className="text-zinc-400">{t('public.sessions.noSessions')}</p>
<Button
variant="outline"
onClick={() => setSelectedTopics([])}
className="mt-4 border-zinc-800"
>
{t('public.sessions.clearFilters')}
</Button>
</div>
)}
</div>
);
};
|