Skip to content

Commit

Permalink
Merge pull request #98 from BuidlerDAO/nig-654
Browse files Browse the repository at this point in the history
fix: fix loading and empty state in Profile page
  • Loading branch information
zhbyak authored Apr 1, 2024
2 parents 6d4eec7 + 83cbb44 commit e7f0492
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
8 changes: 8 additions & 0 deletions src/components/Loading/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@ const Loading = () => {
return <CircularProgress />;
};

export const CenterLoading = () => {
return (
<div className="flex h-[200px] flex-col items-center justify-center space-x-2">
<CircularProgress />
</div>
);
};

export default Loading;
31 changes: 23 additions & 8 deletions src/welcome/Profile/Explore.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React, { useEffect, useRef } from 'react';
import TabContext from '@mui/lab/TabContext';
import TabList from '@mui/lab/TabList';
import TabPanel from '@mui/lab/TabPanel';
Expand All @@ -20,26 +20,41 @@ import { getTimeDistanceFromDate } from '../../utils';
const Explore = () => {
const list = Array(7).fill('');
const { openProfile } = useProfileModal((state) => ({ ...state }));
const { run: getShareList, loading: loading1 } = useShareList();
const { run: getTopList, loading: loading2 } = useTopList();
const { run: getNewList, loading: loading3 } = useNewList();
const { run: getRecentList, loading: loading4 } = useRecentList();
const { run: getShareList, loading: loading4 } = useShareList();
const { run: getTopList, loading: loading1 } = useTopList();
const { run: getNewList, loading: loading2 } = useNewList();
const { run: getRecentList, loading: loading3 } = useRecentList();
const { shareList, topList, newList, recentList } = useShareStore((state) => ({ ...state }));

const [value, setValue] = React.useState('1');
const [loadingx, setLoadingx] = React.useState(true);

const fetchMap: Record<any, any> = {
1: getTopList,
2: getRecentList,
3: getNewList,
2: getNewList,
3: getRecentList,
4: getShareList,
};

const handleChange = (event: React.SyntheticEvent, newValue: string) => {
setLoadingx(true);
setValue(newValue);
fetchMap[newValue]();
};

const loadingRef = useRef(false);

useEffect(() => {
let timeout: any;

if (loading1 || loading2 || loading3 || loading4) {
setLoadingx(true);
timeout = setTimeout(() => {
setLoadingx(false);
}, 500);
}
}, [loading1, loading2, loading3, loading4]);

useEffect(() => {
fetchMap[value]();
}, []);
Expand Down Expand Up @@ -109,7 +124,7 @@ const Explore = () => {
</TabList>
</Box>
<>
{loading1 || loading2 || loading3 || loading4 ? (
{loading1 || loading2 || loading3 || loading4 || loadingx ? (
<div className="flex flex-1 items-center justify-center">
<Loading />
</div>
Expand Down
17 changes: 11 additions & 6 deletions src/welcome/Wallet/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import TableHead from '@mui/material/TableHead';
import TableRow from '@mui/material/TableRow';
import { useToggle } from 'ahooks';
import dayjs from 'dayjs';

import { CenterLoading } from '../../components/Loading';
import { BasicButton, PrimaryButton } from '../../components/Button';
import TableEmptyWidget from '../../components/Empty';
import Modal from '../../components/Modal';
Expand All @@ -19,7 +19,6 @@ import { useTweetList } from '../../service/tweet';
import useProfileModal from '../../store/useProfileModal';
import useShareStore from '../../store/useShareStore';
import useTweetStore from '../../store/useTweetStore';

import BuyModal from './BuyModal';
import SellModal from './SellModal';

Expand Down Expand Up @@ -226,7 +225,9 @@ const ProfileModal = () => {
marginTop: 2,
}}
>
{rows == null || rows.length === 0 ? (
{isGetHolderListLoading ? (
<CenterLoading />
) : rows == null || rows?.length === 0 ? (
<TableEmptyWidget
containerClassName="pt-[30px] pb-[30px]"
label="No holders yet."
Expand All @@ -241,7 +242,7 @@ const ProfileModal = () => {
</TableRow>
</TableHead>
<TableBody>
{rows.map((row, i) => (
{rows?.map((row, i) => (
<TableRow key={i} sx={{ '&:last-child td, &:last-child th': { border: 0 } }}>
<TableCell component="th" scope="row">
{row.holder}
Expand Down Expand Up @@ -276,7 +277,9 @@ const ProfileModal = () => {
marginTop: 2,
}}
>
{holding == null || holding.length === 0 ? (
{isGetHolderListLoading ? (
<CenterLoading />
) : holding == null || holding.length === 0 ? (
<TableEmptyWidget
containerClassName="pt-[30px] pb-[30px]"
label="No shares purchased yet."
Expand Down Expand Up @@ -326,7 +329,9 @@ const ProfileModal = () => {
marginTop: 2,
}}
>
{tweetList == null || tweetList.length === 0 ? (
{isGetTweetListLoading ? (
<CenterLoading />
) : tweetList == null || tweetList.length === 0 ? (
<TableEmptyWidget
containerClassName="pt-[30px] pb-[30px]"
label="No records found. Vote to join weekly rankings."
Expand Down

0 comments on commit e7f0492

Please sign in to comment.