fix(ui): fix middleware types

This commit is contained in:
psychedelicious 2023-04-02 19:38:37 +10:00
parent f9c243d29f
commit 4ac447cf74
2 changed files with 19 additions and 17 deletions

View File

@ -1,4 +1,4 @@
import { AnyAction, Dispatch, MiddlewareAPI } from '@reduxjs/toolkit'; import { MiddlewareAPI } from '@reduxjs/toolkit';
import dateFormat from 'dateformat'; import dateFormat from 'dateformat';
import i18n from 'i18n'; import i18n from 'i18n';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
@ -18,7 +18,7 @@ import {
setIntermediateImage, setIntermediateImage,
} from 'features/gallery/store/gallerySlice'; } from 'features/gallery/store/gallerySlice';
import type { RootState } from 'app/store'; import type { AppDispatch, RootState } from 'app/store';
import { import {
GeneratorProgressEvent, GeneratorProgressEvent,
InvocationCompleteEvent, InvocationCompleteEvent,
@ -33,12 +33,13 @@ import {
STATUS, STATUS,
} from 'services/apiSlice'; } from 'services/apiSlice';
import { emitUnsubscribe } from './actions'; import { emitUnsubscribe } from './actions';
import { listSessions } from 'services/thunks/session';
/** /**
* Returns an object containing listener callbacks * Returns an object containing listener callbacks
*/ */
const makeSocketIOListeners = ( const makeSocketIOListeners = (
store: MiddlewareAPI<Dispatch<AnyAction>, RootState> store: MiddlewareAPI<AppDispatch, RootState>
) => { ) => {
const { dispatch, getState } = store; const { dispatch, getState } = store;

View File

@ -1,9 +1,11 @@
import { Middleware } from '@reduxjs/toolkit'; import { Middleware, MiddlewareAPI } from '@reduxjs/toolkit';
import { emitSubscribe } from 'app/nodesSocketio/actions'; import { emitSubscribe } from 'app/nodesSocketio/actions';
import { AppDispatch, RootState } from 'app/store';
import { setSessionId } from './apiSlice'; import { setSessionId } from './apiSlice';
import { invokeSession } from './thunks/session'; import { invokeSession } from './thunks/session';
export const invokeMiddleware: Middleware = (store) => (next) => (action) => { export const invokeMiddleware: Middleware =
(store: MiddlewareAPI<AppDispatch, RootState>) => (next) => (action) => {
const { dispatch } = store; const { dispatch } = store;
if (action.type === 'api/createSession/fulfilled' && action?.payload?.id) { if (action.type === 'api/createSession/fulfilled' && action?.payload?.id) {
@ -12,7 +14,6 @@ export const invokeMiddleware: Middleware = (store) => (next) => (action) => {
dispatch(setSessionId(sessionId)); dispatch(setSessionId(sessionId));
dispatch(emitSubscribe(sessionId)); dispatch(emitSubscribe(sessionId));
// types are wrong but this works
dispatch(invokeSession({ sessionId })); dispatch(invokeSession({ sessionId }));
} else { } else {
next(action); next(action);