[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>
{/* Description */}
<ResumeExpandableText>{comment.description}</ResumeExpandableText>
<ResumeExpandableText text={comment.description} />
{/* Upvote and edit */}
<div className="flex flex-row space-x-1 pt-1 align-middle">

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

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

Loading…
Cancel
Save