mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-30 14:12:07 +02:00
Websocket Support (#159)
This commit is contained in:
14
src-web/commands/deleteWebsocketConnection.ts
Normal file
14
src-web/commands/deleteWebsocketConnection.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import type { WebsocketConnection } from '@yaakapp-internal/models';
|
||||
import { deleteWebsocketConnection as cmdDeleteWebsocketConnection } from '@yaakapp-internal/ws';
|
||||
import { createFastMutation } from '../hooks/useFastMutation';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
|
||||
export const deleteWebsocketConnection = createFastMutation({
|
||||
mutationKey: ['delete_websocket_connection'],
|
||||
mutationFn: async function (connection: WebsocketConnection) {
|
||||
return cmdDeleteWebsocketConnection(connection.id);
|
||||
},
|
||||
onSuccess: async () => {
|
||||
trackEvent('websocket_connection', 'delete');
|
||||
},
|
||||
});
|
||||
14
src-web/commands/deleteWebsocketConnections.ts
Normal file
14
src-web/commands/deleteWebsocketConnections.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import type { WebsocketRequest } from '@yaakapp-internal/models';
|
||||
import { deleteWebsocketConnections as cmdDeleteWebsocketConnections } from '@yaakapp-internal/ws';
|
||||
import { createFastMutation } from '../hooks/useFastMutation';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
|
||||
export const deleteWebsocketConnections = createFastMutation({
|
||||
mutationKey: ['delete_websocket_connections'],
|
||||
mutationFn: async function (request: WebsocketRequest) {
|
||||
return cmdDeleteWebsocketConnections(request.id);
|
||||
},
|
||||
onSuccess: async () => {
|
||||
trackEvent('websocket_connection', 'delete_many');
|
||||
},
|
||||
});
|
||||
31
src-web/commands/deleteWebsocketRequest.tsx
Normal file
31
src-web/commands/deleteWebsocketRequest.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import type {WebsocketRequest} from "@yaakapp-internal/models";
|
||||
import { deleteWebsocketRequest as cmdDeleteWebsocketRequest } from '@yaakapp-internal/ws';
|
||||
import { InlineCode } from '../components/core/InlineCode';
|
||||
import { createFastMutation } from '../hooks/useFastMutation';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
import { showConfirm } from '../lib/confirm';
|
||||
import { fallbackRequestName } from '../lib/fallbackRequestName';
|
||||
|
||||
export const deleteWebsocketRequest = createFastMutation({
|
||||
mutationKey: ['delete_websocket_request'],
|
||||
mutationFn: async (request: WebsocketRequest) => {
|
||||
const confirmed = await showConfirm({
|
||||
id: 'delete-websocket-request',
|
||||
title: 'Delete WebSocket Request',
|
||||
variant: 'delete',
|
||||
description: (
|
||||
<>
|
||||
Permanently delete <InlineCode>{fallbackRequestName(request)}</InlineCode>?
|
||||
</>
|
||||
),
|
||||
});
|
||||
if (!confirmed) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return cmdDeleteWebsocketRequest(request.id);
|
||||
},
|
||||
onSuccess: async () => {
|
||||
trackEvent('websocket_request', 'delete');
|
||||
},
|
||||
});
|
||||
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');
|
||||
},
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Workspace } from '@yaakapp-internal/models';
|
||||
import { differenceInMilliseconds } from 'date-fns';
|
||||
import { createFastMutation } from '../hooks/useFastMutation';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
@@ -11,7 +12,7 @@ export const upsertWorkspace = createFastMutation<
|
||||
mutationKey: ['upsert_workspace'],
|
||||
mutationFn: (workspace) => invokeCmd<Workspace>('cmd_update_workspace', { workspace }),
|
||||
onSuccess: async (workspace) => {
|
||||
const isNew = workspace.createdAt == workspace.updatedAt;
|
||||
const isNew = differenceInMilliseconds(new Date(), workspace.createdAt + 'Z') < 100;
|
||||
|
||||
if (isNew) trackEvent('workspace', 'create');
|
||||
else trackEvent('workspace', 'update');
|
||||
|
||||
Reference in New Issue
Block a user