Skip to content

Commit

Permalink
refactor: prettier CurrentReading implementation, no full sentence hi…
Browse files Browse the repository at this point in the history
…ghlight
  • Loading branch information
fhenrich33 committed Apr 9, 2024
1 parent 9a99337 commit b4d9302
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/components/CurrentlyReading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@ export const CurrentlyReading = ({
currentSentenceIdx: number;
sentences: string[];
}) => {
const [headRange, tailRange] = currentWordRange;

const currentWord = sentences.length
? sentences[currentSentenceIdx].slice(
currentWordRange[0],
currentWordRange[1]
)
? sentences[currentSentenceIdx].slice(headRange, tailRange)
: "";

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

const sentenceHead = currentSentence.substring(0, currentWordRange[0]);
const sentenceHead = currentSentence.substring(0, headRange);
const sentenceTail = currentSentence.substring(
currentWordRange[1],
tailRange,
currentSentence.length
);

const currentContent = `${sentenceHead}<span data-testid="current-word" style="color: red">${currentWord}</span>${sentenceTail}`;
const currentContent =
currentSentence === currentWord
? currentSentence
: `${sentenceHead}<span data-testid="current-word" style="color: red">${currentWord}</span>${sentenceTail}`;

return (
<div data-testid="currently-reading">
Expand Down

0 comments on commit b4d9302

Please sign in to comment.