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:
Tilman Vatteroth 2022-12-29 12:27:38 +01:00
parent 26c1f1bcaa
commit caf212045a
11 changed files with 13 additions and 16 deletions

View file

@ -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])
}

View file

@ -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>
)
}