Files
ncd-fe/packages/pl-fe/src/middleware/sounds.ts
marcin mikołajczak 859149230e pl-fe: cleanup, avoid parsing schemas more than once
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2024-09-01 15:36:24 +02:00

25 lines
591 B
TypeScript

import { play, soundCache } from 'pl-fe/utils/sounds';
import type { Sounds } from 'pl-fe/utils/sounds';
import type { AnyAction, Middleware } from 'redux';
interface Action extends AnyAction {
meta: {
sound: Sounds;
};
}
/** Middleware to play sounds in response to certain Redux actions. */
const soundsMiddleware = (): Middleware => () => next => anyAction => {
const action = anyAction as Action;
if (action.meta?.sound && soundCache[action.meta.sound]) {
play(soundCache[action.meta.sound]);
}
return next(action);
};
export {
soundsMiddleware as default,
};