Skip to content

Commit

Permalink
fix(lyric): optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
Su-Yong committed Feb 26, 2024
1 parent beecd44 commit 912c4b7
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions renderer/hooks/useLyric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const useLyric = () => {

const lastIter = () => {
const tempLyrics = lyrics();
if (tempLyrics === null) return null;
if (tempLyrics === null || tempLyrics.size() === 0) return null;

const mapper = lyricMapper()[getLyricMapperId(title(), coverUrl())];
const delay = mapper?.delay ?? 0;
Expand All @@ -38,8 +38,8 @@ const useLyric = () => {
return last;
};

const lyric = createMemo(() => lastIter()?.value ? lastIter()?.second : null);
const index = createMemo(() => lastIter()?.value ? lastIter()?.first : null);
const lyric = createMemo(() => lastIter()?.second);
const index = createMemo(() => lastIter()?.first);

const nextLyricsIter = createMemo(() => {
let nextLyricLength = style().lyric.nextLyric;
Expand All @@ -61,7 +61,7 @@ const useLyric = () => {

const getPreviousLyricLength = createMemo(() => {
let previousLyricLength = style().lyric.previousLyric;

const now = lastIter();
const tempLyrics = lyrics();

Expand Down Expand Up @@ -94,11 +94,11 @@ const useLyric = () => {
});
const lyricRange = createMemo(() => {
const now = lastIter();
if (!now || now.value === undefined) return null;
if (!now) return null;

const prevIter = previousLyricsIter() ?? now;
const nextIter = nextLyricsIter() ?? now;

if (prevIter.equals(nextIter)) return [now.second];

const result: string[][] = [];
Expand All @@ -108,7 +108,7 @@ const useLyric = () => {
if (nextIter.equals(now)) {
result.push(now.second);
}

return result;
});

Expand Down

0 comments on commit 912c4b7

Please sign in to comment.