mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
completely removed modal reducer
This commit is contained in:
parent
b1e8bddbaf
commit
8d5afb4f98
34 changed files with 189 additions and 300 deletions
|
@ -1,4 +1,4 @@
|
|||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { useCallback, useState } from 'react';
|
||||
import { getNodeDiff } from '~/api/node';
|
||||
import { uniq } from 'ramda';
|
||||
import { useFlowStore } from '~/store/flow/useFlowStore';
|
||||
|
|
16
src/hooks/modal/useModal.ts
Normal file
16
src/hooks/modal/useModal.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { useModalStore } from '~/store/modal/useModalStore';
|
||||
import { useCallback } from 'react';
|
||||
import { Dialog } from '~/constants/modal';
|
||||
|
||||
export const useModal = () => {
|
||||
const { setCurrent, hide } = useModalStore();
|
||||
|
||||
const showModal = useCallback(
|
||||
(dialog: Dialog) => {
|
||||
setCurrent(dialog);
|
||||
},
|
||||
[setCurrent]
|
||||
);
|
||||
|
||||
return { showModal, hideModal: hide };
|
||||
};
|
11
src/hooks/modal/useShowModal.ts
Normal file
11
src/hooks/modal/useShowModal.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
import { useCallback } from 'react';
|
||||
import { useModal } from '~/hooks/modal/useModal';
|
||||
import { Dialog } from '~/constants/modal';
|
||||
|
||||
export const useShowModal = (dialog: Dialog) => {
|
||||
const modal = useModal();
|
||||
|
||||
return useCallback(() => {
|
||||
modal.showModal(dialog);
|
||||
}, [dialog, modal]);
|
||||
};
|
|
@ -1,13 +1,18 @@
|
|||
import { useCallback } from 'react';
|
||||
import { IFile } from '~/redux/types';
|
||||
import { modalShowPhotoswipe } from '~/redux/modal/actions';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { usePhotoSwipeStore } from '~/store/photoSwipe/usePhotoSwipeStore';
|
||||
import { useShowModal } from '~/hooks/modal/useShowModal';
|
||||
import { Dialog } from '~/constants/modal';
|
||||
|
||||
export const useImageModal = () => {
|
||||
const dispatch = useDispatch();
|
||||
const { setData } = usePhotoSwipeStore();
|
||||
const showModal = useShowModal(Dialog.Photoswipe);
|
||||
|
||||
return useCallback(
|
||||
(images: IFile[], index: number) => dispatch(modalShowPhotoswipe(images, index)),
|
||||
[dispatch]
|
||||
(images: IFile[], index: number) => {
|
||||
setData(images, index);
|
||||
showModal();
|
||||
},
|
||||
[setData, showModal]
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
import { INode } from '~/redux/types';
|
||||
import { useCallback } from 'react';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { modalShowDialog } from '~/redux/modal/actions';
|
||||
import { NODE_EDITOR_DIALOGS } from '~/constants/dialogs';
|
||||
import { apiLockNode, apiPostNodeHeroic, apiPostNodeLike } from '~/api/node';
|
||||
import { showErrorToast } from '~/utils/errors/showToast';
|
||||
|
||||
export const useNodeActions = (node: INode, update: (node: Partial<INode>) => Promise<unknown>) => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const onEdit = useCallback(() => {
|
||||
if (!node.type) {
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch(modalShowDialog(NODE_EDITOR_DIALOGS[node.type]));
|
||||
}, [dispatch, node]);
|
||||
|
||||
const onLike = useCallback(async () => {
|
||||
try {
|
||||
const result = await apiPostNodeLike({ id: node.id });
|
||||
|
@ -50,5 +37,5 @@ export const useNodeActions = (node: INode, update: (node: Partial<INode>) => Pr
|
|||
}
|
||||
}, [node.deleted_at, node.id, update]);
|
||||
|
||||
return { onEdit, onLike, onStar, onLock };
|
||||
return { onLike, onStar, onLock };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue