-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #551 from bounswe/feature/FE-annotation
Add annotation and filter posts by tags
- Loading branch information
Showing
7 changed files
with
354 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
export const renderContentWithAnnotations = (content, annotations) => { | ||
let annotatedContent = []; | ||
let currentIndex = 0; | ||
|
||
annotations | ||
.sort((a, b) => a.start - b.start) // Ensure ascending order | ||
.forEach(({ start, end, value, username, creationDate }, idx) => { | ||
console.log(`Processing annotation ${idx}:`, { start, end, value }); | ||
|
||
// Add text before annotation | ||
if (currentIndex < start) { | ||
annotatedContent.push( | ||
<span key={`plain-${idx}`}>{content.slice(currentIndex, start)}</span> | ||
); | ||
} | ||
|
||
// Add the annotated text itself | ||
if (start < end && end <= content.length) { | ||
annotatedContent.push( | ||
<span | ||
key={`annotation-${idx}`} | ||
className="annotated-text" | ||
title={`${value}\nBy: ${username}\nOn: ${creationDate}`} | ||
> | ||
{content.slice(start, end)} | ||
</span> | ||
); | ||
} | ||
|
||
currentIndex = Math.max(currentIndex, end); | ||
}); | ||
|
||
// Add the remaining content after last annotation | ||
if (currentIndex < content.length) { | ||
annotatedContent.push( | ||
<span key="remainder">{content.slice(currentIndex)}</span> | ||
); | ||
} | ||
|
||
return annotatedContent; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.