Switch to workspace

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak
2024-08-28 12:46:03 +02:00
parent 694abcb489
commit 4d5690d0c1
1318 changed files with 12005 additions and 11618 deletions

View File

@@ -0,0 +1,32 @@
import toast from 'soapbox/toast';
import type { AnyAction, Middleware } from 'redux';
/** Whether the action is considered a failure. */
const isFailType = (type: string): boolean => type.endsWith('_FAIL');
/** Whether the action is a failure to fetch from browser storage. */
const isRememberFailType = (type: string): boolean => type.endsWith('_REMEMBER_FAIL');
/** Whether the error contains an Axios response. */
const hasResponse = (error: any): boolean => Boolean(error && error.response);
/** Don't show 401's. */
const authorized = (error: any): boolean => error?.response?.status !== 401;
/** Whether the error should be shown to the user. */
const shouldShowError = ({ type, skipAlert, error }: AnyAction): boolean =>
!skipAlert && hasResponse(error) && authorized(error) && isFailType(type) && !isRememberFailType(type);
/** Middleware to display Redux errors to the user. */
const errorsMiddleware = (): Middleware =>
() => next => anyAction => {
const action = anyAction as AnyAction;
if (shouldShowError(action)) {
toast.showAlertForError(action.error);
}
return next(action);
};
export { errorsMiddleware as default };

View File

@@ -0,0 +1,25 @@
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,
};