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:
Erik Michelson 2025-03-29 13:51:02 +01:00 committed by Philip Molares
parent deee8e885f
commit e411ddf099
121 changed files with 620 additions and 819 deletions

View file

@ -1,28 +1,30 @@
/*
* 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 { useMemo } from 'react'
import { createAvatar } from '@dicebear/core'
import * as identicon from '@dicebear/identicon'
import type { UserInfoDto } from '@hedgedoc/commons'
/**
* Returns the correct avatar url for a user.
* When an empty or no photoUrl is given, a random avatar is generated from the displayName.
* When the user has no photoUrl, a random avatar is generated from the display name.
*
* @param photoUrl The photo url of the user to use. Maybe empty or not set.
* @param username The username of the user to use as input to the random avatar.
* @return The correct avatar url for the user.
* @param user The user for which to get the avatar URL
* @return The correct avatar url for the user
*/
export const useAvatarUrl = (photoUrl: string | undefined, username: string): string => {
export const useAvatarUrl = (user: UserInfoDto): string => {
const { photoUrl, displayName } = user
return useMemo(() => {
if (photoUrl && photoUrl.trim() !== '') {
return photoUrl
}
const avatar = createAvatar(identicon, {
seed: username
seed: displayName
})
return avatar.toDataUri()
}, [photoUrl, username])
}, [photoUrl, displayName])
}