import type { QueryClient } from '@tanstack/react-query' import { useSuspenseQuery } from '@tanstack/react-query' import { createFileRoute, Link } from '@tanstack/react-router' import * as icons from 'lucide-react' import { ArrowRight, Compass, Plus } from 'lucide-react' import * as motion from 'motion/react-client' import { orpc } from '@/client/orpc' const allIcons = icons as unknown as Record> export const Route = createFileRoute('/_protected/' as never)({ loader: async ({ context }: { context: { queryClient: QueryClient } }) => { await context.queryClient.fetchQuery(orpc.bookmarks.category.list.queryOptions()) }, component: DashboardPage, }) const getGreeting = (hour: number): string => { if (hour >= 5 && hour < 12) return '早上好' if (hour >= 12 && hour < 14) return '中午好' if (hour >= 14 && hour < 18) return '下午好' return '晚上好' } const formatDate = (date: Date): string => { const weekdays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'] const year = date.getFullYear() const month = date.getMonth() + 1 const day = date.getDate() const weekday = weekdays[date.getDay()] return `${year}年${month}月${day}日 ${weekday}` } const containerVariants = { hidden: { opacity: 0 }, visible: { opacity: 1, transition: { staggerChildren: 0.06, delayChildren: 0.1 }, }, } const itemVariants = { hidden: { opacity: 0, y: 12 }, visible: { opacity: 1, y: 0, transition: { duration: 0.4, ease: [0.25, 0.46, 0.45, 0.94] as const } }, } function DashboardPage() { const { data: categories } = useSuspenseQuery(orpc.bookmarks.category.list.queryOptions()) const now = new Date() const totalBookmarks = categories.reduce( (sum: number, cat: { bookmarks: Array<{ id: string }> }) => sum + cat.bookmarks.length, 0, ) const topBookmarks = categories .flatMap((cat: { bookmarks: Array<{ id: string; name: string; url: string; icon: string | null }> }) => cat.bookmarks.slice(0, 4), ) .slice(0, 8) return (

{getGreeting(now.getHours())}

{formatDate(now)}

{topBookmarks.length > 0 && (

常用书签

查看全部
{topBookmarks.map((bookmark: { id: string; name: string; url: string; icon: string | null }) => { const Icon = (bookmark.icon && allIcons[bookmark.icon]) || icons.Globe return (
{bookmark.name}
) })}
)}

概览

书签导航

{categories.length} 个分类 · {totalBookmarks} 个书签

添加书签

快速添加常用链接

) }