* Set default font in examle * prettify file * add ui elements * Use UIButton at AuthPanel * sort deps * remove unsed getUserTitle method * move UserId inside AuthPanel * tests * use UIButton and UInput in Anonymous login * Use UIButton and UIInput in email login * Replace Button to UIButton * fix context for onTitleClick in dropdown * rearrage class props in dropdown * TODO: change finding over DOM to using ref * Use UIButton in input * rearrage deps * Use UIButton in comment * test * Focus and Input buttons * custom focus style for inputs and buttons * the same focus style for comment input * align buttons by top line in input * Token dropdown & hover fix * disable hover when button disabled * make token dropdown markup in new style * Fix trailing comma * update prettier * move prettier config to json format because it is more hendy for settings (for example vscode can suggest rules) * prettier fixed trailing comman in ejs * Remove unnecessary conditions * Files was formatted by Prettier * fix cursor pointer on collapse button * Move components and right naming * ui-button -> button * ui-input -> input * input -> comment-form * Change cursor behavior on disabled state * Change button style * font-weight: normal by default * add small border-radius * Change another one button to component * Fix autofocus on username in email login form * use preact inbuild autoFocus * fix autofocus on back from token step * sleep for 0s enough to wait next render before focus * use more specific name for username input * fix line-height at auth line on mobile * fix className
30 lines
1022 B
TypeScript
30 lines
1022 B
TypeScript
import { useCallback, useMemo } from 'preact/compat';
|
|
import { useDispatch } from 'react-redux';
|
|
import { BoundActionCreator, BoundActionCreators } from '@app/utils/actionBinder';
|
|
|
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
|
|
/** binds actions to dispatch */
|
|
export const useActions = <Actions extends { [key: string]: Function }>(
|
|
actions: Actions
|
|
): BoundActionCreators<Actions> => {
|
|
const dispatch = useDispatch();
|
|
|
|
return useMemo(
|
|
() =>
|
|
Object.entries(actions).reduce<BoundActionCreator<Actions>>((result, [key, fn]) => {
|
|
(result as any)[key] = (...args: any[]) => dispatch(fn(...args));
|
|
return result;
|
|
}, {} as any),
|
|
[dispatch, ...Object.values(actions)]
|
|
) as any;
|
|
};
|
|
|
|
export const useAction = <Action extends Function>(action: Action): BoundActionCreator<Action> => {
|
|
const dispatch = useDispatch();
|
|
|
|
return useCallback(((...args: any[]) => dispatch(action(...args))) as any, [dispatch, action]);
|
|
};
|
|
|
|
/* eslint-enable @typescript-eslint/no-explicit-any */
|