feat: unify workspace sidebar and create Foundry graph pages
This commit is contained in:
+18
-3
@@ -1,6 +1,19 @@
|
||||
import type { Profile } from "./api";
|
||||
|
||||
export type Workspace = { id: string; name: string };
|
||||
export type Workspace = { id: string; name: string; role?: "admin" | "editor" | "viewer" };
|
||||
export type Board = {
|
||||
id: string;
|
||||
workspace_id: string;
|
||||
kind: "board";
|
||||
title: string;
|
||||
version: number;
|
||||
content?: { schema_version: number };
|
||||
};
|
||||
export const DEFAULT_BOARD_TITLE = "未命名图谱";
|
||||
|
||||
export function boardHref(workspace: string, board: string, demo = false) {
|
||||
return `/dashboard/${encodeURIComponent(workspace)}/${encodeURIComponent(board)}${demo ? "?demo=1" : ""}`;
|
||||
}
|
||||
type Request = <T>(path: string, options?: RequestInit) => Promise<T>;
|
||||
|
||||
export async function loadWorkspaceHome(
|
||||
@@ -32,12 +45,14 @@ export async function createBoard(
|
||||
id = workspace.id;
|
||||
onWorkspaceCreated(workspace);
|
||||
}
|
||||
return request<{ id: string }>("workspaces/" + id + "/materials", {
|
||||
const name = title.trim() || DEFAULT_BOARD_TITLE;
|
||||
const result = await request<{ id: string; workspace_id: string; kind: "board"; version: number }>("workspaces/" + id + "/materials", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
kind: "board",
|
||||
title: title.trim(),
|
||||
title: name,
|
||||
content: { schema_version: 1 },
|
||||
}),
|
||||
});
|
||||
return { ...result, workspace_id: result.workspace_id || id, title: name };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user