Upgrade all the Redux things
This commit is contained in:
@ -9,7 +9,7 @@ import { IntlProvider } from 'react-intl';
|
||||
import { Provider } from 'react-redux';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { Action, applyMiddleware, createStore } from 'redux';
|
||||
import thunk from 'redux-thunk';
|
||||
import { thunk } from 'redux-thunk';
|
||||
|
||||
import { ChatProvider } from 'soapbox/contexts/chat-context';
|
||||
import { StatProvider } from 'soapbox/contexts/stat-context';
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import toast from 'soapbox/toast';
|
||||
|
||||
import type { AnyAction } from 'redux';
|
||||
import type { ThunkMiddleware } from 'redux-thunk';
|
||||
import type { AnyAction, Middleware } from 'redux';
|
||||
|
||||
/** Whether the action is considered a failure. */
|
||||
const isFailType = (type: string): boolean => type.endsWith('_FAIL');
|
||||
@ -21,8 +20,9 @@ const shouldShowError = ({ type, skipAlert, error }: AnyAction): boolean => {
|
||||
};
|
||||
|
||||
/** Middleware to display Redux errors to the user. */
|
||||
const errorsMiddleware = (): ThunkMiddleware =>
|
||||
() => next => action => {
|
||||
const errorsMiddleware = (): Middleware =>
|
||||
() => next => anyAction => {
|
||||
const action = anyAction as AnyAction;
|
||||
if (shouldShowError(action)) {
|
||||
toast.showAlertForError(action.error);
|
||||
}
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
import { AnyAction } from 'redux';
|
||||
|
||||
import { play, soundCache } from 'soapbox/utils/sounds';
|
||||
|
||||
import type { ThunkMiddleware } from 'redux-thunk';
|
||||
import type { AnyAction, Middleware } from 'redux';
|
||||
import type { Sounds } from 'soapbox/utils/sounds';
|
||||
|
||||
interface Action extends AnyAction {
|
||||
@ -12,8 +11,9 @@ interface Action extends AnyAction {
|
||||
}
|
||||
|
||||
/** Middleware to play sounds in response to certain Redux actions. */
|
||||
export default function soundsMiddleware(): ThunkMiddleware {
|
||||
return () => next => (action: Action) => {
|
||||
export default function soundsMiddleware(): Middleware {
|
||||
return () => next => anyAction => {
|
||||
const action = anyAction as Action;
|
||||
if (action.meta?.sound && soundCache[action.meta.sound]) {
|
||||
play(soundCache[action.meta.sound]);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { configureStore } from '@reduxjs/toolkit';
|
||||
import thunk, { ThunkDispatch } from 'redux-thunk';
|
||||
import { configureStore, Tuple } from '@reduxjs/toolkit';
|
||||
import { thunk, type ThunkDispatch } from 'redux-thunk';
|
||||
|
||||
import errorsMiddleware from './middleware/errors';
|
||||
import soundsMiddleware from './middleware/sounds';
|
||||
@ -9,11 +9,11 @@ import type { AnyAction } from 'redux';
|
||||
|
||||
export const store = configureStore({
|
||||
reducer: appReducer,
|
||||
middleware: [
|
||||
middleware: () => new Tuple(
|
||||
thunk,
|
||||
errorsMiddleware(),
|
||||
soundsMiddleware(),
|
||||
],
|
||||
),
|
||||
devTools: true,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user