reduce profile layout shift by showing banner placeholder

This commit is contained in:
Martti Malmi 2023-08-23 17:24:59 +03:00
parent 0ecd07b4ab
commit aae6b69347
2 changed files with 15 additions and 10 deletions

View File

@ -10,7 +10,9 @@ export const useProfile = (pub: string) => {
if (!pub) return;
return SocialNetwork.getProfile(pub, (p) => {
p && setProfile(p);
if (p && p.created_at !== profile.created_at) {
setProfile(p);
}
});
}, [pub]);

View File

@ -134,15 +134,18 @@ function Profile(props) {
return (
<View>
<Show when={banner && !blocked}>
<div
className="mb-4 h-48 bg-cover bg-center cursor-pointer"
style={{ backgroundImage: `url(${banner})` }}
onClick={() => setBannerModalOpen(true)}
></div>
<Show when={bannerModalOpen}>
<SimpleImageModal imageUrl={profile.banner} onClose={() => setBannerModalOpen(false)} />
</Show>
<div
className="mb-4 h-48 bg-cover bg-center cursor-pointer"
style={{
backgroundImage:
banner && !blocked
? `url(${banner})`
: 'linear-gradient(120deg, #010101 0%, #1f0f26 50%, #010101 100%)',
}}
onClick={() => banner && !blocked && setBannerModalOpen(true)}
></div>
<Show when={bannerModalOpen}>
<SimpleImageModal imageUrl={profile.banner} onClose={() => setBannerModalOpen(false)} />
</Show>
<div>
<ProfileHelmet