mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2025-12-13 07:46:10 +00:00
added avatar placeholder
This commit is contained in:
parent
bead17d189
commit
4524cc8417
@ -9,7 +9,7 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||||
import { useState } from 'react'
|
import { useState, useEffect } from 'react'
|
||||||
import { useNavigate } from 'react-router-dom'
|
import { useNavigate } from 'react-router-dom'
|
||||||
|
|
||||||
import { useAppState } from '#components/AppShell/hooks/useAppState'
|
import { useAppState } from '#components/AppShell/hooks/useAppState'
|
||||||
@ -57,6 +57,12 @@ export function HeaderView({
|
|||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const appState = useAppState()
|
const appState = useAppState()
|
||||||
|
|
||||||
|
const [imageLoaded, setImageLoaded] = useState(false)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setImageLoaded(false)
|
||||||
|
}, [item])
|
||||||
|
|
||||||
const avatar =
|
const avatar =
|
||||||
itemAvatarField && getValue(item, itemAvatarField)
|
itemAvatarField && getValue(item, itemAvatarField)
|
||||||
? appState.assetsApi.url +
|
? appState.assetsApi.url +
|
||||||
@ -92,13 +98,21 @@ export function HeaderView({
|
|||||||
{avatar && (
|
{avatar && (
|
||||||
<div className='tw-avatar'>
|
<div className='tw-avatar'>
|
||||||
<div
|
<div
|
||||||
className={`${big ? 'tw-w-20' : 'tw-w-10'} tw-inline tw-items-center tw-justify-center overflow-hidden`}
|
className={`${
|
||||||
|
big ? 'tw-w-20' : 'tw-w-10'
|
||||||
|
} tw-inline tw-items-center tw-justify-center overflow-hidden`}
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
className={'tw-w-full tw-h-full tw-object-cover tw-rounded-full'}
|
className={'tw-w-full tw-h-full tw-object-cover tw-rounded-full'}
|
||||||
src={avatar}
|
src={avatar}
|
||||||
alt={item.name + ' logo'}
|
alt={item.name + ' logo'}
|
||||||
|
onLoad={() => setImageLoaded(true)}
|
||||||
|
onError={() => setImageLoaded(false)}
|
||||||
|
style={{ display: imageLoaded ? 'block' : 'none' }}
|
||||||
/>
|
/>
|
||||||
|
{!imageLoaded && (
|
||||||
|
<div className='tw-w-full tw-h-full tw-bg-gray-200 tw-rounded-full' />
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user