Phase 3.1: Enhanced Chore Logging and Reporting System
This commit is contained in:
44
frontend/src/utils/avatarUtils.ts
Normal file
44
frontend/src/utils/avatarUtils.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Generate a consistent color for a user based on their name
|
||||
*/
|
||||
export function getUserColor(name: string): string {
|
||||
const colors = [
|
||||
'bg-red-500',
|
||||
'bg-orange-500',
|
||||
'bg-amber-500',
|
||||
'bg-yellow-500',
|
||||
'bg-lime-500',
|
||||
'bg-green-500',
|
||||
'bg-emerald-500',
|
||||
'bg-teal-500',
|
||||
'bg-cyan-500',
|
||||
'bg-sky-500',
|
||||
'bg-blue-500',
|
||||
'bg-indigo-500',
|
||||
'bg-violet-500',
|
||||
'bg-purple-500',
|
||||
'bg-fuchsia-500',
|
||||
'bg-pink-500',
|
||||
'bg-rose-500',
|
||||
];
|
||||
|
||||
// Simple hash function to get consistent color for same name
|
||||
let hash = 0;
|
||||
for (let i = 0; i < name.length; i++) {
|
||||
hash = name.charCodeAt(i) + ((hash << 5) - hash);
|
||||
}
|
||||
|
||||
const index = Math.abs(hash) % colors.length;
|
||||
return colors[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate initials from a full name
|
||||
*/
|
||||
export function getInitials(name: string): string {
|
||||
const parts = name.trim().split(' ');
|
||||
if (parts.length >= 2) {
|
||||
return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase();
|
||||
}
|
||||
return name.slice(0, 2).toUpperCase();
|
||||
}
|
||||
Reference in New Issue
Block a user