mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-05-17 05:07:08 +02:00
Split codebase (#455)
This commit is contained in:
31
apps/yaak-client/lib/createRequestAndNavigate.tsx
Normal file
31
apps/yaak-client/lib/createRequestAndNavigate.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user