mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-21 02:35:23 -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,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])
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue