feat: polish speaker material upload control

This commit is contained in:
Lago committed 2026-10-07 19:58:00 +02:00
1 parent 8d8d3ae4b8
commit ef0121a3e4
6 files changed
+178 -8

No files matched your search

+10
View File
@@ -10,6 +10,7 @@
"dependencies": { "dependencies": {
"@supabase/supabase-js": "^2.45.4", "@supabase/supabase-js": "^2.45.4",
"html5-qrcode": "^2.3.8", "html5-qrcode": "^2.3.8",
"lucide-react": "^1.14.0",
"qrcode.react": "^4.0.1", "qrcode.react": "^4.0.1",
"react": "^18.3.1", "react": "^18.3.1",
"react-dom": "^18.3.1" "react-dom": "^18.3.1"
@@ -1604,6 +1605,15 @@
"yallist": "^3.0.2" "yallist": "^3.0.2"
} }
}, },
"node_modules/lucide-react": {
"version": "1.14.0",
"resolved": "https://registry.npmjs.org/lucide-react/-/lucide-react-1.14.0.tgz",
"integrity": "sha512-+1mdWcfSJVUsaTIjN9zoezmUhfXo5l0vP7ekBMPo3jcS/aIkxHnXqAPsByszMZx/Y8oQBRJxJx5xg+RH3urzxA==",
"license": "ISC",
"peerDependencies": {
"react": "^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0"
}
},
"node_modules/ms": { "node_modules/ms": {
"version": "2.1.3", "version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
+1
View File
@@ -11,6 +11,7 @@
"dependencies": { "dependencies": {
"@supabase/supabase-js": "^2.45.4", "@supabase/supabase-js": "^2.45.4",
"html5-qrcode": "^2.3.8", "html5-qrcode": "^2.3.8",
"lucide-react": "^1.14.0",
"qrcode.react": "^4.0.1", "qrcode.react": "^4.0.1",
"react": "^18.3.1", "react": "^18.3.1",
"react-dom": "^18.3.1" "react-dom": "^18.3.1"
+11 -7
View File
@@ -1,5 +1,6 @@
import { useEffect, useState, type FormEvent } from 'react'; import { useEffect, useState, type FormEvent } from 'react';
import type { Session } from '@supabase/supabase-js'; import type { Session } from '@supabase/supabase-js';
import { LoaderCircle, Paperclip } from 'lucide-react';
import { supabase } from '../lib/supabase'; import { supabase } from '../lib/supabase';
import { getSpeakerPortalSessions, speakerPortalSession, type SpeakerSession } from '../lib/speakerPortal'; import { getSpeakerPortalSessions, speakerPortalSession, type SpeakerSession } from '../lib/speakerPortal';
import { removeSessionMaterial, sessionMaterialUrl, uploadSessionMaterial } from '../lib/api'; import { removeSessionMaterial, sessionMaterialUrl, uploadSessionMaterial } from '../lib/api';
@@ -110,13 +111,16 @@ export function SpeakerPortal() {
<h3 className="h2">{talk.title}</h3> <h3 className="h2">{talk.title}</h3>
<p className="small">{talk.slot_date} · {talk.start_time.slice(0, 5)} - {talk.end_time.slice(0, 5)}{talk.room && ` · ${talk.room}`}</p> <p className="small">{talk.slot_date} · {talk.start_time.slice(0, 5)} - {talk.end_time.slice(0, 5)}{talk.room && ` · ${talk.room}`}</p>
{talk.material_path ? <a className="speaker-download" href={sessionMaterialUrl(talk.material_path)} target="_blank" rel="noreferrer">Download material</a> : <p className="small muted">No material uploaded</p>} {talk.material_path ? <a className="speaker-download" href={sessionMaterialUrl(talk.material_path)} target="_blank" rel="noreferrer">Download material</a> : <p className="small muted">No material uploaded</p>}
<label className="small" htmlFor={`material-${talk.session_id}`}>{talk.material_path ? 'Replace material' : 'Upload material'}</label> <label className="speaker-upload" htmlFor={`material-${talk.session_id}`}>
<input className="input" id={`material-${talk.session_id}`} aria-label={`${talk.material_path ? 'Replace' : 'Upload'} material for ${talk.title}`} type="file" accept={FILE_TYPES} disabled={!!workingTalk || busy} onChange={(event) => { {workingTalk === talk.session_id ? <LoaderCircle aria-hidden="true" className="speaker-upload-spinner" /> : <Paperclip aria-hidden="true" />}
const file = event.target.files?.[0]; <span>{workingTalk === talk.session_id ? 'Saving material...' : talk.material_path ? 'Replace material' : 'Upload material'}</span>
event.target.value = ''; <input className="input" id={`material-${talk.session_id}`} aria-label={`${talk.material_path ? 'Replace' : 'Upload'} material for ${talk.title}`} aria-describedby={`material-help-${talk.session_id}`} type="file" accept={FILE_TYPES} disabled={!!workingTalk || busy} onChange={(event) => {
if (file) void changeMaterial(talk, file); const file = event.target.files?.[0];
}} /> event.target.value = '';
<p className="small muted">PDF, PowerPoint, ODP, ZIP, TXT · Max 50 MB</p> if (file) void changeMaterial(talk, file);
}} />
</label>
<p id={`material-help-${talk.session_id}`} className="small muted">PDF, PowerPoint, ODP, ZIP, TXT · Max 50 MB</p>
{workingTalk === talk.session_id && <><progress aria-label="Saving material" /><p role="status">Saving material...</p></>} {workingTalk === talk.session_id && <><progress aria-label="Saving material" /><p role="status">Saving material...</p></>}
{talk.material_path && <button className="btn small danger" disabled={!!workingTalk || busy} onClick={() => void changeMaterial(talk)}>Remove material</button>} {talk.material_path && <button className="btn small danger" disabled={!!workingTalk || busy} onClick={() => void changeMaterial(talk)}>Remove material</button>}
</article>)} </article>)}
+64 -1
View File
@@ -6,9 +6,72 @@
.speaker-portal p, .speaker-portal h3, .speaker-download { overflow-wrap: anywhere; } .speaker-portal p, .speaker-portal h3, .speaker-download { overflow-wrap: anywhere; }
.speaker-talk { display: grid; gap: 10px; padding: 18px 0; border-top: 1px solid var(--line); } .speaker-talk { display: grid; gap: 10px; padding: 18px 0; border-top: 1px solid var(--line); }
.speaker-portal input { width: 100%; min-width: 0; } .speaker-portal input { width: 100%; min-width: 0; }
.speaker-portal input[type="file"] { font-size: 12px; padding: 10px; }
.speaker-portal progress { width: 100%; accent-color: var(--accent-2); } .speaker-portal progress { width: 100%; accent-color: var(--accent-2); }
.speaker-download { color: var(--accent-2); } .speaker-download { color: var(--accent-2); }
.speaker-upload {
position: relative;
display: flex;
align-items: center;
gap: 8px;
min-height: 46px;
padding: 12px;
border: 1px solid var(--accent);
border-radius: 8px;
background: var(--accent-soft);
color: var(--accent);
font-size: 13px;
font-weight: 600;
cursor: pointer;
}
.speaker-upload svg {
flex-shrink: 0;
}
.speaker-upload span {
min-width: 0;
overflow-wrap: anywhere;
}
.speaker-portal .speaker-upload input[type="file"] {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
opacity: 0;
padding: 0;
cursor: pointer;
}
.speaker-upload:focus-within {
outline: 2px solid var(--accent);
outline-offset: 3px;
}
.speaker-upload:has(input:disabled) {
opacity: 0.55;
cursor: not-allowed;
}
.speaker-upload:has(input:disabled) input[type="file"] {
cursor: not-allowed;
}
.speaker-upload-spinner {
animation: speaker-upload-rotate 900ms linear infinite;
}
@keyframes speaker-upload-rotate {
to {
transform: rotate(360deg);
}
}
@media (prefers-reduced-motion: reduce) {
.speaker-upload-spinner {
animation: none;
}
}
:root { :root {
--bg: #f0f2f6; --phone-bg: #ffffff; --surface: #ffffff; --surface-2: #f4f5f9; --bg: #f0f2f6; --phone-bg: #ffffff; --surface: #ffffff; --surface-2: #f4f5f9;
--line: #e4e6ee; --text: #423c3c; --muted: #8a8484; --line: #e4e6ee; --text: #423c3c; --muted: #8a8484;
+4
View File
@@ -41,6 +41,10 @@ PowerPoint, ODP, ZIP and TXT files up to 50 MB. Controls are disabled during a
material operation; failures reload server state. Signing out is local to the material operation; failures reload server state. Signing out is local to the
browser session. browser session.
The attachment-style upload control is an independent implementation adapted
from the icon button concept by [vinodjangid07](https://uiverse.io/vinodjangid07/good-donkey-28)
(MIT); no source was copied.
Portal operations never mark attendance or award points. Visiting `/` still Portal operations never mark attendance or award points. Visiting `/` still
uses the normal app's check-in gate. See [portal API behavior](./api-client.md#speaker-portal), uses the normal app's check-in gate. See [portal API behavior](./api-client.md#speaker-portal),
[authorization](../backend/rls.md#speaker-portal-authorization) and [authorization](../backend/rls.md#speaker-portal-authorization) and
+88
View File
@@ -14,6 +14,12 @@ function mockSession(email = '[email protected]') {
return { user, access_token: `eyJhbGciOiJIUzI1NiJ9.${payload}.test-signature`, refresh_token: 'mock-refresh-token', token_type: 'bearer', expires_in: 3600 }; return { user, access_token: `eyJhbGciOiJIUzI1NiJ9.${payload}.test-signature`, refresh_token: 'mock-refresh-token', token_type: 'bearer', expires_in: 3600 };
} }
function deferred() {
let resolve!: () => void;
const promise = new Promise<void>((done) => { resolve = done; });
return { promise, resolve };
}
async function mockApi(page: Page, talks: Record<string, unknown>[] = [], email = '[email protected]') { async function mockApi(page: Page, talks: Record<string, unknown>[] = [], email = '[email protected]') {
const session = mockSession(email); const session = mockSession(email);
const calls = { users: 0, exchanges: 0, portal: 0, unexpected: [] as string[] }; const calls = { users: 0, exchanges: 0, portal: 0, unexpected: [] as string[] };
@@ -147,6 +153,88 @@ test.describe('Speaker portal', () => {
expect(removed).toHaveLength(1); expect(removed).toHaveLength(1);
}); });
test('material upload control keeps the native input accessible', async ({ page }) => {
await page.setViewportSize({ width: 390, height: 844 });
const { session } = await mockApi(page, [{ ...talk }]);
await page.goto(`${portalUrl}#access_token=${session.access_token}&refresh_token=${session.refresh_token}`);
const article = page.getByTestId(`speaker-talk-${talkId}`);
const upload = article.locator('.speaker-upload');
const input = article.getByLabel('Upload material for Past talk');
const box = await upload.boundingBox();
expect(box?.height).toBeGreaterThanOrEqual(44);
expect(box?.width).toBeGreaterThanOrEqual(44);
await expect(upload.locator('svg')).toBeVisible();
await expect(upload.getByText('Upload material', { exact: true })).toBeVisible();
await expect(input).toHaveAttribute('accept', '.pdf,.ppt,.pptx,.odp,.zip,.txt');
await expect(input).toHaveCSS('opacity', '0');
const inputBox = await input.boundingBox();
expect(inputBox?.height).toBeGreaterThanOrEqual(44);
await expect(input).toHaveAttribute('aria-describedby', `material-help-${talkId}`);
await expect(input).toHaveAccessibleDescription('PDF, PowerPoint, ODP, ZIP, TXT · Max 50 MB');
await page.keyboard.press('Tab');
await page.keyboard.press('Tab');
await expect(input).toBeFocused();
await expect.poll(() => upload.evaluate((element) => getComputedStyle(element).outlineStyle)).toBe('solid');
const fileChooser = page.waitForEvent('filechooser');
await input.press('Enter');
await (await fileChooser).setFiles([]);
await expect.poll(() => input.evaluate((entry) => (entry as HTMLInputElement).value)).toBe('');
});
test('held storage request disables file inputs, reports failure and retries the same file', async ({ page }) => {
const otherTalk = { ...talk, session_id: '55555555-5555-4555-8555-555555555555', title: 'Second talk' };
const materialTalk = { ...talk };
const { session } = await mockApi(page, [materialTalk, otherTalk]);
const uploaded: string[] = [];
const removed: string[] = [];
const firstRpc = deferred();
const releaseFirstRpc = deferred();
let attempts = 0;
await page.route('**/rest/v1/sessions?**', (route) => route.fulfill({ json: { material_path: materialTalk.material_path } }));
await page.route('**/storage/v1/object/materials/**', async (route) => {
uploaded.push(decodeURIComponent(new URL(route.request().url()).pathname.split('/object/materials/')[1]));
await route.fulfill({ json: { Key: 'uploaded' } });
});
await page.route('**/storage/v1/object/materials', async (route) => {
removed.push(...route.request().postDataJSON().prefixes);
await route.fulfill({ json: [] });
});
await page.route('**/rest/v1/rpc/set_session_material', async (route) => {
attempts++;
const body = route.request().postDataJSON();
expect(body.p_session_id).toBe(talkId);
if (attempts === 1) {
firstRpc.resolve();
await releaseFirstRpc.promise;
await route.fulfill({ status: 403, json: { message: 'Assignment removed', code: '42501' } });
return;
}
materialTalk.material_path = body.p_material_path;
await route.fulfill({ json: { material_path: materialTalk.material_path } });
});
await page.goto(`${portalUrl}#access_token=${session.access_token}&refresh_token=${session.refresh_token}`);
const article = page.getByTestId(`speaker-talk-${talkId}`);
const input = article.getByLabel('Upload material for Past talk');
const slides = { name: 'slides.txt', mimeType: 'text/plain', buffer: Buffer.from('Slides') };
await input.setInputFiles(slides);
await firstRpc.promise;
await expect(article.locator('.speaker-upload')).toContainText('Saving material...');
await expect(article.getByRole('status')).toHaveText('Saving material...');
await expect(page.locator('input[type="file"]')).toHaveCount(2);
await expect.poll(() => page.locator('input[type="file"]').evaluateAll((inputs) => inputs.every((entry) => (entry as HTMLInputElement).disabled))).toBe(true);
releaseFirstRpc.resolve();
await expect(page.getByRole('alert')).toHaveText('Assignment removed');
await expect.poll(() => page.locator('input[type="file"]').evaluateAll((inputs) => inputs.every((entry) => !(entry as HTMLInputElement).disabled))).toBe(true);
await expect(input).toBeEnabled();
expect(removed).toHaveLength(1);
await expect.poll(() => input.evaluate((entry) => (entry as HTMLInputElement).value)).toBe('');
await input.setInputFiles(slides);
await expect.poll(() => uploaded.length).toBe(2);
await expect(article.getByRole('link', { name: 'Download material' })).toBeVisible();
await expect.poll(() => article.locator('input[type="file"]').evaluate((entry) => (entry as HTMLInputElement).value)).toBe('');
expect(attempts).toBe(2);
});
test('portal authentication does not bypass the normal app check-in gate', async ({ page }) => { test('portal authentication does not bypass the normal app check-in gate', async ({ page }) => {
const { session } = await mockApi(page); const { session } = await mockApi(page);
await page.goto(`${portalUrl}#access_token=${session.access_token}&refresh_token=${session.refresh_token}`); await page.goto(`${portalUrl}#access_token=${session.access_token}&refresh_token=${session.refresh_token}`);