The UI was desktop-first: no viewport meta (phones rendered at ~980px CSS width, killing every breakpoint), an always-inline 240px sidebar squeezing phone content, fixed p-6/100vh chrome, a 6-column bookmarks table, fixed w-60/w-72 rails on collections/tags/contacts, a 12-tab settings strip that overflowed, and w-72 kanban columns. This pass makes every screen usable on a phone while leaving the desktop layout intact. - layout.tsx: viewport meta (width=device-width, initial-scale=1). - app-shell/sidebar: below lg the sidebar is an overlay drawer (closed by default, hamburger opens, backdrop/navigation/resize-to-desktop closes); at lg+ it is the static expand/collapse rail exactly as before. Separate mobileOpen state so closing the drawer never collapses the desktop rail. h-screen -> h-dvh; main p-6 -> p-3 sm:p-6. - lib/use-media-query.ts: hydration-safe useSyncExternalStore media hook (server snapshot false) so surfaces swap whole layouts without duplicating hidden DOM that would break the suites' strict text locators. - bookmarks: table swaps to tappable cards below sm (title/host/status/tags/ updated + open/trash); shared trash handler; detail sheet unchanged. - collections/tags/contacts: rails become master-detail on phones — full-width list first, tap into detail, Back returns; collections no longer auto-jump into the first item on mobile; phone padding. - settings: tab strip scrolls horizontally (triggers shrink-0) instead of overflowing the page. - kanban/collection boards: columns w-[85vw] max-w-72/64 with a peek of the next column; dvh heights. - calendar: compact cells + single-letter weekday headers on phones. - ui/dialog: max-h-[calc(100dvh-2rem)] + internal scroll + phone width guard so tall forms never clip; ui/tabs triggers shrink-0. - top-bar: alerts panel fits 320px; theme/avatar collapse on the smallest widths; hamburger gains an accessible name. - connector settings (MCP/WebDAV/CalDAV/CardDAV): connection rows wrap and the name gets a width floor — the action cluster previously squeezed the name to zero width on phones (a real bug the new mobile test caught). Verification: new mobile regression suite (390x844 context) proves drawer open/close-on-nav, bookmark cards + sheet, tags master-detail + Back, scrollable settings tabs reaching WebDAV, kanban column fits, and zero horizontal overflow on all eight screens; all 19 existing desktop tests still pass (20/20). Real-stack e2e fully passing. yarn lint / SSR eslint / build: 0 errors.
130 lines
6.3 KiB
TypeScript
130 lines
6.3 KiB
TypeScript
'use client'
|
|
|
|
import { useState, useEffect, useCallback } from 'react'
|
|
import { Button } from '@/components/ui/button'
|
|
import { BookmarkCard } from '@/components/bookmark-card'
|
|
import { BookmarkDetailSheet } from '@/components/bookmark-detail-sheet'
|
|
import { ArrowLeft, Users, RefreshCw, Mail, Phone } from 'lucide-react'
|
|
import { toast } from 'sonner'
|
|
import { useIsMobile } from '@/lib/use-media-query'
|
|
import { cn } from '@/lib/utils'
|
|
import type { Bookmark } from '@/components/app-shell'
|
|
import { fetchBookmarks } from '@/lib/bookmarks'
|
|
|
|
interface Contact {
|
|
id: string
|
|
uid: string
|
|
displayName: string
|
|
email: string | null
|
|
phone: string | null
|
|
_count?: { bookmarks: number }
|
|
}
|
|
|
|
export function ContactsClient() {
|
|
const [contacts, setContacts] = useState<Contact[]>([])
|
|
const [selectedContact, setSelectedContact] = useState<string | null>(null)
|
|
const isMobile = useIsMobile()
|
|
const [bookmarks, setBookmarks] = useState<Bookmark[]>([])
|
|
const [selectedBookmark, setSelectedBookmark] = useState<Bookmark | null>(null)
|
|
const [syncing, setSyncing] = useState(false)
|
|
const [loading, setLoading] = useState(true)
|
|
|
|
const loadContacts = useCallback(async () => {
|
|
setLoading(true)
|
|
try {
|
|
const res = await fetch('/api/contacts')
|
|
if (res.ok) setContacts(await res.json())
|
|
} catch { toast.error('Could not load contacts') }
|
|
finally { setLoading(false) }
|
|
}, [])
|
|
|
|
const loadBookmarks = useCallback(async (contactId: string) => {
|
|
try { setBookmarks(await fetchBookmarks(new URLSearchParams({ contactId }))) }
|
|
catch { toast.error('Could not load bookmarks') }
|
|
}, [])
|
|
|
|
useEffect(() => { const timer = setTimeout(loadContacts, 0); return () => clearTimeout(timer) }, [loadContacts])
|
|
useEffect(() => { const timer = setTimeout(() => { if (selectedContact) loadBookmarks(selectedContact) }, 0); return () => clearTimeout(timer) }, [selectedContact, loadBookmarks])
|
|
useEffect(() => { const reload = () => { loadContacts(); if (selectedContact) loadBookmarks(selectedContact) }; window.addEventListener('superbrain:bookmarks-changed', reload); return () => window.removeEventListener('superbrain:bookmarks-changed', reload) }, [loadContacts, loadBookmarks, selectedContact])
|
|
|
|
const syncContacts = async () => {
|
|
setSyncing(true)
|
|
toast.info('Configure your Nextcloud settings in Settings → Nextcloud to sync contacts')
|
|
setSyncing(false)
|
|
}
|
|
|
|
return (
|
|
<div className={cn('flex h-[calc(100dvh-120px)] gap-6', isMobile && 'gap-0')}>
|
|
<div className={cn('w-72 shrink-0 space-y-4 overflow-y-auto', isMobile && (selectedContact ? 'hidden' : 'w-full'))}>
|
|
<div className="flex items-center justify-between">
|
|
<h1 className="font-display text-2xl font-bold tracking-tight">Contacts</h1>
|
|
<Button variant="outline" size="sm" onClick={syncContacts} loading={syncing} className="gap-1.5">
|
|
<RefreshCw className="h-3 w-3" /> Sync
|
|
</Button>
|
|
</div>
|
|
{loading ? (
|
|
<div className="space-y-2">{Array.from({ length: 5 }).map((_, i) => <div key={i} className="h-14 rounded-lg bg-muted animate-pulse" />)}</div>
|
|
) : contacts.length === 0 ? (
|
|
<div className="text-center py-8">
|
|
<Users className="h-10 w-10 text-muted-foreground/50 mx-auto mb-3" />
|
|
<p className="text-sm text-muted-foreground">No contacts yet</p>
|
|
<p className="text-xs text-muted-foreground mt-1">Sync from Nextcloud in Settings</p>
|
|
</div>
|
|
) : (
|
|
<div className="space-y-1">
|
|
{contacts.map((c: Contact) => (
|
|
<div
|
|
key={c.id}
|
|
role="button"
|
|
tabIndex={0}
|
|
aria-pressed={selectedContact === c.id}
|
|
onClick={() => setSelectedContact(c.id)}
|
|
onKeyDown={e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); setSelectedContact(c.id) } }}
|
|
className={`flex items-center gap-3 rounded-lg px-3 py-2.5 cursor-pointer transition-colors focus-visible:outline-2 focus-visible:outline-primary ${
|
|
selectedContact === c.id ? 'bg-accent' : 'hover:bg-muted'
|
|
}`}
|
|
>
|
|
<div className="h-9 w-9 rounded-full bg-primary/20 flex items-center justify-center text-sm font-bold text-primary shrink-0">
|
|
{(c.displayName ?? '?')[0]?.toUpperCase()}
|
|
</div>
|
|
<div className="min-w-0 flex-1">
|
|
<p className="text-sm font-medium truncate">{c.displayName}</p>
|
|
{c.email && <p className="text-xs text-muted-foreground truncate flex items-center gap-1"><Mail className="h-3 w-3" />{c.email}</p>}
|
|
</div>
|
|
<span className="text-xs text-muted-foreground">{c._count?.bookmarks ?? 0}</span>
|
|
</div>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
<div className={cn('flex-1 overflow-y-auto', isMobile && !selectedContact && 'hidden')}>
|
|
{selectedContact ? (
|
|
<div className="space-y-4">
|
|
{isMobile && (
|
|
<Button variant="ghost" size="sm" className="-ml-2 gap-1 text-muted-foreground" onClick={() => setSelectedContact(null)}>
|
|
<ArrowLeft className="h-4 w-4" /> Back
|
|
</Button>
|
|
)}
|
|
<h2 className="font-medium">Bookmarks for {contacts.find(c => c.id === selectedContact)?.displayName}</h2>
|
|
{bookmarks.length === 0 ? (
|
|
<p className="text-sm text-muted-foreground py-8 text-center">No bookmarks linked to this contact</p>
|
|
) : (
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
|
|
{bookmarks.map((b: Bookmark) => <BookmarkCard key={b.id} bookmark={b} compact onClick={() => setSelectedBookmark(b)} />)}
|
|
</div>
|
|
)}
|
|
</div>
|
|
) : (
|
|
<div className="flex flex-col items-center justify-center h-full text-center">
|
|
<Users className="h-12 w-12 text-muted-foreground/50 mb-4" />
|
|
<p className="text-muted-foreground">Select a contact to view linked bookmarks</p>
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
<BookmarkDetailSheet bookmark={selectedBookmark} onClose={() => setSelectedBookmark(null)} onUpdate={() => { if (selectedContact) loadBookmarks(selectedContact) }} />
|
|
</div>
|
|
)
|
|
}
|