Files
upstream-yaak/apps/yaak-client/lib/onboarding.ts
upstream-mirror 906fb231cc
Some checks failed
Lint and Test / Lint/Test (push) Has been cancelled
Generate Sponsors README / deploy (push) Has been skipped
snapshot of https://github.com/mountain-loop/yaak.git (main, 2026-09-23; blobs > 131072B omitted)
2026-09-23 17:39:41 +05:00

45 lines
1.5 KiB
TypeScript

import type { BatchUpsertResult } from "@yaakapp-internal/models";
import { createGlobalModel } from "@yaakapp-internal/models";
import { router } from "./router";
import { rpc } from "./rpc";
import { setKeyValue } from "./keyValueStore";
export type OnboardingChoice =
| "import"
| "import_yaak"
| "example"
| "fresh"
| "open_folder"
| "clone_git";
const NEW_WORKSPACE_NAME = "My Workspace";
/**
* Remembered so later surfaces can lean toward what the user came for (an importer, the
* example, or a blank slate). Nothing reads it yet.
*/
export function recordOnboardingChoice(choice: OnboardingChoice) {
setKeyValue({
namespace: "global",
key: "onboarding",
value: { choice, at: new Date().toISOString() },
}).catch(console.error);
}
export async function createFreshWorkspace() {
const workspaceId = await createGlobalModel({ model: "workspace", name: NEW_WORKSPACE_NAME });
await router.navigate({ to: "/workspaces/$workspaceId", params: { workspaceId } });
}
export async function createExampleWorkspace() {
const created = await rpc<BatchUpsertResult>("cmd_create_example_workspace", {});
const workspace = created.workspaces[0];
if (workspace == null) throw new Error("Example workspace was not created");
const firstRequest = created.httpRequests.find((r) => r.name === "List posts");
await router.navigate({
to: "/workspaces/$workspaceId",
params: { workspaceId: workspace.id },
search: firstRequest ? { request_id: firstRequest.id } : {},
});
}