diff options
author | Eugene Sokolov <eug-vs@keemail.me> | 2020-08-14 05:06:01 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-14 05:06:01 +0300 |
commit | a6d2d1d833116772178125b3e047e0811131c0e0 (patch) | |
tree | 022abcb444cda09f98c2d43accc2fdd85aeb2a82 /src/containers/Profile/Profile.tsx | |
parent | dc0d09f568ca9eeda4978c4750b548ba81688c23 (diff) | |
parent | 1d35dd8a80f0ea72306e96c2229a27798ec75ce9 (diff) | |
download | which-ui-a6d2d1d833116772178125b3e047e0811131c0e0.tar.gz |
Merge pull request #81 from which-ecosystem/better-ux
Handle empty states
Diffstat (limited to 'src/containers/Profile/Profile.tsx')
-rw-r--r-- | src/containers/Profile/Profile.tsx | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/containers/Profile/Profile.tsx b/src/containers/Profile/Profile.tsx index 33abfc2..701aa06 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'; @@ -26,28 +27,31 @@ const Profile: React.FC = () => { } }, [username, history, user]); + const isOwnProfile = useMemo(() => user?.username === username, [user, username]); - 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 message={isOwnProfile ? 'Create a poll and it will show up here.' : ''} /> + : isValidating && <Loading /> } - {user?.username === username && <Fab />} + {isOwnProfile && <Fab />} </Container> ); }; |