feat(ui): add redux events for queue cleared & batch enqueued socket events

This commit is contained in:
psychedelicious 2024-07-01 10:49:22 +10:00
parent 0d9ecf0f90
commit 941db90518
3 changed files with 16 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import { createAction } from '@reduxjs/toolkit';
import type {
BatchEnqueuedEvent,
BulkDownloadCompleteEvent,
BulkDownloadFailedEvent,
BulkDownloadStartedEvent,
@ -21,6 +22,7 @@ import type {
ModelInstallStartedEvent,
ModelLoadCompleteEvent,
ModelLoadStartedEvent,
QueueClearedEvent,
QueueItemStatusChangedEvent,
} from 'services/events/types';
@ -57,6 +59,8 @@ export const socketModelInstallError = createSocketAction<ModelInstallErrorEvent
export const socketModelInstallCancelled = createSocketAction<ModelInstallCancelledEvent>('ModelInstallCancelledEvent');
export const socketQueueItemStatusChanged =
createSocketAction<QueueItemStatusChangedEvent>('QueueItemStatusChangedEvent');
export const socketQueueCleared = createSocketAction<QueueClearedEvent>('QueueClearedEvent');
export const socketBatchEnqueued = createSocketAction<BatchEnqueuedEvent>('BatchEnqueuedEvent');
export const socketBulkDownloadStarted = createSocketAction<BulkDownloadStartedEvent>('BulkDownloadStartedEvent');
export const socketBulkDownloadComplete = createSocketAction<BulkDownloadCompleteEvent>('BulkDownloadCompleteEvent');
export const socketBulkDownloadError = createSocketAction<BulkDownloadFailedEvent>('BulkDownloadFailedEvent');

View File

@ -4,6 +4,7 @@ import { $queueId } from 'app/store/nanostores/queueId';
import type { AppDispatch } from 'app/store/store';
import { toast } from 'features/toast/toast';
import {
socketBatchEnqueued,
socketBulkDownloadComplete,
socketBulkDownloadError,
socketBulkDownloadStarted,
@ -26,6 +27,7 @@ import {
socketModelInstallStarted,
socketModelLoadComplete,
socketModelLoadStarted,
socketQueueCleared,
socketQueueItemStatusChanged,
} from 'services/events/actions';
import type { ClientToServerEvents, ServerToClientEvents } from 'services/events/types';
@ -116,6 +118,12 @@ export const setEventListeners = ({ socket, dispatch }: SetEventListenersArg) =>
socket.on('queue_item_status_changed', (data) => {
dispatch(socketQueueItemStatusChanged({ data }));
});
socket.on('queue_cleared', (data) => {
dispatch(socketQueueCleared({ data }));
});
socket.on('batch_enqueued', (data) => {
dispatch(socketBatchEnqueued({ data }));
});
socket.on('bulk_download_started', (data) => {
dispatch(socketBulkDownloadStarted({ data }));
});

View File

@ -24,6 +24,8 @@ export type DownloadCancelledEvent = S['DownloadCancelledEvent'];
export type DownloadErrorEvent = S['DownloadErrorEvent'];
export type QueueItemStatusChangedEvent = S['QueueItemStatusChangedEvent'];
export type QueueClearedEvent = S['QueueClearedEvent'];
export type BatchEnqueuedEvent = S['BatchEnqueuedEvent'];
export type BulkDownloadStartedEvent = S['BulkDownloadStartedEvent'];
export type BulkDownloadCompleteEvent = S['BulkDownloadCompleteEvent'];
@ -58,6 +60,8 @@ export type ServerToClientEvents = {
model_install_cancelled: (payload: ModelInstallCancelledEvent) => void;
model_load_complete: (payload: ModelLoadCompleteEvent) => void;
queue_item_status_changed: (payload: QueueItemStatusChangedEvent) => void;
queue_cleared: (payload: QueueClearedEvent) => void;
batch_enqueued: (payload: BatchEnqueuedEvent) => void;
bulk_download_started: (payload: BulkDownloadStartedEvent) => void;
bulk_download_complete: (payload: BulkDownloadCompleteEvent) => void;
bulk_download_error: (payload: BulkDownloadFailedEvent) => void;