Skip to content

Commit

Permalink
feat: highlight current word being read
Browse files Browse the repository at this point in the history
  • Loading branch information
fhenrich33 committed Apr 8, 2024
1 parent 4439dc7 commit 53dd51d
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/components/CurrentlyReading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,25 @@ export const CurrentlyReading = ({
currentWordRange[1]
)
: "";

const currentSentence = sentences.length ? sentences[currentSentenceIdx] : "";

const currentContent = currentSentence
.split("")
.toSpliced(
currentWordRange[0],
currentWordRange[1],
`<span data-testid="current-word" style="color: red">${currentWord}</span>`
)
.join("");

return (
<div data-testid="currently-reading">
<span data-testid="current-word">{currentWord}</span>
<p data-testid="current-sentence">{currentSentence}</p>
<p
data-testid="current-sentence"
dangerouslySetInnerHTML={{ __html: currentContent }}
></p>
<p>{sentences.join(" ")}</p>
</div>
);
};

0 comments on commit 53dd51d

Please sign in to comment.