import type { QueryClient } from '@tanstack/react-query' import { useSuspenseQuery } from '@tanstack/react-query' import { createFileRoute } from '@tanstack/react-router' import { Pencil, X } from 'lucide-react' import { AnimatePresence } from 'motion/react' import * as motion from 'motion/react-client' import { useEffect, useState } from 'react' import { orpc } from '@/client/orpc' import { Button } from '@/components/ui/button' import { BookmarkCard } from '@/modules/bookmarks/components/BookmarkCard' import { BookmarkManager } from '@/modules/bookmarks/components/BookmarkManager' import { CategoryManager } from '@/modules/bookmarks/components/CategoryManager' export const Route = createFileRoute('/_protected/bookmarks' as never)({ loader: async ({ context }: { context: { queryClient: QueryClient } }) => { await context.queryClient.fetchQuery(orpc.bookmarks.category.list.queryOptions()) }, component: BookmarksPage, }) const containerVariants = { hidden: { opacity: 0 }, visible: { opacity: 1, transition: { staggerChildren: 0.05, delayChildren: 0.08 }, }, } const itemVariants = { hidden: { opacity: 0, y: 10 }, visible: { opacity: 1, y: 0, transition: { duration: 0.35, ease: [0.25, 0.46, 0.45, 0.94] as const } }, } function BookmarksPage() { const { data: categories } = useSuspenseQuery(orpc.bookmarks.category.list.queryOptions()) const [editing, setEditing] = useState(false) const [selectedCategoryId, setSelectedCategoryId] = useState(null) useEffect(() => { if (selectedCategoryId === null && categories.length > 0) { setSelectedCategoryId(categories[0]?.id ?? null) } }, [categories, selectedCategoryId]) useEffect(() => { if (selectedCategoryId && !categories.some((c: { id: string }) => c.id === selectedCategoryId)) { setSelectedCategoryId(categories[0]?.id ?? null) } }, [categories, selectedCategoryId]) const selectedCategory = categories.find((c: { id: string }) => c.id === selectedCategoryId) return (

{editing ? '书签管理' : '书签导航'}

{editing ? '管理你的书签分类、图标和排序' : '常用链接和网站的快速导航'}

{editing ? (
{selectedCategory ? ( ) : (
请选择一个分类开始管理书签
)}
) : ( {categories.length === 0 ? (

还没有任何书签

点击右上角「编辑」按钮添加你的第一个书签

) : (
{categories.map( (category: { id: string name: string bookmarks: Array<{ id: string; name: string; url: string; icon: string | null }> }) => (

{category.name}

{category.bookmarks.length === 0 ? (
暂无书签
) : (
{category.bookmarks.map((bookmark) => ( ))}
)}
), )}
)}
)}
) }