- {wordReadings?.map(({ id, isPunctuation, text }) => (
+ {wordReadings?.map(({ isPunctuation, text }, wordIdx) => (
{
- scrollWordReadingIntoView(id);
- setSelectedWordId(id);
+ scrollWordReadingIntoView(wordIdx);
+ setSelectedWordIdx(wordIdx);
}}
>
{text}
@@ -215,26 +171,31 @@ const MangaPageView = ({
- {wordReadings
- ?.filter(({ isPunctuation }) => !isPunctuation)
- .map((wordReading, idx) => (
+ {wordReadings?.map((wordReading, wordIdx) =>
+ wordReading.isPunctuation ? null : (
{
- scrollWordReadingIntoView(wordReading.id);
- setSelectedWordId(wordReading.id);
+ scrollWordReadingIntoView(wordIdx);
+ setSelectedWordIdx(wordIdx);
+ }}
+ onAddWordToAnki={() => {
+ console.log(
+ `Adding word to Anki selectedBlockIdx: ${selectedBlockIdx} wordIdx: ${wordIdx}`,
+ );
+ void onAddWordToAnki(selectedBlockIdx!, wordIdx);
}}
ref={(node) => {
- if (node) wordRefs.current.set(wordReading.id, node);
- else wordRefs.current.delete(wordReading.id);
+ if (node) wordRefs.current.set(wordIdx, node);
+ else wordRefs.current.delete(wordIdx);
}}
className={cn(
- selectedWordId === wordReading.id &&
- "border-accent-foreground",
+ selectedWordIdx === wordIdx && "border-accent-foreground",
)}
/>
- ))}
+ ),
+ )}