39 lines
No EOL
1.2 KiB
TypeScript
39 lines
No EOL
1.2 KiB
TypeScript
/**
|
|
* Utility functions for handling gender-based avatar images
|
|
*/
|
|
|
|
/**
|
|
* Gets the appropriate avatar image path based on gender
|
|
* @param gender - The gender string from persona data
|
|
* @returns Path to the appropriate avatar image
|
|
*/
|
|
export const getGenderAvatarPath = (gender: string): string => {
|
|
const normalizedGender = gender?.toLowerCase();
|
|
|
|
// Get the base path from Vite's import.meta.env or use relative path
|
|
const basePath = import.meta.env.BASE_URL || '/';
|
|
|
|
switch (normalizedGender) {
|
|
case 'male':
|
|
return `${basePath}male_avatar.png`;
|
|
case 'female':
|
|
return `${basePath}female_avatar.png`;
|
|
case 'non-binary':
|
|
case 'nonbinary':
|
|
case 'non binary':
|
|
return `${basePath}nonbinary_avatar.png`;
|
|
default:
|
|
// Default to male avatar for unknown gender values
|
|
return `${basePath}male_avatar.png`;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Gets the avatar image source for a persona
|
|
* Priority: custom avatar first, then gender-based avatar
|
|
* @param persona - The persona object with optional avatar and gender fields
|
|
* @returns Path to the appropriate avatar image
|
|
*/
|
|
export const getPersonaAvatarSrc = (persona: { avatar?: string; gender: string }): string => {
|
|
return persona.avatar || getGenderAvatarPath(persona.gender);
|
|
}; |