diff --git a/renderer/components/Meaning/MeaningBox.tsx b/renderer/components/Meaning/MeaningBox.tsx
index 0b85642..bfdbe76 100644
--- a/renderer/components/Meaning/MeaningBox.tsx
+++ b/renderer/components/Meaning/MeaningBox.tsx
@@ -45,32 +45,49 @@ const initialCharacterContentState = {literal: null};
const getStarColor = (learningState) => {
return defaultLearningColorStyling.learningColor[learningState].color;
};
+
const MeaningBox = ({
- meaning,
- setMeaning,
- tokenizeMiteiru,
- subtitleStyling = defaultMeaningBoxStyling,
- customComponent = null,
- lang,
- changeLearningState = null,
- getLearningState = null
- }) => {
+ meaning,
+ setMeaning,
+ tokenizeMiteiru,
+ subtitleStyling = defaultMeaningBoxStyling,
+ customComponent = null,
+ lang,
+ changeLearningState = null,
+ getLearningState = null
+}) => {
const [meaningContent, setMeaningContent] = useState(initialContentState);
const [meaningCharacter, setMeaningCharacter] = useState(initialCharacterContentState);
const [otherMeanings, setOtherMeanings] = useState([]);
const [meaningIndex, setMeaningIndex] = useState(0);
const [tags, setTags] = useState({});
const [romajiedData, setRomajiedData] = useState([]);
+
const handleStarClick = useCallback(() => {
changeLearningState(meaning);
}, [changeLearningState, meaning]);
- useEffect(() => {
- if (meaning === '') {
- setMeaningContent(initialContentState);
- setMeaningCharacter(initialCharacterContentState);
- return;
+
+ const handleBGClick = useCallback(() => setMeaning(''), [setMeaning]);
+
+ const handlePrevious = useCallback(() => {
+ if (meaningIndex > 0) {
+ setMeaningIndex(old => {
+ setMeaningContent(otherMeanings[old - 1]);
+ return old - 1;
+ });
+ }
+ }, [meaningIndex, otherMeanings]);
+
+ const handleNext = useCallback(() => {
+ if (meaningIndex < otherMeanings.length - 1) {
+ setMeaningIndex(old => {
+ setMeaningContent(otherMeanings[old + 1]);
+ return old + 1;
+ });
}
+ }, [meaningIndex, otherMeanings]);
+ useEffect(() => {
const fetchCharacterData = async () => {
if (meaning.length === 1) {
if (lang === videoConstants.japaneseLang && isKanji(meaning)) {
@@ -114,25 +131,27 @@ const MeaningBox = ({
setMeaningIndex(0);
};
- fetchCharacterData();
- fetchMeaningData();
+ if (meaning === '') {
+ setMeaningContent(initialContentState);
+ setMeaningCharacter(initialCharacterContentState);
+ } else {
+ fetchCharacterData();
+ fetchMeaningData();
+ }
}, [lang, meaning]);
useEffect(() => {
const fetchRomajiedData = async () => {
- console.log(meaningContent);
if (lang === videoConstants.japaneseLang) {
const data = await Promise.all(
- meaningContent.single.map(async (val) => {
- return ({
- key: val.key,
- romajied: await tokenizeMiteiru(val.text)
- });
- })
+ meaningContent.single.map(async (val) => ({
+ key: val.key,
+ romajied: await tokenizeMiteiru(val.text)
+ }))
);
setRomajiedData(data);
- } else if (lang === videoConstants.cantoneseLang || videoConstants.chineseLang) {
- const usedData = (meaningContent.simplified.includes(meaning)) ? meaningContent.simplified : meaningContent.content;
+ } else if (lang === videoConstants.cantoneseLang || lang === videoConstants.chineseLang) {
+ const usedData = (meaningContent && meaningContent.simplified && meaningContent.simplified.includes(meaning)) ? meaningContent.simplified : meaningContent.content;
const data = [{key: 0, romajied: (await tokenizeMiteiru(usedData))}];
setRomajiedData(data);
}
@@ -141,70 +160,75 @@ const MeaningBox = ({
if (meaningContent.single.length) fetchRomajiedData();
}, [lang, meaning, meaningContent, tokenizeMiteiru]);
- const handleBGClick = useCallback(() => setMeaning(''), [setMeaning]);
-
- const handlePrevious = useCallback(() => {
- if (meaningIndex > 0) {
- setMeaningIndex(old => {
- setMeaningContent(otherMeanings[old - 1]);
- return old - 1;
- });
- }
- }, [meaningIndex, otherMeanings]);
-
- const handleNext = useCallback(() => {
- if (meaningIndex < otherMeanings.length - 1) {
- setMeaningIndex(old => {
- setMeaningContent(otherMeanings[old + 1]);
- return old + 1;
- });
- }
- }, [meaningIndex, otherMeanings]);
+ const renderRomajiedContent = useCallback(() => (
+ romajiedData.map(({key, romajied}) => (
+