bigbuffet-rw/app/soapbox/middleware/sounds.ts

26 lines
609 B
TypeScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
'use strict';
2022-08-25 12:56:53 -07:00
import { AnyAction } from 'redux';
2022-08-25 12:56:53 -07:00
import { play, soundCache } from 'soapbox/utils/sounds';
2022-08-25 12:56:53 -07:00
import type { ThunkMiddleware } from 'redux-thunk';
import type { Sounds } from 'soapbox/utils/sounds';
2020-03-27 13:59:38 -07:00
2022-08-25 12:56:53 -07:00
interface Action extends AnyAction {
meta: {
sound: Sounds
}
}
2020-03-27 13:59:38 -07:00
/** Middleware to play sounds in response to certain Redux actions. */
export default function soundsMiddleware(): ThunkMiddleware {
2022-08-25 12:56:53 -07:00
return () => next => (action: Action) => {
if (action.meta?.sound && soundCache[action.meta.sound]) {
2020-03-27 13:59:38 -07:00
play(soundCache[action.meta.sound]);
}
return next(action);
};
2021-08-03 12:22:51 -07:00
}