diff --git a/src/renderer/src/helpers.ts b/src/renderer/src/helpers.ts index 9d5a4700..19d1969c 100644 --- a/src/renderer/src/helpers.ts +++ b/src/renderer/src/helpers.ts @@ -1,5 +1,7 @@ import type { GameShop } from "@types"; +import Color from "color"; + export const steamUrlBuilder = { library: (objectID: string) => `https://steamcdn-a.akamaihd.net/steam/apps/${objectID}/header.jpg`, @@ -40,3 +42,6 @@ export const buildGameDetailsPath = ( const searchParams = new URLSearchParams({ title: game.title, ...params }); return `/game/${game.shop}/${game.objectID}?${searchParams.toString()}`; }; + +export const darkenColor = (color: string, amount: number) => + new Color(color).darken(amount).toString(); diff --git a/src/renderer/src/pages/user/user-content.tsx b/src/renderer/src/pages/user/user-content.tsx index 2defbad1..c120f9d1 100644 --- a/src/renderer/src/pages/user/user-content.tsx +++ b/src/renderer/src/pages/user/user-content.tsx @@ -1,16 +1,15 @@ import { UserGame, UserProfile } from "@types"; import cn from "classnames"; import { average } from "color.js"; -import Color from "color"; import * as styles from "./user.css"; import { SPACING_UNIT, vars } from "@renderer/theme.css"; -import { useMemo } from "react"; +import { useMemo, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import SteamLogo from "@renderer/assets/steam-logo.svg?react"; import { useDate } from "@renderer/hooks"; import { useNavigate } from "react-router-dom"; -import { buildGameDetailsPath } from "@renderer/helpers"; +import { buildGameDetailsPath, darkenColor } from "@renderer/helpers"; import { PersonIcon } from "@primer/octicons-react"; import { Button } from "@renderer/components"; import { useUserAuth } from "@renderer/hooks/use-user-auth"; @@ -25,6 +24,10 @@ export const UserContent = ({ userProfile }: ProfileContentProps) => { const { userAuth, signOut } = useUserAuth(); + const profileImageRef = useRef(null); + + const [backgroundColors, setBackgroundColors] = useState([]); + const navigate = useNavigate(); const numberFormatter = useMemo(() => { @@ -62,25 +65,29 @@ export const UserContent = ({ userProfile }: ProfileContentProps) => { }; const handleAvatarLoad = async () => { - console.log(userProfile.profileImageUrl); - const output = await average(userProfile.profileImageUrl!, { + const output = await average(profileImageRef.current!, { amount: 1, format: "hex", }); - const backgroundColor = output - ? (new Color(output).darken(0.7).toString() as string) - : ""; - - console.log(backgroundColor); + setBackgroundColors([ + darkenColor(output as string, 0.6), + darkenColor(output as string, 0.7), + ]); }; return ( <> -
+
{userProfile.profileImageUrl ? (