1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-24 20:36:40 +07:00

fixed node loading hook

This commit is contained in:
Fedor Katurov 2021-11-21 16:49:21 +07:00
parent 4c4461ea19
commit 0dc5ae99a3
7 changed files with 35 additions and 16 deletions

View file

@ -1,5 +1,5 @@
import React, { FC } from 'react'; import React, { FC } from 'react';
import { BorisUsageStats, IBorisState } from '~/redux/boris/reducer'; import { BorisUsageStats } from '~/redux/boris/reducer';
import { BorisStatsGit } from '../BorisStatsGit'; import { BorisStatsGit } from '../BorisStatsGit';
import { BorisStatsBackend } from '../BorisStatsBackend'; import { BorisStatsBackend } from '../BorisStatsBackend';

View file

@ -48,7 +48,19 @@ const Button: FC<IButtonProps> = memo(
has_icon_right: !!iconRight, has_icon_right: !!iconRight,
round, round,
}), }),
[className, size, color, disabled, stretchy, iconLeft, iconRight, title, children, iconOnly, round] [
className,
size,
color,
disabled,
stretchy,
iconLeft,
iconRight,
title,
children,
iconOnly,
round,
]
); );
return ( return (

View file

@ -9,7 +9,9 @@ import markdown from '~/styles/common/markdown.module.scss';
interface IProps extends INodeComponentProps {} interface IProps extends INodeComponentProps {}
const NodeTextBlock: FC<IProps> = ({ node }) => { const NodeTextBlock: FC<IProps> = ({ node }) => {
const content = useMemo(() => formatTextParagraphs(path(['blocks', 0, 'text'], node) || ''), [node]); const content = useMemo(() => formatTextParagraphs(path(['blocks', 0, 'text'], node) || ''), [
node,
]);
return ( return (
<div <div

View file

@ -14,7 +14,7 @@ export const useFullNode = (id: string) => {
lastSeenCurrent, lastSeenCurrent,
} = useShallowSelect(selectNode); } = useShallowSelect(selectNode);
useLoadNode(id, isLoading); useLoadNode(id);
useOnNodeSeen(node); useOnNodeSeen(node);
return { node, comments, commentsCount, related, lastSeenCurrent, isLoading, isLoadingComments }; return { node, comments, commentsCount, related, lastSeenCurrent, isLoading, isLoadingComments };

View file

@ -4,15 +4,14 @@ import { useDispatch } from 'react-redux';
import { EMPTY_NODE } from '~/redux/node/constants'; import { EMPTY_NODE } from '~/redux/node/constants';
// useLoadNode loads node on id change // useLoadNode loads node on id change
export const useLoadNode = (id: any, isLoading: boolean) => { export const useLoadNode = (id: any) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
useEffect(() => { useEffect(() => {
if (isLoading) return;
dispatch(nodeGotoNode(parseInt(id, 10), undefined)); dispatch(nodeGotoNode(parseInt(id, 10), undefined));
return () => { return () => {
dispatch(nodeSetCurrent(EMPTY_NODE)); dispatch(nodeSetCurrent(EMPTY_NODE));
}; };
}, [dispatch, id, isLoading]); }, [dispatch, id]);
}; };

View file

@ -6,13 +6,16 @@ export const useInputPasteUpload = (
input: HTMLTextAreaElement | HTMLInputElement | undefined, input: HTMLTextAreaElement | HTMLInputElement | undefined,
onUpload: (files: File[]) => void onUpload: (files: File[]) => void
) => { ) => {
const onPaste = useCallback(async event => { const onPaste = useCallback(
const image = await getImageFromPaste(event); async event => {
const image = await getImageFromPaste(event);
if (!image) return; if (!image) return;
onUpload([image]); onUpload([image]);
}, [onUpload]); },
[onUpload]
);
useEffect(() => { useEffect(() => {
if (!input) return; if (!input) return;

View file

@ -36,10 +36,13 @@ export const useNodeFormFormik = (
stopEditing: () => void stopEditing: () => void
) => { ) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const onSubmit = useCallback((values: INode, helpers: FormikHelpers<INode>) => { const onSubmit = useCallback(
helpers.setSubmitting(true); (values: INode, helpers: FormikHelpers<INode>) => {
dispatch(nodeSubmitLocal(values, onSuccess(helpers))); helpers.setSubmitting(true);
}, [dispatch]); dispatch(nodeSubmitLocal(values, onSuccess(helpers)));
},
[dispatch]
);
const { current: initialValues } = useRef(values); const { current: initialValues } = useRef(values);