Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue#1402 - Default color is set as checkmate blue color if no avatar is available #1405

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Client/src/Components/Avatar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const stringToColor = (string) => {
*/

const Avatar = ({ src, small, sx }) => {
const defaultAvatarColor = "#156EEF";

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Yo dawg, we've got some leftover spaghetti code here!

Now that we're using a fixed default color, the stringToColor function is just hanging around like yesterday's pasta. We should clean this up.

Let's drop that unused function:

- /**
-  * Generates a color based on the input string.
-  * @param {string} string - The input string to generate the color from.
-  * @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;
- };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const defaultAvatarColor = "#156EEF";
const defaultAvatarColor = "#156EEF";

const { user } = useSelector((state) => state.auth);

const style = small ? { width: 32, height: 32 } : { width: 64, height: 64 };
Expand All @@ -57,7 +59,7 @@ const Avatar = ({ src, small, sx }) => {
fontSize: small ? "16px" : "22px",
color: "white",
fontWeight: 400,
backgroundColor: stringToColor(`${user?.firstName} ${user?.lastName}`),
backgroundColor: user?.avatarImage ? undefined : defaultAvatarColor,
display: "inline-flex",
"&::before": {
content: `""`,
Expand Down