Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion e2e/browser/access.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ 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()
await expect(page.getByLabel('Website domain')).toHaveValue('example.com')
await page.getByRole('button', { name: 'Review contact' }).click()
await page.getByRole('button', { name: 'Save contact' }).click()
await expect(page.getByRole('status')).toContainText('Saved')
Expand Down
5 changes: 5 additions & 0 deletions e2e/browser/cardcap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion e2e/browser/helpers.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
37 changes: 15 additions & 22 deletions e2e/browser/layout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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 })
Expand Down
23 changes: 21 additions & 2 deletions e2e/contact-capture.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>(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)
Expand Down
21 changes: 21 additions & 0 deletions migrations/0006_import_activity.sql
Original file line number Diff line number Diff line change
@@ -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;
24 changes: 24 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
75 changes: 27 additions & 48 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -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, type CaptureMode } from './components/Dashboard'
import { Menu } from './components/Menu'
import { SessionPanel, type SessionProblem } from './components/SessionPanel'
import { SignOutConfirm } from './components/SignOutConfirm'
Expand All @@ -20,6 +20,7 @@ function App() {
const [loading, setLoading] = useState(true)
const [busy, setBusy] = useState(false)
const [captureInput, setCaptureInput] = useState('')
const [captureMode, setCaptureMode] = useState<CaptureMode>(null)
const [capturing, setCapturing] = useState(false)
const [authRequired, setAuthRequired] = useState(false)
const [userEmail, setUserEmail] = useState('')
Expand Down Expand Up @@ -180,8 +181,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 }>(
Expand All @@ -198,6 +199,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)
Expand Down Expand Up @@ -289,6 +291,7 @@ function App() {
setUserEmail('')
setContacts([])
setCaptureInput('')
setCaptureMode(null)
setPasswordPanelOpen(false)
setAccountPassword('')
setAccountPasswordConfirm('')
Expand Down Expand Up @@ -329,7 +332,10 @@ function App() {
contact: isPreview ? reviewedContact(draft) : draft,
})
setContacts((current) => sortContactsByName([...current.filter(contact => contact.id !== data.contact.id), data.contact]))
if (isPreview) setCaptureInput('')
if (isPreview) {
setCaptureInput('')
setCaptureMode(null)
}
selectContact(data.contact)
setNotice('Saved.')
} catch (err) {
Expand Down Expand Up @@ -391,17 +397,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 (
<div className={`app-shell${authRequired ? ' signed-out' : ''}`}>
<a className="skip-link" href="#main">
Skip to contacts
Skip to main content
</a>
<div className="app-content" aria-busy={loading}>
<div className="brand-bar" aria-hidden="true" />
<header className="topbar">
<div className="brand">
<a className="brand" href="/" aria-label="CardCap dashboard" onClick={event => {
if (event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) return
event.preventDefault()
selectContact(null)
setQuery('')
setStatusFilter('')
setPasswordPanelOpen(false)
window.scrollTo(0, 0)
}}>
<picture>
<source srcSet="/brand/csi-monogram-dark.svg" media="(prefers-color-scheme: dark)" />
<img className="brand-mark" src="/brand/csi-monogram-light.svg" alt="" width="36" height="36" />
Expand All @@ -410,7 +424,7 @@ function App() {
<span className="brand-org">Copper State Intelligence</span>
<h1>CardCap</h1>
</div>
</div>
</a>
{!authRequired && (
<div className="toolbar">
<button className="btn primary" type="button" onClick={() => fileInput.current?.click()} disabled={busy}>
Expand Down Expand Up @@ -529,48 +543,13 @@ function App() {
<main className={`workspace view-${view}${photoTab ? ' show-photo' : ''}`} id="main" tabIndex={-1}>
{view === 'loading' && <div className="empty">Loading contacts...</div>}

{(view === 'empty' || view === 'list') && (
<form className="capture-form" onSubmit={event => { event.preventDefault(); void prepareContact() }}>
<label htmlFor="contact-capture">Paste a signature, business details, or a website</label>
<textarea id="contact-capture" value={captureInput} maxLength={12000} rows={2} disabled={busy}
placeholder="Business details or example.com" onChange={event => setCaptureInput(event.currentTarget.value)} />
<button className="btn" disabled={busy || !captureInput.trim()}>
{capturing ? 'Finding contact details…' : 'Review contact'}
</button>
</form>
)}

{view === 'empty' && (
<section className="welcome" aria-labelledby="welcome-title">
<CardArtwork />
<div className="welcome-copy">
<h2 id="welcome-title">Add your first business cards</h2>
<p>Take a photo with Add cards, or import a card image. Review the details, then keep every contact here.</p>
</div>
<ol className="welcome-steps">
<li>
<strong>Add</strong>
<span>Take a photo or upload</span>
</li>
<li>
<strong>Review</strong>
<span>Check the contact details</span>
</li>
<li>
<strong>Export</strong>
<span>Take your contacts with you</span>
</li>
</ol>
<div className="welcome-actions">
<span>Card photos, CSV, vCard or JSON</span>
<button className="btn" type="button" onClick={() => importInput.current?.click()} disabled={busy}>
Import a file
</button>
</div>
</section>
{view === 'list' && (
<Dashboard key={userEmail} contacts={contacts.length} review={reviewCount} busy={busy} capturing={capturing}
mode={captureMode} onMode={setCaptureMode}
input={captureInput} onInput={setCaptureInput} onCapture={() => void prepareContact()} onUpload={() => fileInput.current?.click()} />
)}

{view === 'list' && (
{view === 'list' && contacts.length > 0 && (
<div className="collection-heading">
<div>
<h2>Contacts <span className="collection-count" aria-hidden="true">{contacts.length}</span></h2>
Expand All @@ -580,7 +559,7 @@ function App() {
</div>
)}

{(view === 'list' || view === 'edit') && (
{((view === 'list' && contacts.length > 0) || view === 'edit') && (
<aside className="sidebar" aria-label="Contacts">
<div className="filters">
<label>
Expand Down
Loading
Loading