[resumes][fix] fix expandable text not updating

pull/386/head
Keane Chan 2 years ago
parent 71838f4ac7
commit 7d1ffb9887
No known key found for this signature in database
GPG Key ID: 32718398E1E9F87C

@ -54,7 +54,7 @@ export default function ResumeCommentListItem({
</div> </div>
{/* Description */} {/* Description */}
<ResumeExpandableText>{comment.description}</ResumeExpandableText> <ResumeExpandableText text={comment.description} />
{/* Upvote and edit */} {/* Upvote and edit */}
<div className="flex flex-row space-x-1 pt-1 align-middle"> <div className="flex flex-row space-x-1 pt-1 align-middle">

@ -1,23 +1,24 @@
import clsx from 'clsx'; import clsx from 'clsx';
import type { ReactNode } from 'react'; import { useEffect, useState } from 'react';
import { useLayoutEffect, useRef, useState } from 'react';
type ResumeExpandableTextProps = Readonly<{ type ResumeExpandableTextProps = Readonly<{
children: ReactNode; text: string;
}>; }>;
export default function ResumeExpandableText({ export default function ResumeExpandableText({
children, text,
}: ResumeExpandableTextProps) { }: ResumeExpandableTextProps) {
const ref = useRef<HTMLSpanElement>(null);
const [isExpanded, setIsExpanded] = useState(false); const [isExpanded, setIsExpanded] = useState(false);
const [descriptionOverflow, setDescriptionOverflow] = useState(false); const [descriptionOverflow, setDescriptionOverflow] = useState(false);
useLayoutEffect(() => { useEffect(() => {
if (ref.current && ref.current.clientHeight < ref.current.scrollHeight) { const lines = text.split(/\r\n|\r|\n/);
if (lines.length > 3) {
setDescriptionOverflow(true); setDescriptionOverflow(true);
} else {
setDescriptionOverflow(false);
} }
}, [ref]); }, [text]);
const onSeeActionClicked = () => { const onSeeActionClicked = () => {
setIsExpanded((prevExpanded) => !prevExpanded); setIsExpanded((prevExpanded) => !prevExpanded);
@ -26,13 +27,11 @@ export default function ResumeExpandableText({
return ( return (
<div> <div>
<span <span
ref={ref}
className={clsx( className={clsx(
'whitespace-pre-wrap text-sm', 'line-clamp-3 whitespace-pre-wrap text-sm',
'line-clamp-3',
isExpanded ? 'line-clamp-none' : '', isExpanded ? 'line-clamp-none' : '',
)}> )}>
{children} {text}
</span> </span>
{descriptionOverflow && ( {descriptionOverflow && (
<p <p

@ -189,9 +189,7 @@ export default function ResumeReviewPage() {
aria-hidden="true" aria-hidden="true"
className="mr-1.5 h-5 w-5 flex-shrink-0 text-gray-400" className="mr-1.5 h-5 w-5 flex-shrink-0 text-gray-400"
/> />
<ResumeExpandableText> <ResumeExpandableText text={detailsQuery.data.additionalInfo} />
{detailsQuery.data.additionalInfo}
</ResumeExpandableText>
</div> </div>
)} )}
<div className="flex w-full flex-col py-4 lg:flex-row"> <div className="flex w-full flex-col py-4 lg:flex-row">

Loading…
Cancel
Save