Files
ncd-fe/src/middleware/sounds.ts
marcin mikołajczak a58c52631e Arrow functions and so
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2024-05-13 01:18:04 +02:00

26 lines
596 B
TypeScript

import { play, soundCache } from 'soapbox/utils/sounds';
import type { AnyAction, Middleware } from 'redux';
import type { Sounds } from 'soapbox/utils/sounds';
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,
};