mirror of
https://github.com/RealKai42/qwerty-learner.git
synced 2026-04-05 14:29:04 +08:00
fix: add workaround if word.trans is not an array of string
This commit is contained in:
@@ -321,7 +321,9 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "stun",
|
"name": "stun",
|
||||||
"trans": "使震惊,使晕倒;给(某人)以深刻印象,使深深感动",
|
"trans": [
|
||||||
|
"使震惊,使晕倒;给(某人)以深刻印象,使深深感动"
|
||||||
|
],
|
||||||
"usphone": "stʌn",
|
"usphone": "stʌn",
|
||||||
"ukphone": "stʌn"
|
"ukphone": "stʌn"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -35,8 +35,21 @@ export function useWordList(): UseWordListResult {
|
|||||||
? wordList.slice(currentChapter * CHAPTER_LENGTH, (currentChapter + 1) * CHAPTER_LENGTH)
|
? wordList.slice(currentChapter * CHAPTER_LENGTH, (currentChapter + 1) * CHAPTER_LENGTH)
|
||||||
: []
|
: []
|
||||||
|
|
||||||
// 记录原始 index
|
return newWords.map((word, index) => {
|
||||||
return newWords.map((word, index) => ({ ...word, index }))
|
let trans: string[]
|
||||||
|
if (Array.isArray(word.trans)) {
|
||||||
|
trans = word.trans.filter((item) => typeof item === 'string')
|
||||||
|
} else if (word.trans === null || word.trans === undefined || typeof word.trans === 'object') {
|
||||||
|
trans = []
|
||||||
|
} else {
|
||||||
|
trans = [String(word.trans)]
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...word,
|
||||||
|
index,
|
||||||
|
trans,
|
||||||
|
}
|
||||||
|
})
|
||||||
}, [isFirstChapter, wordList, currentChapter])
|
}, [isFirstChapter, wordList, currentChapter])
|
||||||
|
|
||||||
return { words: wordList === undefined ? undefined : words, isLoading, error }
|
return { words: wordList === undefined ? undefined : words, isLoading, error }
|
||||||
|
|||||||
Reference in New Issue
Block a user