Skip to content

Commit

Permalink
yesididntneedthatfix
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoMadera committed Sep 4, 2023
1 parent 78b4897 commit bdade79
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 4 additions & 3 deletions utils/applyLyricLinePositionAndColor.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { findIndexOrLast } from "./findIndexOrLast";
import {
LINE_HEIGHT,
LYRICS_PADDING_LEFT,
Expand All @@ -14,9 +15,9 @@ export function applyLyricLinePositionAndColor(
containerHeight: number
): void {
const containerMiddle = containerHeight / 2;
const currentLineIndex = Math.max(
allLines.findIndex((line) => line.type === "current"),
allLines.length - 1
const currentLineIndex = findIndexOrLast(
allLines,
(line) => line.type === "current"
);

allLines.forEach((line, index) => {
Expand Down
7 changes: 7 additions & 0 deletions utils/findIndexOrLast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function findIndexOrLast<T>(
arr: T[],
predicate: (element: T) => boolean
): number {
const index = arr.findIndex(predicate);
return index !== -1 ? index : arr.length - 1;
}

0 comments on commit bdade79

Please sign in to comment.