Files
yaak/apps/yaak-client/lib/createRequestAndNavigate.tsx
Gregory Schier 7314aedc71 Merge main into proxy branch (formatting and docs)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 12:09:59 -07:00

32 lines
1.1 KiB
TypeScript

import type { GrpcRequest, HttpRequest, WebsocketRequest } from "@yaakapp-internal/models";
import { createWorkspaceModel } from "@yaakapp-internal/models";
import { activeRequestAtom } from "../hooks/useActiveRequest";
import { jotaiStore } from "./jotai";
import { router } from "./router";
export async function createRequestAndNavigate<
T extends HttpRequest | GrpcRequest | WebsocketRequest,
>(patch: Partial<T> & Pick<T, "model" | "workspaceId">) {
const activeRequest = jotaiStore.get(activeRequestAtom);
if (patch.sortPriority === undefined) {
if (activeRequest != null) {
// Place below the currently active request
patch.sortPriority = activeRequest.sortPriority;
} else {
// Place at the very top
patch.sortPriority = -Date.now();
}
}
patch.folderId = patch.folderId || activeRequest?.folderId;
const newId = await createWorkspaceModel(patch);
await router.navigate({
to: "/workspaces/$workspaceId",
params: { workspaceId: patch.workspaceId },
search: (prev) => ({ ...prev, request_id: newId }),
});
return newId;
}