From 3e4fddad98e0027c8aa9d095bee071c22e716f42 Mon Sep 17 00:00:00 2001 From: Pihkaal Date: Thu, 30 May 2024 20:29:37 +0200 Subject: [PATCH] feat(cava): display smallest bar if value is 0 --- src/components/Music/Cava.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/Music/Cava.tsx b/src/components/Music/Cava.tsx index bbf4798..fa2d444 100644 --- a/src/components/Music/Cava.tsx +++ b/src/components/Music/Cava.tsx @@ -46,12 +46,17 @@ const FrequencyBar = (props: { const emptyBlocksCount = props.height - fullBlocksCount - (remainderIndex > 0 ? 1 : 0); - bar += `${" ".repeat(WIDTH)}\n`.repeat(Math.max(emptyBlocksCount, 0)); + if (remainderIndex === 0 && fullBlocksCount === 0) { + bar += `${" ".repeat(WIDTH)}\n`.repeat(Math.max(emptyBlocksCount - 1, 0)); + bar += GRADIENT[0].repeat(WIDTH); + } else { + bar += `${" ".repeat(WIDTH)}\n`.repeat(Math.max(emptyBlocksCount, 0)); - if (remainderIndex > 0) { - bar += `${GRADIENT[remainderIndex]!.repeat(WIDTH)}\n`; + if (remainderIndex > 0) { + bar += `${GRADIENT[remainderIndex]!.repeat(WIDTH)}\n`; + } + bar += `${FULL_BLOCK.repeat(WIDTH)}\n`.repeat(fullBlocksCount); } - bar += `${FULL_BLOCK.repeat(WIDTH)}\n`.repeat(fullBlocksCount); return {bar}; };