From e30b64bed3f73f579e8eaf2353008c11b23dd599 Mon Sep 17 00:00:00 2001 From: Shalini M Date: Mon, 16 Dec 2024 17:08:27 +0530 Subject: [PATCH 1/2] Changed the avatar color to checkmate blue color --- Client/src/Components/Avatar/index.jsx | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/Client/src/Components/Avatar/index.jsx b/Client/src/Components/Avatar/index.jsx index 3760c04b8..18bb6be47 100644 --- a/Client/src/Components/Avatar/index.jsx +++ b/Client/src/Components/Avatar/index.jsx @@ -9,19 +9,8 @@ import { useEffect, useState } from "react"; * @returns {string} */ const stringToColor = (string) => { - let hash = 0; - let i; - for (i = 0; i < string.length; i += 1) { - hash = string.charCodeAt(i) + ((hash << 5) - hash); - } - let color = "#"; - for (i = 0; i < 3; i += 1) { - const value = (hash >> (i * 8)) & 0xff; - color += `00${value.toString(16)}`.slice(-2); - } - - return color; + return "#156EEF"; }; /** From 2d27eed9ba7ebc57b12b5d026240bfc0d7fb448f Mon Sep 17 00:00:00 2001 From: Shalini Date: Tue, 17 Dec 2024 10:38:20 +0530 Subject: [PATCH 2/2] Used theme for the avatar BG instead of hard coding --- Client/src/Components/Avatar/index.jsx | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/Client/src/Components/Avatar/index.jsx b/Client/src/Components/Avatar/index.jsx index 18bb6be47..39e8a3f42 100644 --- a/Client/src/Components/Avatar/index.jsx +++ b/Client/src/Components/Avatar/index.jsx @@ -2,17 +2,7 @@ import { Avatar as MuiAvatar } from "@mui/material"; import PropTypes from "prop-types"; import { useSelector } from "react-redux"; import { useEffect, useState } from "react"; - -/** - * Generates a color based on the input string. - * @param {string} string - The input string to generate the color from. - * @returns {string} - */ -const stringToColor = (string) => { - - return "#156EEF"; -}; - +import { useTheme } from "@emotion/react"; /** * @component * @param {Object} props @@ -27,6 +17,7 @@ const stringToColor = (string) => { const Avatar = ({ src, small, sx }) => { const { user } = useSelector((state) => state.auth); + const theme = useTheme(); const style = small ? { width: 32, height: 32 } : { width: 64, height: 64 }; const border = small ? 1 : 3; @@ -46,7 +37,7 @@ const Avatar = ({ src, small, sx }) => { fontSize: small ? "16px" : "22px", color: "white", fontWeight: 400, - backgroundColor: stringToColor(`${user?.firstName} ${user?.lastName}`), + backgroundColor: theme.palette.primary.main, // Same BG color as checkmate BG in sidebar display: "inline-flex", "&::before": { content: `""`, @@ -63,7 +54,7 @@ const Avatar = ({ src, small, sx }) => { }} > {user.firstName?.charAt(0)} - {user.lastName?.charAt(0)} + {user.lastName?.charAt(0) || ''} ); };