mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-17 14:37:05 +01:00
24 lines
790 B
TypeScript
24 lines
790 B
TypeScript
import type { GrpcRequest, HttpRequest, WebsocketRequest } from '@yaakapp-internal/models';
|
|
import { duplicateModel } from '@yaakapp-internal/models';
|
|
import { activeWorkspaceIdAtom } from '../hooks/useActiveWorkspace';
|
|
import { jotaiStore } from './jotai';
|
|
import { router } from './router';
|
|
|
|
export async function duplicateRequestAndNavigate(
|
|
model: HttpRequest | GrpcRequest | WebsocketRequest | null,
|
|
) {
|
|
if (model == null) {
|
|
throw new Error('Cannot duplicate null request');
|
|
}
|
|
|
|
const newId = await duplicateModel(model);
|
|
const workspaceId = jotaiStore.get(activeWorkspaceIdAtom);
|
|
if (workspaceId == null) return;
|
|
|
|
await router.navigate({
|
|
to: '/workspaces/$workspaceId',
|
|
params: { workspaceId },
|
|
search: (prev) => ({ ...prev, request_id: newId }),
|
|
});
|
|
}
|