use first letter of display name / name / id as default avatar

This commit is contained in:
Aine 2024-11-21 22:34:44 +02:00
parent 3731410486
commit eae00a6ccd
No known key found for this signature in database
GPG Key ID: 34969C908CCA2804
2 changed files with 17 additions and 2 deletions

View File

@ -31,7 +31,23 @@ const AvatarField = ({ source, ...rest }: AvatarProps & FieldProps) => {
};
}, [mxcURL, fetchAvatar]);
return <Avatar alt={alt} classes={classes} sizes={sizes} src={src} sx={sx} variant={variant} />;
// a hacky way to handle both users and rooms,
// where users have an ID, may have a name, and may have a displayname
// and rooms have an ID and may have a name
let letter = "";
if (record?.id) {
letter = record.id[0].toUpperCase();
}
if (record?.name) {
letter = record.name[0].toUpperCase();
}
if (record?.displayname) {
letter = record.displayname[0].toUpperCase();
}
return (<Avatar alt={alt} classes={classes} sizes={sizes} src={src} sx={sx} variant={variant}>
{letter}
</Avatar>);
};
export default AvatarField;

View File

@ -172,7 +172,6 @@ const authProvider: AuthProvider = {
// called when the user navigates to a new location, to check for authentication
checkAuth: () => {
const access_token = storage.getItem("access_token");
console.log("checkAuth " + access_token);
return typeof access_token === "string" ? Promise.resolve() : Promise.reject();
},
// called when the user navigates to a new location, to check for permissions / roles