feat: 添加可折叠侧边栏布局,优化仓库列表和工作空间页面

This commit is contained in:
xiongxiao
2026-03-19 20:26:27 +08:00
committed by cnb
parent 9a06364880
commit dd6eff9269
13 changed files with 568 additions and 236 deletions

View File

@@ -14,6 +14,7 @@ import {
} from "@/components/ui/card";
import { CreateDialog, EditDialog } from "./components";
import { SearchIcon, RefreshCwIcon, PlusIcon, PencilIcon, TrashIcon } from "lucide-react";
import { SidebarLayout } from "@/pages/sidebar/components";
export const App = () => {
const workspaceStore = useWorkspaceStore(useShallow((state: WorkspaceState) => {
@@ -58,92 +59,94 @@ export const App = () => {
};
return (
<div className="p-5">
<div className="flex justify-between items-center mb-5">
<h1 className="text-2xl font-semibold">Workspaces</h1>
<div className="flex gap-2">
<div className="relative">
<SearchIcon className="absolute left-2.5 top-1/2 -translate-y-1/2 size-4 text-muted-foreground" />
<Input
type="text"
placeholder="搜索workspace..."
value={search}
onChange={(e) => setSearch(e.target.value)}
className="pl-8 w-48"
/>
<SidebarLayout>
<div className="p-5">
<div className="flex justify-between items-center mb-5">
<h1 className="text-2xl font-semibold">Workspaces</h1>
<div className="flex gap-2">
<div className="relative">
<SearchIcon className="absolute left-2.5 top-1/2 -translate-y-1/2 size-4 text-muted-foreground" />
<Input
type="text"
placeholder="搜索workspace..."
value={search}
onChange={(e) => setSearch(e.target.value)}
className="pl-8 w-48"
/>
</div>
<Button variant="outline" size="sm" onClick={handleRefresh}>
<RefreshCwIcon className="size-4" />
</Button>
<Button variant="outline" size="sm" onClick={handleCreate}>
<PlusIcon className="size-4" />
Workspace
</Button>
</div>
<Button variant="outline" size="sm" onClick={handleRefresh}>
<RefreshCwIcon className="size-4" />
</Button>
<Button variant="outline" size="sm" onClick={handleCreate}>
<PlusIcon className="size-4" />
Workspace
</Button>
</div>
</div>
{workspaceStore.loading ? (
<div className="text-center py-10 text-muted-foreground">...</div>
) : workspaceStore.list.length === 0 ? (
<div className="text-center py-10 text-muted-foreground">workspace数据</div>
) : (
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
{workspaceStore.list.map((item) => (
<Card key={item.id}>
<CardHeader>
<CardTitle>{item.title || '未命名'}</CardTitle>
<CardDescription className="text-xs">ID: {item.id}</CardDescription>
</CardHeader>
<CardContent className="space-y-2">
{item.tags && item.tags.length > 0 && (
<div className="flex flex-wrap gap-1">
{item.tags.map((tag, index) => (
<Badge key={index} variant="outline">{tag}</Badge>
))}
{workspaceStore.loading ? (
<div className="text-center py-10 text-muted-foreground">...</div>
) : workspaceStore.list.length === 0 ? (
<div className="text-center py-10 text-muted-foreground">workspace数据</div>
) : (
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
{workspaceStore.list.map((item) => (
<Card key={item.id}>
<CardHeader>
<CardTitle>{item.title || '未命名'}</CardTitle>
<CardDescription className="text-xs">ID: {item.id}</CardDescription>
</CardHeader>
<CardContent className="space-y-2">
{item.tags && item.tags.length > 0 && (
<div className="flex flex-wrap gap-1">
{item.tags.map((tag, index) => (
<Badge key={index} variant="outline">{tag}</Badge>
))}
</div>
)}
{item.summary && (
<p className="text-sm text-muted-foreground">{item.summary}</p>
)}
{item.description && (
<p className="text-sm text-muted-foreground line-clamp-2">{item.description}</p>
)}
<p className="text-xs text-muted-foreground">
: {item.createdAt ? dayjs(item.createdAt).format('YYYY-MM-DD HH:mm:ss') : '-'}
</p>
<p className="text-xs text-muted-foreground">
: {item.updatedAt ? dayjs(item.updatedAt).format('YYYY-MM-DD HH:mm:ss') : '-'}
</p>
<div className="flex gap-2 pt-2">
<Button variant="outline" size="sm" onClick={() => handleEdit(item)}>
<PencilIcon className="size-3.5" />
</Button>
<Button variant="outline" size="sm" onClick={() => handleDelete(item.id)}>
<TrashIcon className="size-3.5" />
</Button>
</div>
)}
{item.summary && (
<p className="text-sm text-muted-foreground">{item.summary}</p>
)}
{item.description && (
<p className="text-sm text-muted-foreground line-clamp-2">{item.description}</p>
)}
<p className="text-xs text-muted-foreground">
: {item.createdAt ? dayjs(item.createdAt).format('YYYY-MM-DD HH:mm:ss') : '-'}
</p>
<p className="text-xs text-muted-foreground">
: {item.updatedAt ? dayjs(item.updatedAt).format('YYYY-MM-DD HH:mm:ss') : '-'}
</p>
<div className="flex gap-2 pt-2">
<Button variant="outline" size="sm" onClick={() => handleEdit(item)}>
<PencilIcon className="size-3.5" />
</Button>
<Button variant="outline" size="sm" onClick={() => handleDelete(item.id)}>
<TrashIcon className="size-3.5" />
</Button>
</div>
</CardContent>
</Card>
))}
</div>
)}
</CardContent>
</Card>
))}
</div>
)}
<CreateDialog
open={workspaceStore.showCreateDialog}
onClose={() => workspaceStore.setShowCreateDialog(false)}
onSubmit={workspaceStore.createItem}
/>
<CreateDialog
open={workspaceStore.showCreateDialog}
onClose={() => workspaceStore.setShowCreateDialog(false)}
onSubmit={workspaceStore.createItem}
/>
<EditDialog
open={workspaceStore.showEditDialog}
item={workspaceStore.editingItem}
onClose={() => {
workspaceStore.setShowEditDialog(false);
workspaceStore.setEditingItem(null);
}}
onSubmit={workspaceStore.updateItem}
/>
</div>
<EditDialog
open={workspaceStore.showEditDialog}
item={workspaceStore.editingItem}
onClose={() => {
workspaceStore.setShowEditDialog(false);
workspaceStore.setEditingItem(null);
}}
onSubmit={workspaceStore.updateItem}
/>
</div>
</SidebarLayout>
);
};