refactor: extract shared utility functions to eliminate duplication

This commit is contained in:
Viktor Barzin 2026-02-28 16:02:06 +00:00
parent b720013a08
commit 1037ff164d
No known key found for this signature in database
GPG key ID: 0EB088298288D958
10 changed files with 85 additions and 110 deletions

View file

@ -3,6 +3,7 @@ import type { AuthUser } from '@/auth/types';
import type { TaskState, TaskStatusResponse, WSMessage } from '@/types';
import { WS_TASKS_PATH } from '@/constants';
import { fetchTasksForUser, fetchTaskStatus } from '@/services';
import { isTerminalStatus } from '@/utils/taskUtils';
const KEEPALIVE_MS = 30_000;
const MAX_RECONNECT_DELAY_MS = 30_000;
@ -14,10 +15,6 @@ function wsUrl(token: string): string {
return `${proto}://${window.location.host}${WS_TASKS_PATH}?token=${encodeURIComponent(token)}`;
}
function isTerminalStatus(status: string): boolean {
return status === 'SUCCESS' || status === 'FAILURE' || status === 'REVOKED';
}
/** Convert an HTTP TaskStatusResponse into the canonical TaskState shape. */
function httpResponseToTaskState(resp: TaskStatusResponse): TaskState {
const state: TaskState = {