mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
99 use swr (#100)
* 99: made node use SWR * 99: fixed comments for SWR node * 99: added error toast to useNodeFormFormik.ts
This commit is contained in:
parent
832386d39a
commit
c2d1c2bfc9
35 changed files with 366 additions and 413 deletions
|
@ -1,12 +1,21 @@
|
|||
import { INode } from '~/redux/types';
|
||||
import { useCallback } from 'react';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { nodeEdit, nodeLike, nodeLock, nodeStar } from '~/redux/node/actions';
|
||||
import { nodeLike, nodeLock, nodeStar } from '~/redux/node/actions';
|
||||
import { modalShowDialog } from '~/redux/modal/actions';
|
||||
import { NODE_EDITOR_DIALOGS } from '~/constants/dialogs';
|
||||
|
||||
export const useNodeActions = (node: INode) => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const onEdit = useCallback(() => dispatch(nodeEdit(node.id)), [dispatch, node]);
|
||||
const onEdit = useCallback(() => {
|
||||
if (!node.type) {
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch(modalShowDialog(NODE_EDITOR_DIALOGS[node.type]));
|
||||
}, [dispatch, node]);
|
||||
|
||||
const onLike = useCallback(() => dispatch(nodeLike(node.id)), [dispatch, node]);
|
||||
const onStar = useCallback(() => dispatch(nodeStar(node.id)), [dispatch, node]);
|
||||
const onLock = useCallback(() => dispatch(nodeLock(node.id, !node.deleted_at)), [dispatch, node]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue