import { round } from 'lodash-es'; import { atom, computed, map } from 'nanostores'; import type { S } from 'services/api/types'; import type { AppSocket } from 'services/events/types'; import type { ManagerOptions, SocketOptions } from 'socket.io-client'; export const $socket = atom(null); export const $socketOptions = map>({}); export const $isConnected = atom(false); export const $lastProgressEvent = atom(null); export const $progressImage = computed($lastProgressEvent, (val) => val?.image ?? null); export const $hasProgressImage = computed($lastProgressEvent, (val) => Boolean(val?.image)); export const $isProgressFromCanvas = computed($lastProgressEvent, (val) => val?.destination === 'canvas'); export const $invocationProgressMessage = computed($lastProgressEvent, (val) => { if (!val) { return null; } let message = val.message; if (val.percentage) { message += ` (${round(val.percentage * 100)}%)`; } return message; });