mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-09 13:51:57 -04:00
refactor(frontend): switch to DTOs from @hedgedoc/commons
Co-authored-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
deee8e885f
commit
e411ddf099
121 changed files with 620 additions and 819 deletions
|
@ -1,18 +1,18 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The HedgeDoc developers (see AUTHORS file)
|
||||
* SPDX-FileCopyrightText: 2025 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { getUserInfo } from '../../../api/users'
|
||||
import { AsyncLoadingBoundary } from '../async-loading-boundary/async-loading-boundary'
|
||||
import type { UserAvatarProps } from './user-avatar'
|
||||
import { UserAvatar } from './user-avatar'
|
||||
import React, { useMemo } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useAsync } from 'react-use'
|
||||
import type { UserInfo } from '../../../api/users/types'
|
||||
import type { CommonUserAvatarProps } from './types'
|
||||
import type { UserInfoDto } from '@hedgedoc/commons'
|
||||
|
||||
export interface UserAvatarForUsernameProps extends Omit<UserAvatarProps, 'photoUrl' | 'displayName'> {
|
||||
export interface UserAvatarForUsernameProps extends CommonUserAvatarProps {
|
||||
username: string | null
|
||||
}
|
||||
|
||||
|
@ -27,12 +27,13 @@ export interface UserAvatarForUsernameProps extends Omit<UserAvatarProps, 'photo
|
|||
*/
|
||||
export const UserAvatarForUsername: React.FC<UserAvatarForUsernameProps> = ({ username, ...props }) => {
|
||||
const { t } = useTranslation()
|
||||
const { error, value, loading } = useAsync(async (): Promise<UserInfo> => {
|
||||
const { error, value, loading } = useAsync(async (): Promise<UserInfoDto> => {
|
||||
return username
|
||||
? await getUserInfo(username)
|
||||
: {
|
||||
displayName: t('common.guestUser'),
|
||||
username: ''
|
||||
username: '',
|
||||
photoUrl: null
|
||||
}
|
||||
}, [username, t])
|
||||
|
||||
|
@ -40,8 +41,8 @@ export const UserAvatarForUsername: React.FC<UserAvatarForUsernameProps> = ({ us
|
|||
if (!value) {
|
||||
return null
|
||||
}
|
||||
return <UserAvatar displayName={value.displayName} photoUrl={value.photoUrl} username={username} {...props} />
|
||||
}, [props, value, username])
|
||||
return <UserAvatar user={value} {...props} />
|
||||
}, [props, value])
|
||||
|
||||
return (
|
||||
<AsyncLoadingBoundary loading={loading || !value} error={error} componentName={'UserAvatarForUsername'}>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue