// Copyright 2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React, { useEffect, useRef, useState } from 'react'; import { Modal } from '../Modal'; import { LocalizerType } from '../../types/Util'; import { GroupDescriptionText } from '../GroupDescriptionText'; // Emojification can cause the scroll height to be *slightly* larger than the client // height, so we add a little wiggle room. const SHOW_READ_MORE_THRESHOLD = 5; export type PropsType = { i18n: LocalizerType; title: string; text: string; }; export const GroupDescription = ({ i18n, title, text, }: PropsType): JSX.Element => { const textRef = useRef(null); const [hasReadMore, setHasReadMore] = useState(false); const [showFullDescription, setShowFullDescription] = useState(false); useEffect(() => { if (!textRef || !textRef.current) { return; } setHasReadMore( textRef.current.scrollHeight - SHOW_READ_MORE_THRESHOLD > textRef.current.clientHeight ); }, [setHasReadMore, text, textRef]); return ( <> {showFullDescription && ( setShowFullDescription(false)} title={title} > )}
{hasReadMore && ( )} ); };