mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-31 14:33:18 +02:00
Websocket Support (#159)
This commit is contained in:
27
src-web/commands/upsertWebsocketRequest.ts
Normal file
27
src-web/commands/upsertWebsocketRequest.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import type { WebsocketRequest } from '@yaakapp-internal/models';
|
||||
import { upsertWebsocketRequest as cmdUpsertWebsocketRequest } from '@yaakapp-internal/ws';
|
||||
import { differenceInMilliseconds } from 'date-fns';
|
||||
import { createFastMutation } from '../hooks/useFastMutation';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
import { router } from '../lib/router';
|
||||
|
||||
export const upsertWebsocketRequest = createFastMutation<
|
||||
WebsocketRequest,
|
||||
void,
|
||||
Parameters<typeof cmdUpsertWebsocketRequest>[0]
|
||||
>({
|
||||
mutationKey: ['upsert_websocket_request'],
|
||||
mutationFn: (request) => cmdUpsertWebsocketRequest(request),
|
||||
onSuccess: async (request) => {
|
||||
const isNew = differenceInMilliseconds(new Date(), request.createdAt + 'Z') < 100;
|
||||
|
||||
if (isNew) {
|
||||
trackEvent('websocket_request', 'create');
|
||||
await router.navigate({
|
||||
to: '/workspaces/$workspaceId',
|
||||
params: { workspaceId: request.workspaceId },
|
||||
search: (prev) => ({ ...prev, request_id: request.id }),
|
||||
});
|
||||
} else trackEvent('websocket_request', 'update');
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user