diff options
author | eug-vs <eug-vs@keemail.me> | 2020-08-14 04:09:56 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-08-14 04:19:52 +0300 |
commit | 917d83bfb70d863944df62fb3ca254ba74e67e6e (patch) | |
tree | f3739faea2ad5ee23d083d2ab1d23f67db1a9170 /src/containers/Profile/Profile.tsx | |
parent | dc0d09f568ca9eeda4978c4750b548ba81688c23 (diff) | |
download | which-ui-917d83bfb70d863944df62fb3ca254ba74e67e6e.tar.gz |
feat: add EmptyState component
Diffstat (limited to 'src/containers/Profile/Profile.tsx')
-rw-r--r-- | src/containers/Profile/Profile.tsx | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/containers/Profile/Profile.tsx b/src/containers/Profile/Profile.tsx index 33abfc2..fe77ff2 100644 --- a/src/containers/Profile/Profile.tsx +++ b/src/containers/Profile/Profile.tsx @@ -7,6 +7,7 @@ import ProfileInfo from './ProfileInfo'; import PollsList from '../../components/PollsList/PollsList'; import Loading from '../../components/Loading/Loading'; import Fab from '../../components/Fab/Fab'; +import EmptyState from '../../components/EmptyState/EmptyState'; import { useAuth } from '../../hooks/useAuth'; import { useUser, useProfile } from '../../hooks/APIClient'; @@ -27,25 +28,27 @@ const Profile: React.FC = () => { }, [username, history, user]); - const totalVotes = useMemo(() => polls.reduce( + const totalVotes = useMemo(() => polls?.reduce( (total: number, current: Poll) => { const { left, right } = current.contents; return total + left.votes + right.votes; }, 0 - ), [polls]); + ) || 0, [polls]); return ( <Container maxWidth="sm" disableGutters> <ProfileInfo userInfo={userInfo} setUserInfo={setUserInfo} - savedPolls={polls.length} + savedPolls={polls?.length || 0} totalVotes={totalVotes} /> { - isValidating && !polls - ? <Loading /> - : <PollsList polls={polls} mutate={mutatePolls} /> + polls + ? polls.length + ? <PollsList polls={polls} mutate={mutatePolls} /> + : <EmptyState /> + : isValidating && <Loading /> } {user?.username === username && <Fab />} </Container> |