From 857942dbf79c86902f6c27f5582de17f2961cdf3 Mon Sep 17 00:00:00 2001 From: viet-nv Date: Tue, 21 Nov 2023 14:48:19 +0700 Subject: [PATCH] feat: add loading --- src/hooks/farms/useFarmFilters.ts | 3 + src/pages/OmniFarms/components/FarmList.tsx | 71 ++++++++++++++++++--- 2 files changed, 64 insertions(+), 10 deletions(-) diff --git a/src/hooks/farms/useFarmFilters.ts b/src/hooks/farms/useFarmFilters.ts index 9c8da8a115..18ed9dd2c7 100644 --- a/src/hooks/farms/useFarmFilters.ts +++ b/src/hooks/farms/useFarmFilters.ts @@ -84,6 +84,9 @@ export default function useFarmFilters(): [FarmFilter, (filters: SetFilterParams const setFarmFilters = useCallback( (filters: SetFilterParams) => { Object.keys(filters).forEach(key => { + if (key !== 'page') { + searchParams.set('page', '1') + } if (key === 'chainIds') { const chainIds = filters[key] if (chainIds?.length) { diff --git a/src/pages/OmniFarms/components/FarmList.tsx b/src/pages/OmniFarms/components/FarmList.tsx index cf3f20d538..69c2025c74 100644 --- a/src/pages/OmniFarms/components/FarmList.tsx +++ b/src/pages/OmniFarms/components/FarmList.tsx @@ -1,3 +1,8 @@ +import { Trans } from '@lingui/macro' +import { useMemo } from 'react' +import Skeleton from 'react-loading-skeleton' +import { usePrevious } from 'react-use' +import { Text } from 'rebass' import { useGetFarmsQuery } from 'services/knprotocol' import styled from 'styled-components' @@ -6,7 +11,7 @@ import { useActiveWeb3React } from 'hooks' import useFarmFilters from 'hooks/farms/useFarmFilters' import useTheme from 'hooks/useTheme' -import FarmTableHeader from './FarmTableHeader' +import FarmTableHeader, { HeaderWrapper } from './FarmTableHeader' import FarmTableRow from './FarmTableRow' const FarmTable = styled.div(({ theme }) => ({ @@ -16,25 +21,71 @@ const FarmTable = styled.div(({ theme }) => ({ overflow: 'hidden', })) +const Row = styled(HeaderWrapper)(({ theme }) => ({ + background: 'transparent', + padding: '1rem 1.5rem', + fontSize: '14px', + fontWeight: '500', + borderBottom: `1px solid ${theme.border}`, + height: '70px', +})) + export default function FarmList() { const theme = useTheme() const { account } = useActiveWeb3React() const [{ chainIds, ...filters }, setFarmFilters] = useFarmFilters() - const { data } = useGetFarmsQuery( - { ...filters, account }, - { - pollingInterval: 10_000, - }, - ) + const params = useMemo(() => ({ ...filters, account }), [filters, account]) + + const prevParams = usePrevious(params) + + const { + currentData: data, + isLoading, + isFetching, + } = useGetFarmsQuery(params, { + pollingInterval: 10_000, + }) + + const skeleton = (width: string, align?: 'left' | 'right') => { + return ( + + + + ) + } return ( - {data?.farmPools.map(farm => { - return - })} + {isLoading || (isFetching && JSON.stringify(prevParams) !== JSON.stringify(params)) ? ( + [...Array(10).keys()].map(i => ( + + {skeleton('80%', 'left')} + {skeleton('80%')} + {skeleton('80%')} + {skeleton('60%')} + {skeleton('80%')} + {skeleton('70%')} + {skeleton('70%')} + + )) + ) : data?.farmPools.length ? ( + data?.farmPools.map(farm => { + return + }) + ) : ( + + No Farm Found + + )} {