mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 21:06:42 +07:00
fixed node loading hook
This commit is contained in:
parent
4c4461ea19
commit
0dc5ae99a3
7 changed files with 35 additions and 16 deletions
|
@ -14,7 +14,7 @@ export const useFullNode = (id: string) => {
|
|||
lastSeenCurrent,
|
||||
} = useShallowSelect(selectNode);
|
||||
|
||||
useLoadNode(id, isLoading);
|
||||
useLoadNode(id);
|
||||
useOnNodeSeen(node);
|
||||
|
||||
return { node, comments, commentsCount, related, lastSeenCurrent, isLoading, isLoadingComments };
|
||||
|
|
|
@ -4,15 +4,14 @@ import { useDispatch } from 'react-redux';
|
|||
import { EMPTY_NODE } from '~/redux/node/constants';
|
||||
|
||||
// useLoadNode loads node on id change
|
||||
export const useLoadNode = (id: any, isLoading: boolean) => {
|
||||
export const useLoadNode = (id: any) => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
useEffect(() => {
|
||||
if (isLoading) return;
|
||||
dispatch(nodeGotoNode(parseInt(id, 10), undefined));
|
||||
|
||||
return () => {
|
||||
dispatch(nodeSetCurrent(EMPTY_NODE));
|
||||
};
|
||||
}, [dispatch, id, isLoading]);
|
||||
}, [dispatch, id]);
|
||||
};
|
||||
|
|
|
@ -6,13 +6,16 @@ export const useInputPasteUpload = (
|
|||
input: HTMLTextAreaElement | HTMLInputElement | undefined,
|
||||
onUpload: (files: File[]) => void
|
||||
) => {
|
||||
const onPaste = useCallback(async event => {
|
||||
const image = await getImageFromPaste(event);
|
||||
const onPaste = useCallback(
|
||||
async event => {
|
||||
const image = await getImageFromPaste(event);
|
||||
|
||||
if (!image) return;
|
||||
if (!image) return;
|
||||
|
||||
onUpload([image]);
|
||||
}, [onUpload]);
|
||||
onUpload([image]);
|
||||
},
|
||||
[onUpload]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!input) return;
|
||||
|
|
|
@ -36,10 +36,13 @@ export const useNodeFormFormik = (
|
|||
stopEditing: () => void
|
||||
) => {
|
||||
const dispatch = useDispatch();
|
||||
const onSubmit = useCallback((values: INode, helpers: FormikHelpers<INode>) => {
|
||||
helpers.setSubmitting(true);
|
||||
dispatch(nodeSubmitLocal(values, onSuccess(helpers)));
|
||||
}, [dispatch]);
|
||||
const onSubmit = useCallback(
|
||||
(values: INode, helpers: FormikHelpers<INode>) => {
|
||||
helpers.setSubmitting(true);
|
||||
dispatch(nodeSubmitLocal(values, onSuccess(helpers)));
|
||||
},
|
||||
[dispatch]
|
||||
);
|
||||
|
||||
const { current: initialValues } = useRef(values);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue