From d66248cb9733fe5aab310e62acc88290e865e9bf Mon Sep 17 00:00:00 2001 From: Wanjohi <71614375+wanjohiryan@users.noreply.github.com> Date: Thu, 5 Sep 2024 21:30:30 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20Use=20mute=20card=20color?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/ui/src/card.tsx | 74 +++----------------------------- packages/ui/src/home-nav-bar.tsx | 4 +- packages/ui/src/large-card.tsx | 0 3 files changed, 8 insertions(+), 70 deletions(-) create mode 100644 packages/ui/src/large-card.tsx diff --git a/packages/ui/src/card.tsx b/packages/ui/src/card.tsx index 4973f2e2..ed7a29de 100644 --- a/packages/ui/src/card.tsx +++ b/packages/ui/src/card.tsx @@ -1,4 +1,4 @@ -import { component$, useSignal, useVisibleTask$, $ } from "@builder.io/qwik"; +import { component$ } from "@builder.io/qwik"; type Props = { game: { @@ -9,87 +9,25 @@ type Props = { export const Card = component$(({ game }: Props) => { const imageUrl = `http://localhost:8787/image/cover/${game.id}.avif` - const backgroundColor = useSignal(undefined); - const imgRef = useSignal(); - - const extractColor = $((img: HTMLImageElement) => { - const canvas = document.createElement('canvas'); - const ctx = canvas.getContext('2d'); - if (!ctx) return "rgb(200,200,200)"; // Fallback light gray - - canvas.width = img.naturalWidth; - canvas.height = img.naturalHeight; - ctx.drawImage(img, 0, 0, img.naturalWidth, img.naturalHeight); - - const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height).data; - let r = 0, g = 0, b = 0, count = 0; - - for (let i = 0; i < imageData.length; i += 4) { - // Only consider brighter pixels - if (imageData[i] > 150 || imageData[i + 1] > 150 || imageData[i + 2] > 150) { - r += imageData[i]; - g += imageData[i + 1]; - b += imageData[i + 2]; - count++; - } - } - - if (count === 0) return "rgb(200,200,200)"; // Fallback if no bright pixels found - - r = Math.floor(r / count); - g = Math.floor(g / count); - b = Math.floor(b / count); - - - // For light mode, keep the existing logic - const minBrightness = 100; - r = Math.max(r, minBrightness); - g = Math.max(g, minBrightness); - b = Math.max(b, minBrightness); - - - return `rgb(${r},${g},${b})`; - }); - - useVisibleTask$(async ({ track }) => { - track(() => imgRef.value); - - const img = imgRef.value; - if (img) { - const processImage = async () => { - backgroundColor.value = await extractColor(img); - }; - - if (img.complete) { - await processImage(); - } else { - img.onload = processImage; - } - } - }); return ( -
-
+
+ ) }); \ No newline at end of file diff --git a/packages/ui/src/home-nav-bar.tsx b/packages/ui/src/home-nav-bar.tsx index 2e2d59da..3d9151e4 100644 --- a/packages/ui/src/home-nav-bar.tsx +++ b/packages/ui/src/home-nav-bar.tsx @@ -29,13 +29,13 @@ export const HomeNavBar = component$(() => {

-
-