Skip to content

Commit

Permalink
Fix leaderboard sticky image loading issue
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Jun 11, 2024
1 parent 810fc20 commit 706ab76
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/components/AddressAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getIpfsContentUrl } from '@/utils/ipfs'
import { getUserProfileLink } from '@/utils/links'
import { decodeProfileSource } from '@/utils/profile'
import dynamic from 'next/dynamic'
import Image from 'next/image'
import Image, { ImageProps } from 'next/image'
import {
ComponentProps,
ComponentPropsWithoutRef,
Expand All @@ -31,11 +31,18 @@ export type AddressAvatarProps = ComponentProps<'div'> & {
address: string
asLink?: boolean
forceProfileSource?: ForceProfileSource
loading?: ImageProps['loading']
}

const AddressAvatar = forwardRef<HTMLDivElement, AddressAvatarProps>(
function AddressAvatar(
{ address, forceProfileSource, asLink, ...props }: AddressAvatarProps,
{
address,
forceProfileSource,
asLink,
loading,
...props
}: AddressAvatarProps,
ref
) {
const backgroundColor = useRandomColor(address)
Expand Down Expand Up @@ -114,6 +121,7 @@ const AddressAvatar = forwardRef<HTMLDivElement, AddressAvatarProps>(
>
<div className='relative h-full w-full'>
<Image
loading={loading}
width={500}
height={500}
className={cx(
Expand Down
15 changes: 12 additions & 3 deletions src/modules/telegram/StatsPage/LeaderboardTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { LeaderboardDataPeriod } from '@/services/datahub/leaderboard/types'
import { useMyMainAddress } from '@/stores/my-account'
import { cx, mutedTextColorStyles } from '@/utils/class-names'
import Image from 'next/image'
import Image, { ImageProps } from 'next/image'
import { useMemo } from 'react'

const TABLE_LIMIT = 100
Expand Down Expand Up @@ -82,6 +82,7 @@ const LeaderboardTable = ({ period }: LeaderboardTableProps) => {
rank: userStats.rank!,
'user-role': (
<UserPreview
loading='eager'
address={userStats.address}
desc={<UserReward reward={userStats.reward} />}
/>
Expand Down Expand Up @@ -163,10 +164,18 @@ type UserPreviewProps = {
desc?: React.ReactNode
}

export const UserPreview = ({ address, desc }: UserPreviewProps) => {
export const UserPreview = ({
address,
desc,
loading,
}: UserPreviewProps & { loading?: ImageProps['loading'] }) => {
return (
<div className='flex items-center gap-2'>
<AddressAvatar address={address} className='h-[38px] w-[38px]' />
<AddressAvatar
address={address}
className='h-[38px] w-[38px]'
loading={loading}
/>
<div className='flex flex-col gap-2'>
<Name
address={address}
Expand Down

0 comments on commit 706ab76

Please sign in to comment.