chore: init monorepo snapshot
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { useQuery, type UseQueryResult } from "@tanstack/react-query";
|
||||
import type { SidebarInitialData } from "@/components/sidebar/types";
|
||||
|
||||
async function requestSidebarData(workspaceId: string): Promise<SidebarInitialData> {
|
||||
const response = await fetch(`/api/sidebar?workspaceId=${workspaceId}`, {
|
||||
method: "GET",
|
||||
credentials: "include",
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
const message = payload?.error ?? "获取侧边栏数据失败";
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
export function useSidebarData(initialData: SidebarInitialData): UseQueryResult<SidebarInitialData> {
|
||||
const workspaceId = initialData.activeWorkspaceId;
|
||||
|
||||
return useQuery({
|
||||
queryKey: ["sidebar", workspaceId],
|
||||
queryFn: () => requestSidebarData(workspaceId),
|
||||
initialData,
|
||||
staleTime: 1000 * 60,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user