diff --git a/src/components/flow/Cell/index.tsx b/src/components/flow/Cell/index.tsx index 71454949..b3ee8664 100644 --- a/src/components/flow/Cell/index.tsx +++ b/src/components/flow/Cell/index.tsx @@ -1,22 +1,22 @@ -import React, { FC, useState, useCallback, useEffect, useRef } from "react"; -import { INode } from "~/redux/types"; -import { getURL, formatCellText } from "~/utils/dom"; -import classNames from "classnames"; +import React, { FC, useState, useCallback, useEffect, useRef } from 'react'; +import { INode } from '~/redux/types'; +import { getURL, formatCellText } from '~/utils/dom'; +import classNames from 'classnames'; -import * as styles from "./styles.scss"; -import { Icon } from "~/components/input/Icon"; -import { flowSetCellView } from "~/redux/flow/actions"; -import { PRESETS } from "~/constants/urls"; -import { debounce } from "throttle-debounce"; -import { NODE_TYPES } from "~/redux/node/constants"; -import { Group } from "~/components/containers/Group"; +import * as styles from './styles.scss'; +import { Icon } from '~/components/input/Icon'; +import { flowSetCellView } from '~/redux/flow/actions'; +import { PRESETS } from '~/constants/urls'; +import { debounce } from 'throttle-debounce'; +import { NODE_TYPES } from '~/redux/node/constants'; +import { Group } from '~/components/containers/Group'; interface IProps { node: INode; is_text?: boolean; can_edit?: boolean; - onSelect: (id: INode["id"], type: INode["type"]) => void; + onSelect: (id: INode['id'], type: INode['type']) => void; onChangeCellView: typeof flowSetCellView; } @@ -24,7 +24,7 @@ const Cell: FC = ({ node: { id, title, thumbnail, type, flow, description }, can_edit, onSelect, - onChangeCellView + onChangeCellView, }) => { const ref = useRef(null); const [is_loaded, setIsLoaded] = useState(false); @@ -35,16 +35,14 @@ const Cell: FC = ({ const { top, height } = ref.current.getBoundingClientRect(); - const visibility = - top + height > -window.innerHeight && top < window.innerHeight * 2; + const visibility = top + height > -window.innerHeight && top < window.innerHeight * 2; if (visibility !== is_visible) setIsVisible(visibility); }, [ref, is_visible, setIsVisible]); - const checkIfVisibleDebounced = useCallback( - debounce(Math.random() * 200, checkIfVisible), - [checkIfVisible] - ); + const checkIfVisibleDebounced = useCallback(debounce(Math.random() * 200, checkIfVisible), [ + checkIfVisible, + ]); useEffect(() => { checkIfVisible(); @@ -52,13 +50,13 @@ const Cell: FC = ({ useEffect(() => { // recalc visibility of other elements - window.dispatchEvent(new CustomEvent("scroll")); + window.dispatchEvent(new CustomEvent('scroll')); }, [flow]); useEffect(() => { - window.addEventListener("scroll", checkIfVisibleDebounced); + window.addEventListener('scroll', checkIfVisibleDebounced); - return () => window.removeEventListener("scroll", checkIfVisibleDebounced); + return () => window.removeEventListener('scroll', checkIfVisibleDebounced); }, [checkIfVisibleDebounced]); const onImageLoad = useCallback(() => { @@ -75,38 +73,32 @@ const Cell: FC = ({ const toggleViewDescription = useCallback(() => { const show_description = !(flow && flow.show_description); - const display = (flow && flow.display) || "single"; + const display = (flow && flow.display) || 'single'; onChangeCellView(id, { show_description, display }); }, [id, flow, onChangeCellView]); const setViewSingle = useCallback(() => { const show_description = (flow && !!flow.show_description) || false; - onChangeCellView(id, { show_description, display: "single" }); + onChangeCellView(id, { show_description, display: 'single' }); }, [id, flow, onChangeCellView]); const setViewHorizontal = useCallback(() => { const show_description = (flow && !!flow.show_description) || false; - onChangeCellView(id, { show_description, display: "horizontal" }); + onChangeCellView(id, { show_description, display: 'horizontal' }); }, [id, flow, onChangeCellView]); const setViewVertical = useCallback(() => { const show_description = (flow && !!flow.show_description) || false; - onChangeCellView(id, { show_description, display: "vertical" }); + onChangeCellView(id, { show_description, display: 'vertical' }); }, [id, flow, onChangeCellView]); const setViewQuadro = useCallback(() => { const show_description = (flow && !!flow.show_description) || false; - onChangeCellView(id, { show_description, display: "quadro" }); + onChangeCellView(id, { show_description, display: 'quadro' }); }, [id, flow, onChangeCellView]); return ( -
+
{is_visible && ( <> {can_edit && ( @@ -136,9 +128,7 @@ const Cell: FC = ({
{title &&
{title}
} - +
)} @@ -146,9 +136,7 @@ const Cell: FC = ({
{title &&
{title}
} - +
)}
@@ -158,18 +146,11 @@ const Cell: FC = ({
- +
)} diff --git a/src/utils/dom.ts b/src/utils/dom.ts index cc866b6b..6dc5c09d 100644 --- a/src/utils/dom.ts +++ b/src/utils/dom.ts @@ -122,7 +122,7 @@ export const splitCommentByBlocks = (text: string): ICommentBlock[] => export const formatCommentText = (author: string, text: string): ICommentBlock[] => text ? splitCommentByBlocks(formatText(text)) : null; -export const formatCellText = (text: string): string => formatText(text); +export const formatCellText = (text: string): string => formatTextParagraphs(formatText(text)); export const getPrettyDate = (date: string): string => { if (differenceInMonths(new Date(), new Date(date)) >= 3) {