1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

removed all router-modals

This commit is contained in:
Fedor Katurov 2022-01-09 20:27:23 +07:00
parent 85d20e5009
commit ffce400398
15 changed files with 99 additions and 143 deletions

View file

@ -2,8 +2,12 @@ import { INode } from '~/types';
import { useCallback } from 'react';
import { apiLockNode, apiPostNodeHeroic, apiPostNodeLike } from '~/api/node';
import { showErrorToast } from '~/utils/errors/showToast';
import { useModal } from '~/hooks/modal/useModal';
import { Dialog } from '~/constants/modal';
export const useNodeActions = (node: INode, update: (node: Partial<INode>) => Promise<unknown>) => {
const { showModal } = useModal();
const onLike = useCallback(async () => {
try {
const result = await apiPostNodeLike({ id: node.id });
@ -37,5 +41,7 @@ export const useNodeActions = (node: INode, update: (node: Partial<INode>) => Pr
}
}, [node.deleted_at, node.id, update]);
return { onLike, onStar, onLock };
const onEdit = useCallback(() => showModal(Dialog.EditNode, { nodeId: node.id! }), [node]);
return { onLike, onStar, onLock, onEdit };
};

View file

@ -1,15 +1,15 @@
import { useHistory } from 'react-router';
import { useCallback } from 'react';
import { ITag } from '~/types';
import { URLS } from '~/constants/urls';
import { useLoadNode } from '~/hooks/node/useLoadNode';
import { apiDeleteNodeTag, apiPostNodeTags } from '~/api/node';
import { useGetNodeRelated } from '~/hooks/node/useGetNodeRelated';
import { useShowModal } from '~/hooks/modal/useShowModal';
import { Dialog } from '~/constants/modal';
export const useNodeTags = (id: number) => {
const showModal = useShowModal(Dialog.TagSidebar);
const { refresh: refreshRelated } = useGetNodeRelated(id);
const { update } = useLoadNode(id);
const history = useHistory();
const onChange = useCallback(
async (tags: string[]) => {
@ -30,9 +30,9 @@ export const useNodeTags = (id: number) => {
return;
}
history.push(URLS.NODE_TAG_URL(id, encodeURIComponent(tag.title)));
showModal({ tag: tag.title });
},
[history, id]
[showModal, id]
);
const onDelete = useCallback(