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({

- Restore Room Snapshot (.JSON) + Open Class Work (.json)

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({

The main board's ink and worksheet will be replaced. Prepared rounds will be replaced.{' '}
)} diff --git a/src/lib/googleDrive.ts b/src/lib/googleDrive.ts index 01e73cc..aceefb5 100644 --- a/src/lib/googleDrive.ts +++ b/src/lib/googleDrive.ts @@ -7,6 +7,11 @@ export const PPT_MIME = 'application/vnd.ms-powerpoint'; export const PDF_MIME = 'application/pdf'; export const OCTET_STREAM_MIME = 'application/octet-stream'; export const JSON_MIME = 'application/json'; +/** + * Lessons saved to Drive get their own type, so the lesson picker can list only lessons: the Picker filters by type, + * not by file name, and room saves are application/json too. Lessons saved before this are application/json. + */ +export const LESSON_MIME = 'application/vnd.allaboard.lesson+json'; export const FOLDER_MIME = 'application/vnd.google-apps.folder'; export const MAX_PPTX_BYTES = 100 * 1024 * 1024; @@ -505,8 +510,9 @@ async function openPicker( /** * Worksheet picker: Slides | PDFs | Browse Drive tabs. * Snapshot picker: My room saves (only my .json files) | Browse Drive (starting in the last save folder). - * Lesson picker: My saved files | Browse Drive. Browse also allows application/octet-stream, because a `.allaboard` - * file someone uploaded to Drive by hand may carry that type. Still `drive.file`: the Picker grants per-file access. + * Lesson picker: My lessons (only files saved as lessons, LESSON_MIME) | Browse Drive. Browse also lists + * application/json (lessons saved before LESSON_MIME existed) and application/octet-stream (a `.allaboard` file someone + * uploaded to Drive by hand). Still `drive.file`: the Picker grants per-file access. */ export async function pickDriveFile(kind: 'worksheet' | 'snapshot' | 'lesson'): Promise { const accessToken = await getAccessToken(); @@ -531,13 +537,15 @@ export async function pickDriveFile(kind: 'worksheet' | 'snapshot' | 'lesson'): if (!cachedAccount) await getDriveAccount(); const lastFolder = getLastDriveFolder(); views = [ - makeView(pickerNs, 'DOCS', 'My saved files', (v) => { - v.setIncludeFolders(false).setSelectFolderEnabled(false).setMimeTypes(JSON_MIME); + makeView(pickerNs, 'DOCS', 'My lessons', (v) => { + v.setIncludeFolders(false).setSelectFolderEnabled(false).setMimeTypes(LESSON_MIME); tryCall(v, 'setOwnedByMe', true); if (listMode) tryCall(v, 'setMode', listMode); }), makeView(pickerNs, 'DOCS', 'Browse Drive', (v) => { - v.setIncludeFolders(true).setSelectFolderEnabled(false).setMimeTypes(`${JSON_MIME},${OCTET_STREAM_MIME}`); + v.setIncludeFolders(true) + .setSelectFolderEnabled(false) + .setMimeTypes(`${LESSON_MIME},${JSON_MIME},${OCTET_STREAM_MIME}`); if (lastFolder.id) tryCall(v, 'setParent', lastFolder.id); if (listMode) tryCall(v, 'setMode', listMode); }), @@ -814,15 +822,17 @@ export async function downloadDriveFile( } /** - * Saves a room snapshot to Drive as `fileName` inside `folder`. + * Saves a room snapshot (or, with LESSON_MIME, a lesson) to Drive as `fileName` inside `folder`. * If that's the same name and folder as this room's last save, the file is updated in place; * otherwise a new file is created. Remembers the result for next time. + * The type is set on updates too, so re-saving an older lesson makes it show under "My lessons". */ export async function saveJsonToDrive( roomId: string, fileName: string, folder: DriveFolder, - json: string + json: string, + mimeType: string = JSON_MIME ): Promise { if (!cachedAccount) await getDriveAccount(); const last = getRoomDriveSave(roomId); @@ -834,13 +844,13 @@ export async function saveJsonToDrive( : 'https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable'; const method = fileId ? 'PATCH' : 'POST'; const metadata: Record = fileId - ? { name: fileName } - : { name: fileName, mimeType: JSON_MIME, ...(folder.id ? { parents: [folder.id] } : {}) }; + ? { name: fileName, ...(mimeType !== JSON_MIME ? { mimeType } : {}) } + : { name: fileName, mimeType, ...(folder.id ? { parents: [folder.id] } : {}) }; const res = await driveFetch(url, { method, headers: { 'Content-Type': 'application/json; charset=UTF-8', - 'X-Upload-Content-Type': JSON_MIME, + 'X-Upload-Content-Type': mimeType, }, body: JSON.stringify(metadata), }); @@ -866,7 +876,7 @@ export async function saveJsonToDrive( const putRes = await driveFetch(uploadUrl, { method: 'PUT', - headers: { 'Content-Type': JSON_MIME }, + headers: { 'Content-Type': mimeType }, body: json, }); const saved = await putRes.json(); diff --git a/src/lib/lessonPack.ts b/src/lib/lessonPack.ts index dab21ef..8135c6d 100644 --- a/src/lib/lessonPack.ts +++ b/src/lib/lessonPack.ts @@ -379,7 +379,7 @@ export function validateLesson(raw: unknown): { lesson: LessonPack | null; error if (!isObject(raw)) return { lesson: null, error: "This isn't an AllAboard lesson file." }; if (raw.kind !== LESSON_KIND) { if (raw.kind === undefined && (raw.version === 1 || raw.version === 2) && 'elements' in raw) { - return { lesson: null, error: 'This is a room save. Use Import .JSON instead.' }; + return { lesson: null, error: 'This is a class work save, not a lesson. Use Open class work instead.' }; } return { lesson: null, error: "This isn't an AllAboard lesson file." }; } diff --git a/src/lib/problemReport.ts b/src/lib/problemReport.ts index 41cf5e6..c430f03 100644 --- a/src/lib/problemReport.ts +++ b/src/lib/problemReport.ts @@ -36,7 +36,7 @@ export const REPORT_CATEGORIES: ReportCategory[] = [ { id: 'breakouts', label: 'Breakout rounds or student boards', hint: 'Wrong board, rounds, groups, Live Grid' }, { id: 'chat', label: 'Chat', hint: 'Messages missing, late or in the wrong place' }, { id: 'teacher', label: 'Teacher tools', hint: 'PIN, lock, timer, stamps, moderation' }, - { id: 'saving', label: 'Saving, loading or exporting', hint: 'Save .JSON, lessons, PDF export, Google Drive' }, + { id: 'saving', label: 'Saving, loading or exporting', hint: 'Save class work, lessons, PDF export, Google Drive' }, { id: 'other', label: 'Something else', hint: 'Anything that doesn’t fit above' }, ]; diff --git a/src/lib/roomSnapshot.ts b/src/lib/roomSnapshot.ts index 227ca85..57bc1eb 100644 --- a/src/lib/roomSnapshot.ts +++ b/src/lib/roomSnapshot.ts @@ -10,7 +10,7 @@ export interface ParsedSnapshot { error: string | null; } -/** Shared by local "Import .JSON" and "Open from Drive". Never throws. */ +/** Shared by local "Open class work" and "Open Room from Drive". Never throws. */ export function parseSnapshotText(fileName: string, text: string, fallbackRoomId: string): ParsedSnapshot { const empty: PendingSnapshotData = { fileName, roomId: fallbackRoomId, elements: [], messages: [], background: null }; let parsed: any; diff --git a/tests/lessonPack.test.ts b/tests/lessonPack.test.ts index 9abfdba..a5a2323 100644 --- a/tests/lessonPack.test.ts +++ b/tests/lessonPack.test.ts @@ -167,7 +167,7 @@ describe('lesson packs (pure)', () => { parseLessonText('x', JSON.stringify({ ...buildLessonPack(input()), version: LESSON_VERSION + 1 })).error ?? '', /newer AllAboard/ ); - assert.match(parseLessonText('x', JSON.stringify({ version: 2, elements: [] })).error ?? '', /room save/); + assert.match(parseLessonText('x', JSON.stringify({ version: 2, elements: [] })).error ?? '', /class work save/); const tooMany = { ...buildLessonPack(input()), rounds: Array.from({ length: 51 }, () => ({ mode: 'individual' })) }; assert.match(parseLessonText('x', JSON.stringify(tooMany)).error ?? '', /at most 50 rounds/); const tooManyGroups = { diff --git a/tests/roundVariantsServer.test.ts b/tests/roundVariantsServer.test.ts index 5e9851d..b77eeb8 100644 --- a/tests/roundVariantsServer.test.ts +++ b/tests/roundVariantsServer.test.ts @@ -186,7 +186,7 @@ describe('worksheet variants A–D on rounds', () => { assert.equal(init.roundVariants.r1.extra[0].fileName, 'b.png'); assert.equal(init.roundVariants.r1.rule, 'rotate'); - // Room save (Save .JSON → Import .JSON) into another room keeps them. + // Room save (Save class work → Open class work) into another room keeps them. const { socket: t3 } = await pool.join(srv, { roomId: 'v-5-copy', userId: 't1', name: 'Teacher' }); assert.equal((await emitAck(t3, 'teacher:auth', { pin: '1234' })).ok, true); const templates = waitForEvent(t3, 'round-templates-sync');