From 093b049ad2a6f434d4efd887af6987ad849fd561 Mon Sep 17 00:00:00 2001 From: nebojsajsimic <6024893+nebojsajsimic@users.noreply.github.com> Date: Tue, 28 Jan 2025 16:46:13 +0100 Subject: [PATCH 1/2] Limit Character Count for Forum Proposals and Add "Read More" Icon #2649 --- .../SingleGovernanceAction/index.jsx | 211 ++++++++++-------- 1 file changed, 122 insertions(+), 89 deletions(-) diff --git a/pdf-ui/src/pages/ProposedGovernanceActions/SingleGovernanceAction/index.jsx b/pdf-ui/src/pages/ProposedGovernanceActions/SingleGovernanceAction/index.jsx index 6b612b6..436d90f 100644 --- a/pdf-ui/src/pages/ProposedGovernanceActions/SingleGovernanceAction/index.jsx +++ b/pdf-ui/src/pages/ProposedGovernanceActions/SingleGovernanceAction/index.jsx @@ -138,7 +138,19 @@ const SingleGovernanceAction = ({ id }) => { const handleShareClick = (event) => { setShareAnchorEl(event.currentTarget); }; - + // Read More / Read Less logic + const [showFullText, setShowFullText] = useState(false); + const [truncatedText, setTruncatedText] = useState(''); + const [totalCharLength, setTotalCharLength] = useState(0); + const [AbstractMarkdownText, setAbstractMarkdownText] = useState(''); + const maxLength = 500; + useEffect(() => { + if (maxLength && AbstractMarkdownText.length > maxLength) { + setTruncatedText(AbstractMarkdownText.slice(0, maxLength) + '...'); + } else { + setTruncatedText(AbstractMarkdownText); + } + }, [AbstractMarkdownText, maxLength]); const handleShareClose = () => { setShareAnchorEl(null); }; @@ -189,6 +201,12 @@ const SingleGovernanceAction = ({ id }) => { return navigate('/proposal_discussion'); } setProposal(response); + + if(response?.attributes?.content?.attributes?.prop_abstract.length + response?.attributes?.content?.attributes?.prop_motivation.length + response?.attributes?.content?.attributes?.prop_rationale.length > 500) + { + setTotalCharLength(response?.attributes?.content?.attributes?.prop_abstract.length + response?.attributes?.content?.attributes?.prop_motivation.length + response?.attributes?.content?.attributes?.prop_rationale.length); + setAbstractMarkdownText(response?.attributes?.content?.attributes?.prop_abstract); + } } catch (error) { if ( error?.response?.data?.error?.details === @@ -1029,96 +1047,111 @@ const SingleGovernanceAction = ({ id }) => { > Abstract - - {children} - - ); - }, - }} - > - {proposal?.attributes?.content - ?.attributes?.prop_abstract || ''} - - - - - theme?.palette?.text?.grey, - }} - > - Motivation - - - {children} - - ); - }, - }} - > - {proposal?.attributes?.content - ?.attributes?.prop_motivation || ''} - - - - - theme?.palette?.text?.grey, - }} - > - Rationale - - - {children} - - ); - }, - }} - > - {proposal?.attributes?.content - ?.attributes?.prop_rationale || ''} + + {showFullText || !maxLength ? AbstractMarkdownText : truncatedText} + + + {!showFullText && maxLength && totalCharLength > maxLength && ( + )} - + {showFullText && ( + <> + + theme?.palette?.text?.grey, + }} + > + Motivation + + + {children} + + ); + }, + }} + > + {proposal?.attributes?.content + ?.attributes?.prop_motivation || ''} + + + + theme?.palette?.text?.grey, + }} + > + Rationale + + + {children} + + ); + }, + }} + > + {proposal?.attributes?.content + ?.attributes?.prop_rationale || ''} + + + + + )} {proposal?.attributes?.content?.attributes ?.proposal_links?.length > 0 && ( From 6becb5fb5183003b291ad65559c720c5dd71f99d Mon Sep 17 00:00:00 2001 From: nebojsajsimic <6024893+nebojsajsimic@users.noreply.github.com> Date: Tue, 28 Jan 2025 16:53:17 +0100 Subject: [PATCH 2/2] Version update --- pdf-ui/CHANGELOG.md | 5 +++++ pdf-ui/package-lock.json | 2 +- pdf-ui/package.json | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pdf-ui/CHANGELOG.md b/pdf-ui/CHANGELOG.md index aed6f1b..b5490c4 100644 --- a/pdf-ui/CHANGELOG.md +++ b/pdf-ui/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 As a minor extension, we also keep a semantic version for the `UNRELEASED` changes. + +## [v0.5.9](https://www.npmjs.com/package/@intersect.mbo/pdf-ui/v/0.5.9) 2025-01-28 +### Fixed +- Added "Read More" on proposal page if Character Count is bigger den 500 [Issue #2649](https://github.com/IntersectMBO/govtool/issues/2649) + ## [v0.5.8](https://www.npmjs.com/package/@intersect.mbo/pdf-ui/v/0.5.8) 2025-01-27 ### Added - ### Fixed diff --git a/pdf-ui/package-lock.json b/pdf-ui/package-lock.json index b715d7b..26337c0 100644 --- a/pdf-ui/package-lock.json +++ b/pdf-ui/package-lock.json @@ -1,6 +1,6 @@ { "name": "@intersect.mbo/pdf-ui", - "version": "0.5.8", + "version": "0.5.9", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/pdf-ui/package.json b/pdf-ui/package.json index ac0635b..bee4c70 100644 --- a/pdf-ui/package.json +++ b/pdf-ui/package.json @@ -1,6 +1,6 @@ { "name": "@intersect.mbo/pdf-ui", - "version": "0.5.8", + "version": "0.5.9", "description": "Proposal discussion ui", "main": "./src/index.js", "exports": {