feat(web): add loading skeletons, error boundaries, and accessibility improvements

- Add segment-level loading.tsx for dashboard, search, admin, and auth routes
- Add segment-level error.tsx with Vietnamese error messages for all route groups
- Add skip-to-content navigation link in root layout
- Add id="main-content" to all layout main elements
- Add aria-label to nav elements and mobile menu buttons
- Improve dashboard nav responsiveness (icon-only on mobile)
- Hide user name on small screens in dashboard layout

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Ho Ngoc Hai
2026-04-08 13:48:33 +07:00
parent 400a75845c
commit a590a41e73
13 changed files with 498 additions and 13 deletions

View File

@@ -18,7 +18,7 @@ export default function PublicLayout({ children }: { children: React.ReactNode }
<span className="text-lg font-bold text-primary">GoodGo</span>
</Link>
<nav className="flex items-center space-x-1">
<nav aria-label="Điều hướng chính" className="flex items-center space-x-1">
<Link
href="/"
className={cn(
@@ -67,7 +67,7 @@ export default function PublicLayout({ children }: { children: React.ReactNode }
</div>
</header>
<main>{children}</main>
<main id="main-content">{children}</main>
<footer className="border-t bg-muted/40">
<div className="mx-auto max-w-7xl px-4 py-8">

View File

@@ -0,0 +1,60 @@
'use client';
import { useEffect } from 'react';
export default function SearchError({
error,
reset,
}: {
error: Error & { digest?: string };
reset: () => void;
}) {
useEffect(() => {
console.error('Search error:', error);
}, [error]);
return (
<div className="mx-auto max-w-7xl px-4 py-6">
<div className="flex min-h-[400px] flex-col items-center justify-center">
<div className="mx-auto max-w-md text-center">
<div className="mx-auto flex h-14 w-14 items-center justify-center rounded-full bg-destructive/10">
<svg
className="h-7 w-7 text-destructive"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"
/>
</svg>
</div>
<h2 className="mt-4 text-xl font-semibold">Lỗi tìm kiếm</h2>
<p className="mt-2 text-sm text-muted-foreground">
Không thể thực hiện tìm kiếm. Vui lòng thử lại hoặc thay đi bộ lọc.
</p>
{error.digest && (
<p className="mt-1 text-xs text-muted-foreground"> lỗi: {error.digest}</p>
)}
<div className="mt-6 flex justify-center gap-3">
<button
onClick={reset}
className="inline-flex h-9 items-center rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground shadow transition-colors hover:bg-primary/90"
>
Thử lại
</button>
<a
href="/"
className="inline-flex h-9 items-center rounded-md border border-input bg-background px-4 text-sm font-medium shadow-sm transition-colors hover:bg-accent hover:text-accent-foreground"
>
Về trang chủ
</a>
</div>
</div>
</div>
</div>
);
}

View File

@@ -0,0 +1,72 @@
export default function SearchLoading() {
return (
<div className="mx-auto max-w-7xl px-4 py-6">
{/* Header skeleton */}
<div className="mb-6">
<div className="h-8 w-64 animate-pulse rounded bg-muted" />
<div className="mt-2 h-4 w-80 animate-pulse rounded bg-muted" />
</div>
{/* View mode toggle skeleton */}
<div className="mb-4 flex items-center justify-between">
<div className="flex gap-1 rounded-lg border p-1">
<div className="h-8 w-24 animate-pulse rounded bg-muted" />
<div className="h-8 w-24 animate-pulse rounded bg-muted" />
<div className="hidden h-8 w-24 animate-pulse rounded bg-muted lg:block" />
</div>
<div className="h-8 w-20 animate-pulse rounded bg-muted lg:hidden" />
</div>
{/* Filter bar skeleton (desktop) */}
<div className="mb-4 hidden lg:block">
<div className="flex gap-3 rounded-lg border p-4">
{Array.from({ length: 5 }).map((_, i) => (
<div key={i} className="h-9 w-36 animate-pulse rounded bg-muted" />
))}
<div className="h-9 w-24 animate-pulse rounded-md bg-muted" />
</div>
</div>
{/* Content area skeleton */}
<div className="flex gap-6">
{/* Sidebar skeleton (desktop) */}
<aside className="hidden w-64 shrink-0 lg:block">
<div className="rounded-lg border bg-card p-4">
<div className="space-y-4">
{Array.from({ length: 6 }).map((_, i) => (
<div key={i}>
<div className="h-4 w-20 animate-pulse rounded bg-muted" />
<div className="mt-2 h-9 w-full animate-pulse rounded bg-muted" />
</div>
))}
</div>
</div>
</aside>
{/* Results grid skeleton */}
<div className="min-w-0 flex-1">
<div className="mb-4 flex items-center justify-between">
<div className="h-4 w-32 animate-pulse rounded bg-muted" />
<div className="h-9 w-40 animate-pulse rounded bg-muted" />
</div>
<div className="grid gap-4 sm:grid-cols-2 xl:grid-cols-3">
{Array.from({ length: 6 }).map((_, i) => (
<div key={i} className="rounded-lg border bg-card shadow-sm">
<div className="aspect-[16/10] animate-pulse rounded-t-lg bg-muted" />
<div className="p-4">
<div className="h-5 w-3/4 animate-pulse rounded bg-muted" />
<div className="mt-2 h-4 w-1/2 animate-pulse rounded bg-muted" />
<div className="mt-3 flex gap-2">
<div className="h-6 w-16 animate-pulse rounded bg-muted" />
<div className="h-6 w-16 animate-pulse rounded bg-muted" />
</div>
<div className="mt-3 h-5 w-24 animate-pulse rounded bg-muted" />
</div>
</div>
))}
</div>
</div>
</div>
</div>
);
}