diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 081be68..2e3ff0b 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -193,7 +193,7 @@ Cloud Run service "allaboard" ── one container :3000 (node server.ts, Build grid and moderation. **If you add a delta event, send it to `boardAudience` *and* call `noteChange`.** - **Students only hold their own board's ink.** `init` and `breakout-sync` are built per socket (`subBoardsFor`): teachers get every board; students get every board's metadata, background and chat, but `elements: []` except on - their own board (`placeSocket` sends the real contents when they move). So a student's Save .JSON contains only their + their own board (`placeSocket` sends the real contents when they move). So a student's Save class work contains only their own board's ink, and a teacher's copy of boards they aren't viewing is ≤ 1.5 s old. (`room-restored` after an import is still full, room-wide.) - **Ink pacing (client).** `element-append-points` is queued and sent every 500 ms (`POINT_FLUSH_MS`); any other drawing emit goes through diff --git a/e2e/classroom.spec.ts b/e2e/classroom.spec.ts index afb8432..f148382 100644 --- a/e2e/classroom.spec.ts +++ b/e2e/classroom.spec.ts @@ -476,7 +476,7 @@ test.describe('teacher and students', () => { const strokeOf = async (page: Page) => { const download = page.waitForEvent('download'); - await page.getByRole('button', { name: 'Save .JSON' }).click(); + await page.getByRole('button', { name: 'Save class work' }).click(); const file = await (await download).path(); const snapshot = JSON.parse((await import('node:fs')).readFileSync(file!, 'utf8')); return snapshot.elements[0].points as number[]; @@ -847,6 +847,48 @@ test.describe('room exists confirmation modal', () => { await visitor.context.close(); await invitee.context.close(); }); + + test('lobby New Room makes the typed room (or a random one) and goes in, but warns when it already exists', async ({ browser }) => { + const freshRoom = uniqueRoom('newroom'); + const maker = await newUser(browser); + const randomMaker = await newUser(browser); + const latecomer = await newUser(browser); + + // No name yet: New Room says so and stays in the lobby. + await maker.page.goto('/'); + await maker.page.getByLabel('Room Code').fill(freshRoom); + await maker.page.getByRole('button', { name: 'New Room' }).click(); + await expect(maker.page.getByText('Type your name first, then press New Room.')).toBeVisible(); + await expect(maker.page.getByLabel('Room Code')).toHaveValue(freshRoom); + + // With a name: New Room makes that room and goes straight in. + await maker.page.getByLabel('Your Display Name').fill('Ms. Maker'); + await maker.page.getByRole('button', { name: 'New Room' }).click(); + await expect(maker.page.getByRole('dialog')).toHaveCount(0); + await expect(maker.page.locator('.konvajs-content').first()).toBeVisible(); + await expect(maker.page).toHaveURL(new RegExp(`room=${freshRoom}`)); + + // An empty box makes a random room. + await randomMaker.page.goto('/'); + await randomMaker.page.getByLabel('Your Display Name').fill('Mr. Random'); + await randomMaker.page.getByLabel('Room Code').fill(''); + await randomMaker.page.getByRole('button', { name: 'New Room' }).click(); + await expect(randomMaker.page.locator('.konvajs-content').first()).toBeVisible(); + await expect(randomMaker.page).toHaveURL(/room=class-/); + + // A code that's already in use gets the "already exists" choice instead of a silent join. + await latecomer.page.goto('/'); + await latecomer.page.getByLabel('Your Display Name').fill('Sam'); + await latecomer.page.getByLabel('Room Code').fill(freshRoom); + await latecomer.page.getByRole('button', { name: 'New Room' }).click(); + const dialog = latecomer.page.getByRole('dialog'); + await expect(dialog.getByText('Room Already Exists')).toBeVisible(); + await dialog.getByRole('button', { name: 'Cancel', exact: true }).click(); + await expect(dialog).toHaveCount(0); + await expect(latecomer.page.getByRole('button', { name: 'Join Classroom' })).toBeVisible(); + + for (const u of [maker, randomMaker, latecomer]) await u.context.close(); + }); }); test.describe('kick or ban contribution purge modal', () => { diff --git a/e2e/googleDrive.spec.ts b/e2e/googleDrive.spec.ts index fc99765..02149f5 100644 --- a/e2e/googleDrive.spec.ts +++ b/e2e/googleDrive.spec.ts @@ -494,7 +494,7 @@ test.describe('Google Drive integration (stubbed Google)', () => { await joinRoom(page, uniqueRoom('gd-open'), 'Ms T', '4829'); await page.getByRole('button', { name: 'Open Room from Drive' }).click(); - await expect(page.getByText('Restore Room Snapshot (.JSON)')).toBeVisible(); + await expect(page.getByText('Open Class Work (.json)')).toBeVisible(); await expect(page.getByText('saved-room.json')).toBeVisible(); await expect(page.getByText('#prev-room')).toBeVisible(); await expect(page.getByText('1 items')).toBeVisible(); @@ -592,6 +592,36 @@ test.describe('Google Drive integration (stubbed Google)', () => { expect(requests[2].url).toContain('/files/drive-file-42?uploadType=resumable'); }); + test('lessons save to Drive as their own type, and the lesson picker lists only those first', async ({ page }) => { + await installFakeGoogle(page, { pickerAction: 'cancel' }); + const requests = await fakeDriveUploads(page); + await joinRoom(page, uniqueRoom('gd-lesson'), 'Ms T', '4829'); + + await page.getByRole('button', { name: 'Save lesson…' }).click(); + const save = page.getByTestId('save-lesson-modal'); + await save.getByLabel('Lesson title').fill('Fractions'); + await save.getByRole('button', { name: 'Save to Drive' }).click(); + await expect(save.getByText(/Saved fractions-.*\.allaboard to My Drive/)).toBeVisible(); + expect(requests[0].method).toBe('POST'); + expect(requests[0].meta).toEqual({ + name: expect.stringMatching(/^fractions-\d{4}-\d{2}-\d{2}\.allaboard$/), + mimeType: 'application/vnd.allaboard.lesson+json', + }); + await save.getByRole('button', { name: 'Close', exact: true }).click(); + + // A room save (application/json) is never in "My lessons"; Browse Drive still finds older lessons saved as JSON. + await page.getByRole('button', { name: 'Load lesson…' }).click(); + await page.getByTestId('load-lesson-modal').getByRole('button', { name: 'Open from Drive' }).click(); + await expect.poll(async () => (await pickerLog(page)).length).toBe(1); + const [log] = await pickerLog(page); + expect(log.views.map((v) => v.calls.setLabel?.[0])).toEqual(['My lessons', 'Browse Drive']); + expect(log.views[0].calls.setMimeTypes).toEqual(['application/vnd.allaboard.lesson+json']); + expect(log.views[0].calls.setOwnedByMe).toEqual([true]); + expect(log.views[1].calls.setMimeTypes).toEqual([ + 'application/vnd.allaboard.lesson+json,application/json,application/octet-stream', + ]); + }); + test('Save Room to Drive saves a renamed file into a chosen folder, and remembers that folder', async ({ page }) => { await installFakeGoogle(page); const requests = await fakeDriveUploads(page); diff --git a/e2e/worksheets.spec.ts b/e2e/worksheets.spec.ts index c6d64d3..13d5178 100644 --- a/e2e/worksheets.spec.ts +++ b/e2e/worksheets.spec.ts @@ -319,7 +319,7 @@ test.describe('worksheet UI', () => { await expect(page.getByRole('button', { name: 'Grid', exact: true })).toHaveAttribute('aria-pressed', 'true'); const downloadPromise = page.waitForEvent('download'); - await page.getByRole('button', { name: 'Save .JSON' }).click(); + await page.getByRole('button', { name: 'Save class work' }).click(); const download = await downloadPromise; const fs = await import('node:fs/promises'); const saved = JSON.parse(await fs.readFile((await download.path())!, 'utf8')); @@ -370,7 +370,7 @@ test.describe('worksheet UI', () => { await expect(page.getByTitle('Remove background worksheet from this board')).toBeVisible(); const downloadPromise = page.waitForEvent('download'); - await page.getByRole('button', { name: 'Save .JSON' }).click(); + await page.getByRole('button', { name: 'Save class work' }).click(); const download = await downloadPromise; const fs = await import('node:fs/promises'); const saved = JSON.parse(await fs.readFile((await download.path())!, 'utf8')); diff --git a/src/App.tsx b/src/App.tsx index c4a5071..b90cae0 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1426,6 +1426,43 @@ export default function App() { performLobbyJoin(targetRoomId, trimmed, cleanPin); }; + /** + * Lobby "New Room": make the room typed in the Room Code box (a random unused code when it's empty) and join it. + * When a room with that code already exists, the same "room already exists" choice as Join comes up, so a + * "new" room never quietly lands you in someone else's. + */ + const handleLobbyNewRoom = async () => { + if (!socket || isCheckingRoom) return; + const trimmed = userName.trim(); + if (!trimmed) { + setKickNotice('Type your name first, then press New Room.'); + displayNameInputRef.current?.focus(); + return; + } + const cleanPin = initialTeacherPin.trim(); + if (cleanPin && cleanPin.length < MIN_TEACHER_PIN_LENGTH) { + setKickNotice(`Teacher PIN must be at least ${MIN_TEACHER_PIN_LENGTH} characters.`); + return; + } + const typed = roomId.replace(/^-|-$/g, '').trim(); + setIsCheckingRoom(true); + try { + if (!typed) { + performLobbyJoin(await generateUnusedRoomCode(), trimmed, cleanPin); + return; + } + const target = normalizeRoomCode(typed); + const availability = await checkRoomAvailability(target); + if (availability?.exists) { + setPendingRoomPrompt({ source: 'lobby', availability, userName: trimmed, teacherPin: cleanPin }); + return; + } + performLobbyJoin(target, trimmed, cleanPin); + } finally { + setIsCheckingRoom(false); + } + }; + const handleCancelRoomPrompt = useCallback(() => { if (!isCheckingRoom) { setPendingRoomPrompt(null); @@ -2018,14 +2055,9 @@ export default function App() { {onTeacherLessonRequest && ( diff --git a/src/components/CanvasModals.tsx b/src/components/CanvasModals.tsx index 7679aed..c96be1b 100644 --- a/src/components/CanvasModals.tsx +++ b/src/components/CanvasModals.tsx @@ -1705,7 +1705,7 @@ export function RestoreSnapshotModal({
File: {pendingSnapshot.fileName} diff --git a/src/components/LessonPackModals.tsx b/src/components/LessonPackModals.tsx index 4d50ecc..5a2a09b 100644 --- a/src/components/LessonPackModals.tsx +++ b/src/components/LessonPackModals.tsx @@ -27,6 +27,7 @@ import { pickDriveFile, pickDriveFolder, saveJsonToDrive, + LESSON_MIME, type DriveFolder, } from '../lib/googleDrive'; @@ -218,7 +219,7 @@ export function SaveLessonModal({ try { await getAccessToken(); // first, inside the click, so the sign-in popup isn't blocked // Kept apart from this room's own Drive save, so saving a lesson never replaces the room file. - const saved = await saveJsonToDrive(`lesson:${roomId}`, build.fileName, folder, build.json); + const saved = await saveJsonToDrive(`lesson:${roomId}`, build.fileName, folder, build.json, LESSON_MIME); setDriveMessage({ text: `Saved ${saved.fileName} to ${saved.folder.name}.`, isError: false }); } catch (err) { setDriveMessage({ text: driveError(err, 'Could not save to Google Drive.'), isError: true }); @@ -679,7 +680,7 @@ export function LoadLessonModal({