From fc82286f610d6e085ab5487123158e6cbca57019 Mon Sep 17 00:00:00 2001 From: an-lee Date: Thu, 28 Mar 2024 16:19:40 +0800 Subject: [PATCH] handle undefined --- .../components/medias/media-caption.tsx | 131 +++++++++--------- 1 file changed, 62 insertions(+), 69 deletions(-) diff --git a/enjoy/src/renderer/components/medias/media-caption.tsx b/enjoy/src/renderer/components/medias/media-caption.tsx index d5fbfcc8..35ed5360 100644 --- a/enjoy/src/renderer/components/medias/media-caption.tsx +++ b/enjoy/src/renderer/components/medias/media-caption.tsx @@ -82,7 +82,7 @@ export const MediaCaption = () => { setActiveRegion(region); } - activeRegion.remove(); + activeRegion?.remove(); } else if (activeRegion.id.startsWith("meaning-group-region")) { setActiveRegion( regions.getRegions().find((r) => r.id.startsWith("segment-region")) @@ -277,81 +277,74 @@ export const MediaCaption = () => { {/* use the words splitted by caption text if it is matched with the timeline length, otherwise use the timeline */} {caption.text.split(" ").length !== caption.timeline.length ? (caption.timeline || []).map((w, index) => ( -
toggleRegion(index)} - > -
-
- {w.text} -
- {displayIpa && ( -
- {w.timeline - .map((t) => - t.timeline - .map((s) => convertIpaToNormal(s.text)) - .join("") - ) - .join(" · ")} -
- )} + onClick={() => toggleRegion(index)} + > +
+
+ {w.text}
+ {displayIpa && ( +
+ {w.timeline + .map((t) => + t.timeline + .map((s) => convertIpaToNormal(s.text)) + .join("") + ) + .join(" · ")} +
+ )}
- )) +
+ )) : caption.text.split(" ").map((word, index) => ( -
toggleRegion(index)} - > -
-
- {word} -
- {displayIpa && ( -
- {caption.timeline[index].timeline - .map((t) => - t.timeline - .map((s) => convertIpaToNormal(s.text)) - .join("") - ) - .join(" · ")} -
- )} + onClick={() => toggleRegion(index)} + > +
+
+ {word}
+ {displayIpa && ( +
+ {caption.timeline[index].timeline + .map((t) => + t.timeline + .map((s) => convertIpaToNormal(s.text)) + .join("") + ) + .join(" · ")} +
+ )}
- ))} +
+ ))}