Skip to content

Commit

Permalink
Refactored ColophonText
Browse files Browse the repository at this point in the history
  • Loading branch information
jbogdani committed Jan 5, 2025
1 parent c078b9b commit b9a2679
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.7.2] - 2025-01-05
### Changed
- Refactored ColophonText

## [2.7.1] - 2025-01-05
### Changed
- Fixed bug with missing ref attribute
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "paths-atlas",
"version": "2.7.1",
"version": "2.7.2",
"description": "The Archaeological Atlas of Coptic Literature by PAThs, an ERC Advanced funded project",
"bugs": "https://github.com/paths-erc/atlas/issues",
"email": "julian.bogdani@uniroma1.it",
Expand Down
66 changes: 46 additions & 20 deletions src/components/Record/ColophonText.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,51 @@ const formatColophon = (xml) => {
return allParagraphs;
}

/**
* Component to render a single colophon text item.
* @param {Object} props - The properties object.
* @param {Object} props.paragraph - The colophon text item.
* @returns {JSX.Element} The rendered colophon text item.
*/
const ColophonTextItem = ({ paragraph }) => (
<React.Fragment>
{paragraph.fol && <small>fol. {paragraph.fol}</small>}
<ol className='colophons'>
{paragraph.content.split('\n').map((line, key) => (
<li key={key} dangerouslySetInnerHTML={{ __html: line.trim() }} />
))}
</ol>
</React.Fragment>
);

export default function ColophonText(props) {
/**
* Component to render the colophon text.
* @param {Object} props - The properties object.
* @param {string} props.clph - The colophon identifier.
* @param {Array} props.clphText - The colophon text data.
* @returns {JSX.Element} The rendered colophon text.
*/
const ColophonText = ({ clph, clphText }) => {
if (!clphText) {
return <Loading>Loading the marked text of the colophon #{clph}</Loading>;
}

return (
<div>
{clphText.map((p, k) => (
<ColophonTextItem key={k} paragraph={p} />
))}
</div>
);
};

/**
* Wrapper component to fetch and manage the state of the colophon text.
* @param {Object} props - The properties object.
* @param {number} props.colophon - The id of the colohpon to fetch.
* @returns {JSX.Element} The rendered colophon text wrapper.
*/
export default function ColophonTextWrapper(props) {

const clph = props.colophon;

Expand All @@ -55,27 +98,10 @@ export default function ColophonText(props) {


if (errorText) {
return <div className='text-danger'>{errorText}</div>;
return <div>{errorText}</div>;
}
if (!clphText) {
return <Loading>Loading the marked text of the colophon #{clph}</Loading>;
}


return (
<div>
{
clphText.map((p, k) => {
return <React.Fragment key={k}>
{p.fol && <small>fol. {p.fol}</small>}
<ol className='colophons'>
{p.content.split('\n').map((line, key) => {
return <li key={key} dangerouslySetInnerHTML={{ __html: line.trim() }} />
})}
</ol>
</React.Fragment>
})
}
</div>
<ColophonText clph={clph} clphText={clphText} />
);
}

0 comments on commit b9a2679

Please sign in to comment.