refactor: remove redundant calls for getCurrentUser

This commit is contained in:
Prayag Prajapati committed 2024-09-25 20:35:38 +05:30
1 parent e82ff1ff0c
commit 647dcc3690
35 files changed
+651 -690

No files matched your search

+63
View File
@@ -0,0 +1,63 @@
import Button from "@mui/material/Button";
import Typography from "@mui/material/Typography";
import { useEffect, useRef, useState } from "react";
const ShowMoreText = ({
content,
collapsedLines,
extraProps,
}: { content: string; collapsedLines: number; extraProps?: unknown }) => {
const [displayFull, setDisplayFull] = useState(false);
const [isOverflowing, setIsOverflowing] = useState(false);
const textRef = useRef(null);
useEffect(() => {
if (textRef.current) {
if (textRef.current.offsetHeight < textRef.current.scrollHeight) {
setIsOverflowing(true);
} else {
setIsOverflowing(false);
}
// textRef.current.
}
}, []);
return (
<div
className="flex flex-column"
{...extraProps}
style={{
alignItems: "flex-end",
gap: "1em",
opacity: 0.8,
}}
>
<Typography
ref={textRef}
key={displayFull}
style={{
display: "-webkit-box",
textOverflow: "ellipsis",
overflow: "hidden",
WebkitLineClamp: displayFull ? "none" : (collapsedLines ?? 2),
WebkitBoxOrient: "vertical",
width: "100%",
}}
variant="subtitle2"
fontWeight={300}
>
{content}
</Typography>
{content.length > 0 && isOverflowing && (
<Button
color="white"
variant="outlined"
onClick={() => setDisplayFull((state) => !state)}
// key={displayFull}
>
{displayFull ? "Show less" : "Show more"}
</Button>
)}
</div>
);
};
export default ShowMoreText;