From f65bcd2814d87074b44ce21efb97fc781c7fbe0c Mon Sep 17 00:00:00 2001 From: aliraza556 Date: Thu, 26 Dec 2024 23:25:02 +0500 Subject: [PATCH] Update TopEarners component with responsive --- src/components/common/TopEarners/index.tsx | 62 +++++++++++++++---- .../TopEarners/leaderboardItem/index.tsx | 2 +- src/pages/BountiesLandingPage/index.tsx | 9 ++- src/pages/leaderboard/store.ts | 4 ++ 4 files changed, 59 insertions(+), 18 deletions(-) diff --git a/src/components/common/TopEarners/index.tsx b/src/components/common/TopEarners/index.tsx index 85f8a0ce..42889b7c 100644 --- a/src/components/common/TopEarners/index.tsx +++ b/src/components/common/TopEarners/index.tsx @@ -1,15 +1,21 @@ -import { EuiLoadingSpinner } from '@elastic/eui'; +import { EuiLoadingSpinner, EuiText } from '@elastic/eui'; import { colors, mobileBreakpoint } from 'config'; import { observer } from 'mobx-react-lite'; -import React, { useEffect } from 'react'; +import React, { useEffect, useState } from 'react'; import { useStores } from 'store'; import styled from 'styled-components'; import { LeaerboardItem } from './leaderboardItem'; +interface TopEarnersProps { + limit?: number; + className?: string; + style?: React.CSSProperties; + onError?: (error: Error) => void; +} + const Container = styled.div` - height: calc(100% - 4rem); - padding: 2rem; - background-color: ${colors.light.background100}; + height: 100%; + min-height: 100%; overflow: auto; align-items: center; justify-content: center; @@ -53,11 +59,40 @@ const LoaderContainer = styled.div` height: 100%; `; -const TopEarners = observer(() => { +const ErrorContainer = styled.div` + display: flex; + justify-content: center; + align-items: center; + width: 100%; + padding: 1rem; + color: ${colors.light.red1}; +`; + +const TopEarners = observer(({ limit = 5, className, style, onError }: TopEarnersProps) => { const { leaderboard } = useStores(); + const [error, setError] = useState(null); + useEffect(() => { - leaderboard.fetchLeaders(); - }, [leaderboard]); + const fetchData = async () => { + try { + await leaderboard.fetchLeaders(); + } catch (err) { + const error = err instanceof Error ? err : new Error('Failed to fetch leaderboard data'); + setError(error); + onError?.(error); + } + }; + + fetchData(); + }, [leaderboard, onError]); + + if (error) { + return ( + + Failed to load top earners + + ); + } if (leaderboard.isLoading) { return ( @@ -66,12 +101,15 @@ const TopEarners = observer(() => { ); } + return ( - +
- {leaderboard?.top3.map((item: any, index: number) => ( - - ))} + {leaderboard?.topEarners + .slice(0, limit) + .map((item: any, index: number) => ( + + ))}
); diff --git a/src/components/common/TopEarners/leaderboardItem/index.tsx b/src/components/common/TopEarners/leaderboardItem/index.tsx index 594c0043..f75a5d47 100644 --- a/src/components/common/TopEarners/leaderboardItem/index.tsx +++ b/src/components/common/TopEarners/leaderboardItem/index.tsx @@ -9,7 +9,7 @@ import { UserInfo } from '../../../../pages/leaderboard/userInfo'; const ItemContainer = styled.div` --position-gutter: 3rem; - position: relative; + position: sticky; display: flex; flex-direction: row; align-items: center; diff --git a/src/pages/BountiesLandingPage/index.tsx b/src/pages/BountiesLandingPage/index.tsx index 2e07be73..d7dbcaac 100644 --- a/src/pages/BountiesLandingPage/index.tsx +++ b/src/pages/BountiesLandingPage/index.tsx @@ -29,7 +29,7 @@ const BountiesLandingPage: React.FC = () => { min-height: 500px; margin: 30px auto; width: 100%; - padding: 40px 30px; + padding: 40px 20px 20px 30px; background: white; `; @@ -43,7 +43,7 @@ const BountiesLandingPage: React.FC = () => { &:after { content: ''; position: absolute; - left: 66.66%; + left: 63%; top: 0; bottom: 0; width: 1px; @@ -71,7 +71,7 @@ const BountiesLandingPage: React.FC = () => { font-size: 24px; font-family: Barlow; color: ${color.text1}; - margin-bottom: 32px; + margin-bottom: 24px; font-weight: 500; } @@ -106,8 +106,7 @@ const BountiesLandingPage: React.FC = () => {

Freedom to Earn!

-

Second column with content

- +
diff --git a/src/pages/leaderboard/store.ts b/src/pages/leaderboard/store.ts index 4d975533..e12ad4ec 100644 --- a/src/pages/leaderboard/store.ts +++ b/src/pages/leaderboard/store.ts @@ -52,6 +52,10 @@ export class LeaderboardStore { get others() { return this.sortedBySats.slice(3); } + + get topEarners() { + return this.sortedBySats; + } } export const leaderboardStore = new LeaderboardStore();