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

View File

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