diff --git a/app/routes/profile/index.tsx b/app/routes/profile/index.tsx index 16470fb..19094d5 100644 --- a/app/routes/profile/index.tsx +++ b/app/routes/profile/index.tsx @@ -1,11 +1,7 @@ import { useContext, useState, useEffect } from "react"; import { toast } from "react-hot-toast"; import { useLocalStorage } from "~/hooks/useLocalStorage"; -import { - getGravatarUrlWithDefault, - idToColor, - isValidPlayerStats, -} from "~/utils/utils"; +import { getGravatarUrlWithDefault, isValidPlayerStats } from "~/utils/utils"; import { AuthContext } from "../../components/AuthProvider/AuthProvider"; import { updateUsername, @@ -17,12 +13,28 @@ import trianglify from "trianglify"; import { EnvelopeIcon } from "@heroicons/react/20/solid"; function generateBackground(emailHash: string) { + const seedNumber = Array.from(emailHash).reduce( + (acc, char) => acc + char.charCodeAt(0), + 0 + ); + + const colors = ["#4b6bfc", "#fbbd25", "#11b97f"]; + const shuffledColors = colors + .slice(seedNumber % colors.length) + .concat(colors.slice(0, seedNumber % colors.length)); + + const cellSize = 20 + (seedNumber % 181); + const variance = 0.1 + 0.8 * ((seedNumber % 100) / 100); + const pattern = trianglify({ width: 1920, - height: 1080, + height: 600, seed: emailHash, - cellSize: 80, - variance: 0.25, + cellSize: cellSize, + variance: variance, + palette: { + default: shuffledColors, + }, }); const canvas = pattern.toCanvas(); @@ -151,75 +163,81 @@ export default function Profile() {
-
-
- -
-
-
-

{profile.name}

-
-
-
+ {profile && ( + <> +
+
+ +
+
+
+

+ {profile.name} +

+
+
+
+ + )}
- - {!importedDate && localStats && ( -
-

Import your game stats

-

- If you've been playing Chessguessr, your stats are saved in your - browser. By importing them, you can keep them safe on your - account and access them on any device. Please note, stats can be - imported only once. -

- -
-

Your Local Stats:

-
    -
  • Games Played: {localStats.gamesPlayed}
  • -
  • Current Streak: {localStats.currentStreak}
  • -
  • Guess distribution:
  • -
      -
    • 1: {localStats.guesses["1"]}
    • -
    • 2: {localStats.guesses["2"]}
    • -
    • 3: {localStats.guesses["3"]}
    • -
    • 4: {localStats.guesses["4"]}
    • -
    • 5: {localStats.guesses["5"]}
    • +
      + {!importedDate && localStats && ( +
      +

      + Import your game stats +

      +

      + If you've been playing Chessguessr, your stats are saved in + your browser. By importing them, you can keep them safe on + your account and access them on any device. Please note, stats + can be imported only once. +

      +
      +

      Your Local Stats:

      +
        +
      • Games Played: {localStats.gamesPlayed}
      • +
      • Current Streak: {localStats.currentStreak}
      • +
      • Guess distribution:
      • +
          +
        • 1: {localStats.guesses["1"]}
        • +
        • 2: {localStats.guesses["2"]}
        • +
        • 3: {localStats.guesses["3"]}
        • +
        • 4: {localStats.guesses["4"]}
        • +
        • 5: {localStats.guesses["5"]}
        • +
      -
    +
+
+ +
- -
- + )} + {message && ( +
+ {message}
-
- )} - - {message && ( -
- {message} -
- )} + )} +
);