From e36c5ceae284c3df78c5dd3d0a0dc28936e650e3 Mon Sep 17 00:00:00 2001 From: Nils Jacobsen Date: Mon, 27 Feb 2023 11:18:16 +0100 Subject: [PATCH] feat: add gradient placeholder #30 --- src/client/components/DashboardHeader.tsx | 8 ++++++-- src/client/components/GridList.tsx | 5 ++++- src/client/components/crop/ImageUpload.tsx | 5 ++++- src/helper/generateUserGradient.ts | 16 ++++++++++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 src/helper/generateUserGradient.ts diff --git a/src/client/components/DashboardHeader.tsx b/src/client/components/DashboardHeader.tsx index 6151e7d6..475f96d3 100644 --- a/src/client/components/DashboardHeader.tsx +++ b/src/client/components/DashboardHeader.tsx @@ -3,6 +3,7 @@ import clsx from "clsx"; import { signOut } from "next-auth/react"; import { Fragment } from "react"; import { useRecoilState, useRecoilValue } from "recoil"; +import { generateGradient } from "../../helper/generateUserGradient"; import { settingsOpenState } from "../store/ui/modals"; import { currentUserState } from "../store/user"; import { Icon } from "./Icons"; @@ -13,6 +14,8 @@ export default function DashboardHeader() { if (!user) return null; + const gradient = generateGradient(user?.firstName ? user.firstName : "Horst"); + return (
@@ -75,12 +78,13 @@ export default function DashboardHeader() {
Open user menu - profile image + /> : +
}
{filteredSites && @@ -51,7 +54,7 @@ export default function GridList() { alt="site profile picture" /> ) : ( -
+
)}

diff --git a/src/client/components/crop/ImageUpload.tsx b/src/client/components/crop/ImageUpload.tsx index 7e7c387f..6be840ee 100644 --- a/src/client/components/crop/ImageUpload.tsx +++ b/src/client/components/crop/ImageUpload.tsx @@ -16,6 +16,7 @@ import { currentUserState, isrUserState } from "../../store/user"; import { isrDataState, isrState } from "../../store/isr"; import { useUpdateUploadCreditMutation } from "../../graphql/updateUploadCredit.generated"; import { toast } from "react-hot-toast"; +import { generateGradient } from "../../../helper/generateUserGradient"; interface ImageUploadProps { imageUrl: string; @@ -181,6 +182,8 @@ const ImageUpload: FC = ({ } }, [cropData]); + const gradient = generateGradient(currentUser?.firstName ? currentUser.firstName : "Horst"); + return ( <>
= ({ />
) : ( -
+ (!isIsrMode || imageUrl) &&
)}
{!disabled && ( diff --git a/src/helper/generateUserGradient.ts b/src/helper/generateUserGradient.ts new file mode 100644 index 00000000..2b5d7c6c --- /dev/null +++ b/src/helper/generateUserGradient.ts @@ -0,0 +1,16 @@ +export function generateGradient(name: string): string { + const colors = [ + 'red', + 'orange', + 'yellow', + 'green', + 'blue', + 'purple' + ]; // Define an array of colors for the gradient + + const hue = name.split('').reduce((acc, char) => acc + char.charCodeAt(0), 0) % colors.length; // Generate hue based on character codes of name + const startColor = colors[hue]; // Use the hue to select a starting color for the gradient + const endColor = colors[(hue + 1) % colors.length]; // Use the next color in the array as the ending color for the gradient + + return `linear-gradient(to right, ${startColor}, ${endColor})`; + } \ No newline at end of file