feat(home): HomeRoute with new + import PDF flows
This commit is contained in:
1 parent
c1483ff265
commit
9271a79067
1 file changed
+64
-1
@@ -1,3 +1,66 @@
|
|||||||
|
import { useNavigate } from 'react-router-dom'
|
||||||
|
import { useRef, useState } from 'react'
|
||||||
|
import Brand from '@/components/brand/Brand'
|
||||||
|
import Button from '@/components/ui/Button'
|
||||||
|
import Card from '@/components/ui/Card'
|
||||||
|
import { useConfig } from '@/app/providers/ConfigProvider'
|
||||||
|
import { importReportFromPdf, ImportError } from '@/pdf/import'
|
||||||
|
import { useReportStore } from '@/state/reportStore'
|
||||||
|
|
||||||
export default function HomeRoute() {
|
export default function HomeRoute() {
|
||||||
return <div>HomeRoute placeholder</div>
|
const navigate = useNavigate()
|
||||||
|
const cfg = useConfig()
|
||||||
|
const fileRef = useRef<HTMLInputElement | null>(null)
|
||||||
|
const hydrate = useReportStore((s) => s.hydrateReport)
|
||||||
|
const [error, setError] = useState<string | null>(null)
|
||||||
|
const [busy, setBusy] = useState(false)
|
||||||
|
|
||||||
|
async function onPickFile(e: React.ChangeEvent<HTMLInputElement>) {
|
||||||
|
const file = e.target.files?.[0]
|
||||||
|
if (!file) return
|
||||||
|
setBusy(true)
|
||||||
|
setError(null)
|
||||||
|
try {
|
||||||
|
const bytes = new Uint8Array(await file.arrayBuffer())
|
||||||
|
const report = await importReportFromPdf(bytes)
|
||||||
|
hydrate(report)
|
||||||
|
navigate('/editor')
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof ImportError ? err.message : "Erreur de lecture du PDF.")
|
||||||
|
} finally {
|
||||||
|
setBusy(false)
|
||||||
|
if (fileRef.current) fileRef.current.value = ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<main className="min-h-screen flex flex-col">
|
||||||
|
<header className="px-6 py-4 border-b border-[var(--color-border)] flex items-center justify-between">
|
||||||
|
<Brand size="lg" />
|
||||||
|
<span className="text-sm text-[var(--color-ink-muted)]">{cfg.tagline}</span>
|
||||||
|
</header>
|
||||||
|
<section className="flex-1 grid place-items-center px-6">
|
||||||
|
<div className="grid gap-4 md:grid-cols-2 max-w-3xl w-full">
|
||||||
|
<Card className="p-6 space-y-4">
|
||||||
|
<h2 className="font-serif text-2xl">Nouveau bilan</h2>
|
||||||
|
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||||
|
Démarrer un nouveau bilan d'ostéopathie sur un animal.
|
||||||
|
</p>
|
||||||
|
<Button onClick={() => navigate('/new')} size="lg">Commencer</Button>
|
||||||
|
</Card>
|
||||||
|
<Card className="p-6 space-y-4">
|
||||||
|
<h2 className="font-serif text-2xl">Importer un PDF</h2>
|
||||||
|
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||||
|
Reprendre un bilan précédent généré par cette application pour effectuer un suivi.
|
||||||
|
</p>
|
||||||
|
<input ref={fileRef} type="file" accept="application/pdf,.pdf" className="hidden" onChange={onPickFile} />
|
||||||
|
<Button variant="secondary" size="lg" onClick={() => fileRef.current?.click()} disabled={busy}>
|
||||||
|
{busy ? 'Lecture…' : 'Choisir un PDF'}
|
||||||
|
</Button>
|
||||||
|
{error && <p className="text-sm text-red-700">{error}</p>}
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user