mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-13 06:34:39 -04:00
fix(async-loading): show async loaded components only if value is present
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
26c1f1bcaa
commit
caf212045a
11 changed files with 13 additions and 16 deletions
|
@ -14,7 +14,7 @@ import type { AsyncState } from 'react-use/lib/useAsyncFn'
|
|||
*
|
||||
* @return An {@link AsyncState async state} that represents the current state of the loading process.
|
||||
*/
|
||||
export const useLoadNoteFromServer = (): [AsyncState<void>, () => void] => {
|
||||
export const useLoadNoteFromServer = (): [AsyncState<boolean>, () => void] => {
|
||||
const id = useSingleStringUrlParameter('noteId', undefined)
|
||||
|
||||
return useAsyncFn(async () => {
|
||||
|
@ -23,5 +23,6 @@ export const useLoadNoteFromServer = (): [AsyncState<void>, () => void] => {
|
|||
}
|
||||
const noteFromServer = await getNote(id)
|
||||
setNoteDataFromServer(noteFromServer)
|
||||
return true
|
||||
}, [id])
|
||||
}
|
||||
|
|
|
@ -38,13 +38,9 @@ export const UserAvatarForUsername: React.FC<UserAvatarForUsernameProps> = ({ us
|
|||
}
|
||||
}, [username, t])
|
||||
|
||||
if (!value) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<AsyncLoadingBoundary loading={loading} error={error} componentName={'UserAvatarForUsername'}>
|
||||
<UserAvatar user={value} {...props} />
|
||||
<AsyncLoadingBoundary loading={loading || !value} error={error} componentName={'UserAvatarForUsername'}>
|
||||
<UserAvatar user={value as UserInfo} {...props} />
|
||||
</AsyncLoadingBoundary>
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue