From e677fab5e4d5210c80442c0fac188fa229527d11 Mon Sep 17 00:00:00 2001 From: Junho Yeo Date: Mon, 10 Oct 2022 00:47:16 +0900 Subject: [PATCH] [web] Render Skeleton instead of `NFTListSection` before initial `NFTs` tab click (#280) --- .../bento-web/src/dashboard/DashboardMain.tsx | 73 ++++++++++++------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/packages/bento-web/src/dashboard/DashboardMain.tsx b/packages/bento-web/src/dashboard/DashboardMain.tsx index 6fec47f0..ddafa434 100644 --- a/packages/bento-web/src/dashboard/DashboardMain.tsx +++ b/packages/bento-web/src/dashboard/DashboardMain.tsx @@ -2,11 +2,11 @@ import { Wallet } from '@bento/common'; import { OpenSeaAsset } from '@bento/core'; import groupBy from 'lodash.groupby'; import { useTranslation } from 'next-i18next'; -import React, { useMemo, useState } from 'react'; +import React, { useEffect, useMemo, useState } from 'react'; import styled from 'styled-components'; import { AnimatedTab } from '@/components/AnimatedTab'; -import { Badge, Checkbox } from '@/components/system'; +import { Badge, Checkbox, Skeleton } from '@/components/system'; import { useLocalStorage } from '@/hooks/useLocalStorage'; import { DashboardTokenBalance } from '@/dashboard/types/TokenBalance'; @@ -26,7 +26,12 @@ import { NFTListSection } from './sections/NFTListSection'; import { ProfileSummarySection } from './sections/ProfileSummarySection'; import { WalletListSection } from './sections/WalletListSection'; -const TAB_ITEMS = ['Crypto', 'NFTs', 'Badges'] as const; +enum DashboardTabType { + Crypto = 'Crypto', + NFTs = 'NFTs', + Badges = 'Badges', +} +const DASHBOARD_TAB_ITEMS = Object.values(DashboardTabType); const walletBalanceReducer = (key: string, callback: (acc: number, balance: WalletBalance) => number) => @@ -110,27 +115,32 @@ export const DashboardMain: React.FC = ({ }, [walletBalancesJSONKey, nftBalancesJSONKey]); const tokenBalancesJSONKey = JSON.stringify(tokenBalances); - const [isNFTsShown, setNFTsShown] = useLocalStorage( - '@is-nfts-shown-v1', - true, - ); + const [isNFTBalancesIncluded, setNFTBalancesIncluded] = + useLocalStorage('@is-nfts-shown-v1', true); const renderedTokenBalances = useMemo(() => { - if (isNFTsShown) { + if (isNFTBalancesIncluded) { return tokenBalances; } return tokenBalances.filter((v) => v.type !== 'nft'); - }, [isNFTsShown, tokenBalancesJSONKey]); + }, [isNFTBalancesIncluded, tokenBalancesJSONKey]); const netWorthInUSD = useMemo( () => tokenBalances.reduce((acc, info) => acc + info.netWorth, 0), [tokenBalancesJSONKey], ); - const [currentTab, setCurrentTab] = useState( - TAB_ITEMS[0], + const [currentTab, setCurrentTab] = useState( + DashboardTabType.Crypto, ); + const [isNFTsInitialized, setNFTsInitialized] = useState(false); + useEffect(() => { + if (currentTab === DashboardTabType.NFTs) { + setNFTsInitialized(true); + } + }, [currentTab]); + return (
@@ -149,10 +159,10 @@ export const DashboardMain: React.FC = ({ - + = ({
{ - if (!isNFTsShown) { + if (!isNFTBalancesIncluded) { // showing Analytics.logEvent('click_show_nfts', undefined); } else { // hiding Analytics.logEvent('click_hide_nfts', undefined); } - setNFTsShown(!isNFTsShown); + setNFTBalancesIncluded(!isNFTBalancesIncluded); }} > - + {t('Show NFTs')} @@ -237,17 +250,27 @@ export const DashboardMain: React.FC = ({
- - + + {!isNFTsInitialized ? ( + + ) : ( + + )} - + Coming Soon!