From e8f5cdae83b5a7344706b6b1cb2dd65bc490385f Mon Sep 17 00:00:00 2001 From: Cody LeCates Date: Wed, 18 Nov 2026 15:10:37 -0700 Subject: [PATCH 1/2] Make the CardCap dashboard home and track account import activity --- e2e/browser/access.spec.ts | 3 +- e2e/browser/cardcap.spec.ts | 5 ++ e2e/browser/helpers.ts | 2 +- e2e/browser/layout.spec.ts | 37 +++++------- e2e/contact-capture.e2e.test.ts | 23 +++++++- migrations/0006_import_activity.sql | 21 +++++++ src/App.css | 24 ++++++++ src/App.tsx | 67 +++++++--------------- src/components/Dashboard.tsx | 89 +++++++++++++++++++++++++++++ src/shared/types.ts | 10 ++++ src/worker/import-activity.ts | 36 ++++++++++++ src/worker/index.ts | 25 ++++++-- src/worker/repository.ts | 7 +++ 13 files changed, 272 insertions(+), 77 deletions(-) create mode 100644 migrations/0006_import_activity.sql create mode 100644 src/components/Dashboard.tsx create mode 100644 src/worker/import-activity.ts diff --git a/e2e/browser/access.spec.ts b/e2e/browser/access.spec.ts index 356e9f9..4177942 100644 --- a/e2e/browser/access.spec.ts +++ b/e2e/browser/access.spec.ts @@ -42,7 +42,8 @@ test('reviewing and cancelling a website draft leaves the collection empty, savi extractionConfidence: 0.9, needsReview: true, createdAt: new Date().toISOString(), updatedAt: new Date().toISOString(), source: { url, text: company + ' 480-555-0101', checkedAt: new Date().toISOString() }, } } })) - await page.getByLabel('Paste a signature, business details, or a website').fill('example.com') + await page.getByRole('button', { name: 'Add a domain' }).click() + await page.getByLabel('Website domain').fill('example.com') await page.getByRole('button', { name: 'Review contact' }).click() await page.getByRole('button', { name: 'Cancel' }).click() await expect(page.getByRole('heading', { name: WELCOME_HEADING })).toBeVisible() diff --git a/e2e/browser/cardcap.spec.ts b/e2e/browser/cardcap.spec.ts index fee2715..cb6e165 100644 --- a/e2e/browser/cardcap.spec.ts +++ b/e2e/browser/cardcap.spec.ts @@ -107,6 +107,11 @@ test('a failed extraction shows a safe message, leaves nothing behind, and a ret await expect(banner).not.toContainText('OpenAI') expect(await r2Keys(request)).toEqual(r2Before) await expect(page.getByRole('heading', { name: WELCOME_HEADING })).toBeVisible() + await page.reload() + const activity = page.getByRole('region', { name: 'Recent imports' }) + await expect(activity).toContainText('maria-card.png') + await expect(activity).toContainText('Failed') + await expect(activity).toContainText('Unable to extract this card.') await request.get('/__test/inference?mode=card') await uploadCard(page) diff --git a/e2e/browser/helpers.ts b/e2e/browser/helpers.ts index 8cf4425..88439be 100644 --- a/e2e/browser/helpers.ts +++ b/e2e/browser/helpers.ts @@ -1,6 +1,6 @@ import { expect, type Page } from '@playwright/test' -export const WELCOME_HEADING = 'Add your first business cards' +export const WELCOME_HEADING = 'Dashboard' /** Open the Export or Account menu and press one of its items. */ export async function chooseFromMenu(page: Page, menu: 'Export' | 'Account', item: string) { diff --git a/e2e/browser/layout.spec.ts b/e2e/browser/layout.spec.ts index 333748c..71518ea 100644 --- a/e2e/browser/layout.spec.ts +++ b/e2e/browser/layout.spec.ts @@ -38,25 +38,15 @@ async function uploadCard(page: Page) { await expect(page.getByRole('status')).toContainText('Cards added') } -test('with no contacts there is one welcoming state and nothing else competing with it', async ({ page, request }) => { +test('the empty dashboard offers all three capture actions', async ({ page, request }) => { await signIn(page, request) - await expect(page.getByRole('heading', { name: WELCOME_HEADING })).toBeVisible() - await expect(page.getByRole('heading')).toHaveCount(2) // the app name and the welcome - // No second empty message, no list tools, no editor, no photo panel. - await expect(page.getByText('Ready for your first batch')).toHaveCount(0) - await expect(page.getByText('No contacts yet')).toHaveCount(0) - await expect(page.getByRole('searchbox')).toHaveCount(0) - await expect(page.locator('.contact-row')).toHaveCount(0) - await expect(page.getByLabel('Name', { exact: true })).toHaveCount(0) - await expect(page.getByRole('complementary', { name: 'Card photo' })).toHaveCount(0) - // The next action is obvious: Add cards is the one primary button; Import is secondary. - await expect(page.getByRole('banner').getByRole('button', { name: 'Add cards' })).toHaveClass(/primary/) - await expect(page.getByRole('banner').getByRole('button', { name: 'Import' })).not.toHaveClass(/primary/) - // Only one primary button on the whole screen: the header's Add cards. The welcome offers just the secondary Import. - await expect(page.locator('.btn.primary')).toHaveCount(1) - await expect(page.getByRole('button', { name: 'Add cards' })).toHaveCount(1) - await expect(page.locator('.welcome-actions .btn')).toHaveText(['Import a file']) - await expect(page.getByRole('button', { name: 'Import a file' })).not.toHaveClass(/primary/) + await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible() + await expect(page.getByText('No imports yet.')).toBeVisible() + await page.getByRole('button', { name: 'Add a domain' }).click() + await expect(page.getByLabel('Website domain')).toBeFocused() + await page.getByRole('button', { name: 'Paste an email signature' }).click() + await expect(page.getByLabel('Signature or business details')).toBeFocused() + await expect(page.getByRole('button', { name: 'Upload business cards' })).toBeVisible() }) test('export formats live in one Export menu and sign out lives in the Account menu', async ({ page, request }) => { @@ -97,7 +87,7 @@ test('once there are contacts: search and list first; the editor and card photo await page.reload() // List state. - await expect(page.getByRole('heading', { name: WELCOME_HEADING })).toHaveCount(0) + await expect(page.getByRole('heading', { name: WELCOME_HEADING })).toBeVisible() await expect(page.getByRole('searchbox')).toBeVisible() await expect(page.locator('.contact-row')).toHaveCount(3) await expect(page.getByLabel('Name', { exact: true })).toHaveCount(0) @@ -139,7 +129,10 @@ test('desktop collection uses the workspace and a contact can return to the coll expect(collection?.width).toBeGreaterThan(1000) await page.locator('.contact-row', { hasText: 'Ada Lovelace' }).click() await expect(page.getByLabel('Name', { exact: true })).toBeVisible() - await page.getByRole('button', { name: 'All contacts', exact: true }).click() + await page.getByRole('link', { name: 'CardCap dashboard' }).click() + await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible() + await expect(page.getByText('people.csv', { exact: true })).toBeVisible() + await expect(page.getByText('3 new, 0 merged')).toBeVisible() await expect(page.getByRole('searchbox')).toBeVisible() await expect(page.getByLabel('Name', { exact: true })).toHaveCount(0) await expect(page.locator('.contact-row')).toHaveCount(3) @@ -161,10 +154,10 @@ test('controls are compact with a mouse', async ({ page, request }) => { test.describe('on a phone: one task at a time', () => { test.use({ viewport: { width: 375, height: 812 }, hasTouch: true }) - test('the welcome Import a file picker accepts a card photo and opens it for review', async ({ page, request }) => { + test('the dashboard upload picker accepts a card photo and opens it for review', async ({ page, request }) => { await signIn(page, request) const chooserReady = page.waitForEvent('filechooser') - await page.getByRole('button', { name: 'Import a file', exact: true }).click() + await page.getByRole('button', { name: 'Upload business cards', exact: true }).click() const chooser = await chooserReady expect(await chooser.element().getAttribute('accept')).toContain('image/*') await chooser.setFiles({ name: 'business-card.png', mimeType: 'image/png', buffer: PNG_BUFFER }) diff --git a/e2e/contact-capture.e2e.test.ts b/e2e/contact-capture.e2e.test.ts index d82cf2e..5b47413 100644 --- a/e2e/contact-capture.e2e.test.ts +++ b/e2e/contact-capture.e2e.test.ts @@ -9,14 +9,33 @@ it('limits capture per account, returns an unsaved draft, and preserves its sour try { const db = await h.mf.getD1Database('DB') const alice = await h.signIn('capture@example.test') - const run = vi.fn(async () => ({ response: { company: 'Acme Studio', phones: ['480-555-0101'] } })) + let resume!: () => void + const waiting = new Promise(resolve => { resume = resolve }) + const run = vi.fn(async () => { + await waiting + return { response: { company: 'Acme Studio', phones: ['480-555-0101'] } } + }) const env = { DB: db, SESSION_SECRET, AI: { run } } as unknown as Env const input = 'Acme Studio\n480-555-0101' const capture = (cookie: string) => worker.fetch(new Request('https://cardcap.test/api/contact-drafts', { method: 'POST', headers: { cookie, 'content-type': 'application/json' }, body: JSON.stringify({ input }), }), env, { waitUntil() {} } as unknown as ExecutionContext) expect((await capture('')).status).toBe(401) - const response = await capture(alice.cookie) + const pending = capture(alice.cookie) + await vi.waitFor(() => expect(run).toHaveBeenCalledTimes(1)) + try { + expect(await (await alice.request('/api/import-activity')).json()).toMatchObject({ + processing: 1, errors: 0, recent: [{ label: 'Pasted text', state: 'processing' }], + }) + const bob = await h.signIn('other@example.test') + expect(await (await bob.request('/api/import-activity')).json()).toEqual({ processing: 0, errors: 0, recent: [] }) + } finally { + resume() + } + const response = await pending + expect(await (await alice.request('/api/import-activity')).json()).toMatchObject({ + processing: 0, errors: 0, recent: [{ state: 'complete', detail: 'Contact detected for review' }], + }) expect(response.status).toBe(200) const { contact } = await response.json() as { contact: Contact } expect(contact.source?.text).toBe(input) diff --git a/migrations/0006_import_activity.sql b/migrations/0006_import_activity.sql new file mode 100644 index 0000000..fc3a18d --- /dev/null +++ b/migrations/0006_import_activity.sql @@ -0,0 +1,21 @@ +CREATE TABLE IF NOT EXISTS import_activity ( + id TEXT PRIMARY KEY, + user_id TEXT NOT NULL REFERENCES users(id), + label TEXT NOT NULL, + state TEXT NOT NULL, + detail TEXT NOT NULL DEFAULT '', + started_at TEXT NOT NULL +); +CREATE INDEX IF NOT EXISTS idx_import_activity_user_time ON import_activity(user_id, started_at DESC); + +INSERT OR IGNORE INTO import_activity (id, user_id, label, state, detail, started_at) +SELECT 'photo-' || id, user_id, 'Business card', + CASE WHEN status IN ('failed', 'error') THEN 'failed' ELSE 'complete' END, + CASE WHEN status IN ('failed', 'error') THEN 'Unable to extract this card.' + WHEN status = 'duplicate' THEN 'Duplicate merged' ELSE 'Card processed' END, created_at +FROM extraction_jobs; + +INSERT OR IGNORE INTO import_activity (id, user_id, label, state, detail, started_at) +SELECT 'capture-' || c.id, c.user_id, COALESCE(NULLIF(json_extract(s.capture_source, '$.url'), ''), 'Pasted text'), + 'complete', 'Contact saved', COALESCE(NULLIF(json_extract(s.capture_source, '$.checkedAt'), ''), c.created_at) +FROM contact_sources s JOIN contacts c ON c.id = s.contact_id; diff --git a/src/App.css b/src/App.css index c0a4202..f247e21 100644 --- a/src/App.css +++ b/src/App.css @@ -380,6 +380,30 @@ html { color-scheme: light dark; } .capture-form label { font-weight: 600; } .capture-form textarea { min-height: 64px; padding: 12px; border: var(--csi-border); border-radius: 6px; background: var(--csi-paper); color: var(--csi-ink); font: inherit; resize: vertical; } .capture-form .btn { justify-self: start; } + +.brand { color: inherit; text-decoration: none; } +.dashboard { min-width: 0; margin-bottom: 44px; } +.dashboard h2 { color: var(--csi-ink); font-size: clamp(32px, 4vw, 48px); line-height: 1.1; margin: 0 0 24px; } +.dashboard h3 { color: var(--csi-ink); font-size: 20px; margin: 0 0 16px; } +.dashboard-totals { display: grid; grid-template-columns: repeat(4, 1fr); margin: 0 0 28px; padding: 20px 0; border-block: var(--csi-border); gap: 16px; } +.dashboard-totals dt, .import-list span, .import-list time { color: var(--csi-muted); } +.dashboard-totals dd { font: 400 32px/1.2 var(--csi-mono); color: var(--csi-ink); margin: 4px 0 0; } +.dashboard-sections { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: clamp(24px, 4vw, 64px); } +.dashboard-actions { display: flex; flex-wrap: wrap; gap: 8px; } +.dashboard .capture-form { margin: 18px 0 0; } +.import-list { list-style: none; margin: 0; padding: 0; } +.import-list li { display: flex; justify-content: space-between; gap: 16px; border-bottom: var(--csi-border); padding: 10px 0; } +.import-list li:first-child { padding-top: 0; } +.import-list li div { display: grid; align-content: start; min-width: 0; gap: 2px; overflow-wrap: anywhere; } +.import-list li div:last-child { text-align: right; flex-shrink: 0; } +.import-list b { font-weight: 500; } +.import-list time { font-size: 12px; } +.import-failed { color: var(--csi-rose); } +.import-processing { color: var(--csi-turquoise-deep); } +@media (max-width: 760px) { + .dashboard-sections { grid-template-columns: minmax(0, 1fr); } + .dashboard-totals { grid-template-columns: repeat(2, minmax(0, 1fr)); } +} .capture-evidence { padding: 16px; min-width: 0; color: var(--csi-ink); } .capture-evidence small { display: block; margin-top: 6px; } .capture-evidence p { white-space: pre-wrap; overflow-wrap: anywhere; } diff --git a/src/App.tsx b/src/App.tsx index 36bd986..2ed401a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,7 +1,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react' import './App.css' import { LoginGate } from './components/LoginGate' -import { CardArtwork } from './components/CardArtwork' +import { Dashboard } from './components/Dashboard' import { Menu } from './components/Menu' import { SessionPanel, type SessionProblem } from './components/SessionPanel' import { SignOutConfirm } from './components/SignOutConfirm' @@ -180,8 +180,8 @@ function App() { setBusy(true) setError('') setNotice(`Uploading ${files.length} card${files.length === 1 ? '' : 's'}...`) + let lastContact: Contact | null = null try { - let lastContact: Contact | null = null let duplicateCount = 0 for (const file of Array.from(files)) { const data = await apiUpload<{ contact: Contact; extractionMode: string; duplicate: { id: string; reasons: string[] } | null }>( @@ -198,6 +198,7 @@ function App() { : 'Cards added. Review the extracted fields before follow-up.', ) } catch (err) { + if (lastContact && !signedOutRef.current) await loadContacts() fail(err) } finally { setBusy(false) @@ -391,17 +392,25 @@ function App() { const isPreview = Boolean(draft?.source && !contacts.some(contact => contact.id === draft.id)) const duplicate = isPreview && draft ? findDuplicateContact(draft, contacts) : null - const view = draft ? 'edit' : contacts.length ? 'list' : loading ? 'loading' : 'empty' + const view = draft ? 'edit' : loading && !contacts.length ? 'loading' : 'list' return (
- Skip to contacts + Skip to main content
+ {!authRequired && (