diff --git a/apps/convivo/package-lock.json b/apps/convivo/package-lock.json index 805bcb0..0f1b70a 100644 --- a/apps/convivo/package-lock.json +++ b/apps/convivo/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@supabase/supabase-js": "^2.45.4", "html5-qrcode": "^2.3.8", + "lucide-react": "^1.14.0", "qrcode.react": "^4.0.1", "react": "^18.3.1", "react-dom": "^18.3.1" @@ -1604,6 +1605,15 @@ "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": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", diff --git a/apps/convivo/package.json b/apps/convivo/package.json index 006c837..07ca468 100644 --- a/apps/convivo/package.json +++ b/apps/convivo/package.json @@ -11,6 +11,7 @@ "dependencies": { "@supabase/supabase-js": "^2.45.4", "html5-qrcode": "^2.3.8", + "lucide-react": "^1.14.0", "qrcode.react": "^4.0.1", "react": "^18.3.1", "react-dom": "^18.3.1" diff --git a/apps/convivo/src/screens/SpeakerPortal.tsx b/apps/convivo/src/screens/SpeakerPortal.tsx index 5bedaf2..429f2ed 100644 --- a/apps/convivo/src/screens/SpeakerPortal.tsx +++ b/apps/convivo/src/screens/SpeakerPortal.tsx @@ -1,5 +1,6 @@ import { useEffect, useState, type FormEvent } from 'react'; import type { Session } from '@supabase/supabase-js'; +import { LoaderCircle, Paperclip } from 'lucide-react'; import { supabase } from '../lib/supabase'; import { getSpeakerPortalSessions, speakerPortalSession, type SpeakerSession } from '../lib/speakerPortal'; import { removeSessionMaterial, sessionMaterialUrl, uploadSessionMaterial } from '../lib/api'; @@ -110,13 +111,16 @@ export function SpeakerPortal() {

{talk.title}

{talk.slot_date} · {talk.start_time.slice(0, 5)} - {talk.end_time.slice(0, 5)}{talk.room && ` · ${talk.room}`}

{talk.material_path ? Download material :

No material uploaded

} - - { - const file = event.target.files?.[0]; - event.target.value = ''; - if (file) void changeMaterial(talk, file); - }} /> -

PDF, PowerPoint, ODP, ZIP, TXT · Max 50 MB

+ +

PDF, PowerPoint, ODP, ZIP, TXT · Max 50 MB

{workingTalk === talk.session_id && <>

Saving material...

} {talk.material_path && } )} @@ -126,4 +130,4 @@ export function SpeakerPortal() { } ; -} \ No newline at end of file +} diff --git a/apps/convivo/src/styles.css b/apps/convivo/src/styles.css index 95685bf..62dbee0 100644 --- a/apps/convivo/src/styles.css +++ b/apps/convivo/src/styles.css @@ -6,9 +6,72 @@ .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-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-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 { --bg: #f0f2f6; --phone-bg: #ffffff; --surface: #ffffff; --surface-2: #f4f5f9; --line: #e4e6ee; --text: #423c3c; --muted: #8a8484; diff --git a/docs/frontend/screens.md b/docs/frontend/screens.md index 9c22fd6..8838382 100644 --- a/docs/frontend/screens.md +++ b/docs/frontend/screens.md @@ -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 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 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 diff --git a/e2e/tests/speaker-portal.spec.ts b/e2e/tests/speaker-portal.spec.ts index fa20d96..7f16a3b 100644 --- a/e2e/tests/speaker-portal.spec.ts +++ b/e2e/tests/speaker-portal.spec.ts @@ -14,6 +14,12 @@ function mockSession(email = 'speaker@example.org') { 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((done) => { resolve = done; }); + return { promise, resolve }; +} + async function mockApi(page: Page, talks: Record[] = [], email = 'speaker@example.org') { const session = mockSession(email); const calls = { users: 0, exchanges: 0, portal: 0, unexpected: [] as string[] }; @@ -147,6 +153,88 @@ test.describe('Speaker portal', () => { 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 }) => { const { session } = await mockApi(page); await page.goto(`${portalUrl}#access_token=${session.access_token}&refresh_token=${session.refresh_token}`); @@ -232,4 +320,4 @@ test.describe('Speaker portal', () => { expect(await page.evaluate(() => Object.keys(localStorage).filter((key) => key.endsWith('-auth-token')))).toEqual([]); }); } -}); \ No newline at end of file +});