chore: import existing Endoleap Pages Router project
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import type { Profile } from "./api";
|
||||
|
||||
export type Workspace = { id: string; name: string };
|
||||
type Request = <T>(path: string, options?: RequestInit) => Promise<T>;
|
||||
|
||||
export async function loadWorkspaceHome(
|
||||
request: Request,
|
||||
signal?: AbortSignal,
|
||||
) {
|
||||
const [profile, result] = await Promise.all([
|
||||
request<Profile>("profile", { signal }),
|
||||
request<Workspace[] | { items: Workspace[] }>("workspaces", { signal }),
|
||||
]);
|
||||
return {
|
||||
profile,
|
||||
workspaces: Array.isArray(result) ? result : result.items || [],
|
||||
};
|
||||
}
|
||||
|
||||
export async function createBoard(
|
||||
request: Request,
|
||||
title: string,
|
||||
workspaceId: string,
|
||||
onWorkspaceCreated: (workspace: Workspace) => void,
|
||||
) {
|
||||
let id = workspaceId;
|
||||
if (!id) {
|
||||
const workspace = await request<Workspace>("workspaces", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ name: "个人空间" }),
|
||||
});
|
||||
id = workspace.id;
|
||||
onWorkspaceCreated(workspace);
|
||||
}
|
||||
return request<{ id: string }>("workspaces/" + id + "/materials", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
kind: "board",
|
||||
title: title.trim(),
|
||||
content: { schema_version: 1 },
|
||||
}),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user