Auto-select a newly created distribution list or group when sending story
This commit is contained in:
parent
81e4564687
commit
2db14e8d6f
14 changed files with 94 additions and 26 deletions
|
@ -2,16 +2,45 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { ActionCreatorsMapObject } from 'redux';
|
||||
import type { ThunkAction } from 'redux-thunk';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
|
||||
/**
|
||||
* Type-level function from an action creator (which may be ThunkAction creator) to a
|
||||
* bound action creator.
|
||||
*
|
||||
* binding a thunk action creator changes it from:
|
||||
* (params) => ThunkAction<R, ...>
|
||||
* to:
|
||||
* (params) => R
|
||||
*
|
||||
* a regular action creator's type is unchanged
|
||||
*/
|
||||
type BoundActionCreator<A> = A extends (
|
||||
...params: infer P
|
||||
) => ThunkAction<infer R, any, any, any>
|
||||
? (...params: P) => R
|
||||
: A;
|
||||
|
||||
export type BoundActionCreatorsMapObject<T extends ActionCreatorsMapObject> = {
|
||||
[Property in keyof T]: BoundActionCreator<T[Property]>;
|
||||
};
|
||||
|
||||
export const useBoundActions = <T extends ActionCreatorsMapObject>(
|
||||
actions: T
|
||||
): T => {
|
||||
): BoundActionCreatorsMapObject<T> => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
return useMemo(() => {
|
||||
return bindActionCreators(actions, dispatch);
|
||||
// bindActionCreators from redux has the wrong type when using thunk actions
|
||||
// so we cast to the correct type
|
||||
return bindActionCreators(
|
||||
actions,
|
||||
dispatch
|
||||
) as any as BoundActionCreatorsMapObject<T>;
|
||||
}, [actions, dispatch]);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue