mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-24 02:36:31 -05:00
fix(avatars): show correct profile picture of users
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
7195c1bdc0
commit
62dfe4df72
1 changed files with 5 additions and 3 deletions
|
@ -10,6 +10,7 @@ import { UserAvatar } from './user-avatar'
|
||||||
import React, { useMemo } from 'react'
|
import React, { useMemo } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { useAsync } from 'react-use'
|
import { useAsync } from 'react-use'
|
||||||
|
import type { UserInfo } from '../../../api/users/types'
|
||||||
|
|
||||||
export interface UserAvatarForUsernameProps extends Omit<UserAvatarProps, 'photoUrl' | 'displayName'> {
|
export interface UserAvatarForUsernameProps extends Omit<UserAvatarProps, 'photoUrl' | 'displayName'> {
|
||||||
username: string | null
|
username: string | null
|
||||||
|
@ -26,11 +27,12 @@ export interface UserAvatarForUsernameProps extends Omit<UserAvatarProps, 'photo
|
||||||
*/
|
*/
|
||||||
export const UserAvatarForUsername: React.FC<UserAvatarForUsernameProps> = ({ username, ...props }) => {
|
export const UserAvatarForUsername: React.FC<UserAvatarForUsernameProps> = ({ username, ...props }) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { error, value, loading } = useAsync(async (): Promise<{ displayName: string; photo?: string }> => {
|
const { error, value, loading } = useAsync(async (): Promise<UserInfo> => {
|
||||||
return username
|
return username
|
||||||
? await getUserInfo(username)
|
? await getUserInfo(username)
|
||||||
: {
|
: {
|
||||||
displayName: t('common.guestUser')
|
displayName: t('common.guestUser'),
|
||||||
|
username: ''
|
||||||
}
|
}
|
||||||
}, [username, t])
|
}, [username, t])
|
||||||
|
|
||||||
|
@ -38,7 +40,7 @@ export const UserAvatarForUsername: React.FC<UserAvatarForUsernameProps> = ({ us
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return <UserAvatar displayName={value.displayName} photoUrl={value.photo} username={username} {...props} />
|
return <UserAvatar displayName={value.displayName} photoUrl={value.photoUrl} username={username} {...props} />
|
||||||
}, [props, value, username])
|
}, [props, value, username])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in a new issue