From 911b3729e17c2b083c0cfc44b7e67c37838da4ea Mon Sep 17 00:00:00 2001 From: devilkiller-ag Date: Wed, 27 Mar 2024 12:28:37 +0530 Subject: [PATCH] added comments: --- components/tools/ToolsCard.tsx | 174 +++++++++++++++++++++------------ 1 file changed, 109 insertions(+), 65 deletions(-) diff --git a/components/tools/ToolsCard.tsx b/components/tools/ToolsCard.tsx index 7a724f6a391..ccac6654a36 100644 --- a/components/tools/ToolsCard.tsx +++ b/components/tools/ToolsCard.tsx @@ -1,7 +1,10 @@ import { useEffect, useRef, useState } from 'react'; import TextTruncate from 'react-text-truncate'; -import type { ToolData, VisibleDataListType } from '@/types/components/tools/ToolDataType'; +import type { + ToolData, + VisibleDataListType, +} from '@/types/components/tools/ToolDataType'; import { HeadingTypeStyle } from '@/types/typography/Heading'; import { ParagraphTypeStyle } from '@/types/typography/Paragraph'; @@ -23,10 +26,12 @@ interface ToolsCardProp { */ export default function ToolsCard({ toolData }: ToolsCardProp) { const [showDescription, setShowDescription] = useState(false); - const [showMoreDescription, setShowMoreDescription] = useState(false); + const [showMoreDescription, setShowMoreDescription] = + useState(false); const [readMore, setReadMore] = useState(false); const descriptionRef = useRef(null); + // Decide whether to show full description or not in the card based on the number of lines occupied by the description. useEffect(() => { const divHeight = descriptionRef.current?.offsetHeight || 0; const numberOfLines = divHeight / 20; @@ -53,17 +58,19 @@ export default function ToolsCard({ toolData }: ToolsCardProp) { const [visible, setVisible] = useState({ lang: false, tech: false, - desc: false + desc: false, }); return ( -
-
-
-
- {toolData.title} +
+
+
+
+ + {toolData.title} +
setTimeout(() => { if (!visible.desc) setVisible({ ...visible, desc: true }); @@ -71,23 +78,28 @@ export default function ToolsCard({ toolData }: ToolsCardProp) { } > setTimeout(() => { if (visible.desc) setVisible({ ...visible, desc: false }); }, 300) } > - {toolData.filters?.hasCommercial === false ? 'Open Source' : 'Commercial'} + {toolData.filters?.hasCommercial === false + ? 'Open Source' + : 'Commercial'} {visible.desc && ( - - {Data.properties.filters.properties.hasCommercial.description} + + { + Data.properties.filters.properties.hasCommercial + .description + } )}
-
+
- +
{showDescription && (
setShowDescription(false)} > - + {toolData.description}
@@ -114,89 +130,109 @@ export default function ToolsCard({ toolData }: ToolsCardProp) {
-
-
+
+
{toolData.filters?.language || toolData?.filters?.technology?.length ? ( -
+
{toolData.filters.language && ( -
+
-
+
{toolData.filters?.language && toolData.filters?.language.map((item, index) => ( - + ))}
)} {toolData.filters?.technology?.length && ( -
+
-
+
{toolData.filters?.technology && toolData.filters.technology.map((item, index) => ( - + ))}
)}
) : ( -
-
+
+
{' '} No further details provided{' '}
)}
- {(toolData?.links?.repoUrl || toolData?.links?.websiteUrl || toolData?.links?.docsUrl) && ( + {(toolData?.links?.repoUrl || + toolData?.links?.websiteUrl || + toolData?.links?.docsUrl) && ( <> -
-
+
+
{toolData.links.repoUrl && ( <> {onGit ? ( -
- GitHub -
View Github
+
+ GitHub +
View Github
) : ( -
-
View Source Code
+
+
+ View Source Code +
)} @@ -204,29 +240,37 @@ export default function ToolsCard({ toolData }: ToolsCardProp) { )} {toolData.links.websiteUrl && ( -