From 1e274d0e527cbc9ad281b898035180934853acc3 Mon Sep 17 00:00:00 2001 From: lovegaoshi <106490582+lovegaoshi@users.noreply.github.com> Date: Fri, 15 Mar 2024 06:02:17 -0700 Subject: [PATCH] fix: resolved lrc mapping catch updateLyricMapping expecting lrcOption to be updated via setLrcOption, but state wont be refreshed during func call cycle. passing it as a param instead. --- package.json | 2 +- src/components/player/Lyric.tsx | 29 +++++++++++++++-------------- yarn.lock | 8 ++++---- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index 1939d917..ecaf8869 100644 --- a/package.json +++ b/package.json @@ -125,7 +125,7 @@ "@types/he": "^1.2.3", "@types/jest": "^29.5.12", "@types/md5": "^2.3.5", - "@types/node": "^20.11.26", + "@types/node": "^20.11.27", "@types/react": "^18.2.65", "@types/react-native": "^0.73.0", "@types/react-native-background-timer": "^2.0.2", diff --git a/src/components/player/Lyric.tsx b/src/components/player/Lyric.tsx index 32cba120..a214c189 100644 --- a/src/components/player/Lyric.tsx +++ b/src/components/player/Lyric.tsx @@ -105,9 +105,8 @@ export const LyricView = ({ logger.debug('[lrc] read local lrc and loading...'); setLrc(readlrc); return true; - } else if (lrcDetail.lyric.endsWith('.txt')) { - logger.debug('[lrc] local lrc no longer exists, fetching new...'); } + logger.debug('[lrc] local lrc no longer exists, fetching new...'); searchAndSetCurrentLyric(0, await lyricPromise, lrcKey); return true; } @@ -143,15 +142,19 @@ export const LyricView = ({ return lyricMapping.has(track?.song?.id); }; - const updateLyricMapping = ( - newLrcDetail: Partial = {} - ) => { - if (lrcOption !== null && lrcOption !== undefined) { + const updateLyricMapping = ({ + resolvedLrc = lrcOption, + newLrcDetail = {}, + }: { + resolvedLrc?: NoxNetwork.NoxFetchedLyric; + newLrcDetail?: Partial; + }) => { + if (resolvedLrc !== null && resolvedLrc !== undefined) { const lrcpath = `${track.song.id}.txt`; writeTxtFile(lrcpath, [newLrcDetail.lyric || lrc], 'lrc/'); const lyricDeatail: NoxMedia.LyricDetail = { songId: track.song.id, - lyricKey: lrcOption.key, + lyricKey: resolvedLrc.key, lyricOffset: currentTimeOffset, ...newLrcDetail, lyric: lrcpath, @@ -165,7 +168,7 @@ export const LyricView = ({ ? currentTimeOffset + LYRIC_OFFSET_INTERVAL : currentTimeOffset - LYRIC_OFFSET_INTERVAL; setCurrentTimeOffset(newTimeOffset); - updateLyricMapping({ lyricOffset: newTimeOffset }); + updateLyricMapping({ newLrcDetail: { lyricOffset: newTimeOffset } }); }; const fetchAndSetLyricOptions = async (adhocTitle?: string) => { @@ -194,12 +197,10 @@ export const LyricView = ({ console.debug(`lrcoptions: ${JSON.stringify(resolvedLrcOptions)}`); if (resolvedLrcOptions.length === 0) setLrc('无法找到歌词,请手动搜索...'); else { - const lyric = await searchLyric( - lyricMid || resolvedLrcOptions[index!].songMid, - setLrc - ); - setLrcOption(resolvedLrcOptions[index!]); - updateLyricMapping({ lyric }); + const resolvedLrc = resolvedLrcOptions[index!]; + const lyric = await searchLyric(lyricMid || resolvedLrc.songMid, setLrc); + setLrcOption(resolvedLrc); + updateLyricMapping({ newLrcDetail: { lyric }, resolvedLrc }); } }; diff --git a/yarn.lock b/yarn.lock index a3201418..708e8181 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3981,10 +3981,10 @@ dependencies: undici-types "~5.26.4" -"@types/node@^20.11.26": - version "20.11.26" - resolved "https://registry.npmjs.org/@types/node/-/node-20.11.26.tgz#3fbda536e51d5c79281e1d9657dcb0131baabd2d" - integrity sha512-YwOMmyhNnAWijOBQweOJnQPl068Oqd4K3OFbTc6AHJwzweUwwWG3GIFY74OKks2PJUDkQPeddOQES9mLn1CTEQ== +"@types/node@^20.11.27": + version "20.11.27" + resolved "https://registry.npmjs.org/@types/node/-/node-20.11.27.tgz#debe5cfc8a507dd60fe2a3b4875b1604f215c2ac" + integrity sha512-qyUZfMnCg1KEz57r7pzFtSGt49f6RPkPBis3Vo4PbS7roQEDn22hiHzl/Lo1q4i4hDEgBJmBF/NTNg2XR0HbFg== dependencies: undici-types "~5.26.4"