diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/components/Feed/Feed.tsx | 24 | ||||
-rw-r--r-- | src/components/ReviewCard/ReviewCard.tsx | 16 | ||||
-rw-r--r-- | src/pages/HomePage/ReviewForm.tsx | 2 | ||||
-rw-r--r-- | src/pages/ProfilePage/ProfilePage.tsx | 5 |
4 files changed, 37 insertions, 10 deletions
diff --git a/src/components/Feed/Feed.tsx b/src/components/Feed/Feed.tsx index afa914d..03358da 100644 --- a/src/components/Feed/Feed.tsx +++ b/src/components/Feed/Feed.tsx @@ -1,7 +1,8 @@ import React from 'react'; import { Poll } from 'which-types'; import { WindowScroller, AutoSizer, List } from 'react-virtualized'; - +import CircularProgress from '@material-ui/core/CircularProgress'; +import { makeStyles } from '@material-ui/core'; import PollCard from '../PollCard/PollCard'; interface PropTypes { @@ -14,7 +15,18 @@ interface RenderPropTypes { style: React.CSSProperties; } +const useStyles = makeStyles(theme => ({ + loader: { + width: '100%', + textAlign: 'center', + marginTop: theme.spacing(10) + } +})); + const Feed: React.FC<PropTypes> = ({ polls }) => { + const classes = useStyles(); + + const RenderItem: React.FC<RenderPropTypes> = ({ index, style, key }) => { const poll = polls[index]; return ( @@ -24,7 +36,13 @@ const Feed: React.FC<PropTypes> = ({ polls }) => { ); }; - return ( + const loader = ( + <div className={classes.loader}> + <CircularProgress color="primary" style={{ margin: '0 auto' }} /> + </div> + ); + + const list = ( <WindowScroller> {({ height, @@ -55,6 +73,8 @@ const Feed: React.FC<PropTypes> = ({ polls }) => { )} </WindowScroller> ); + + return polls.length ? list : loader; }; export default Feed; diff --git a/src/components/ReviewCard/ReviewCard.tsx b/src/components/ReviewCard/ReviewCard.tsx index 97581fc..2016a5e 100644 --- a/src/components/ReviewCard/ReviewCard.tsx +++ b/src/components/ReviewCard/ReviewCard.tsx @@ -30,12 +30,16 @@ const ReviewCard: React.FC<PropTypes> = ({ feedback }) => { user={feedback.author} info={<Rating value={feedback.score} readOnly size="small" />} /> - <Divider /> - <CardContent> - <Typography> - {feedback.contents} - </Typography> - </CardContent> + {feedback.contents && ( + <> + <Divider /> + <CardContent> + <Typography> + {feedback.contents} + </Typography> + </CardContent> + </> + )} </Card> ); }; diff --git a/src/pages/HomePage/ReviewForm.tsx b/src/pages/HomePage/ReviewForm.tsx index 7ad0880..248e36e 100644 --- a/src/pages/HomePage/ReviewForm.tsx +++ b/src/pages/HomePage/ReviewForm.tsx @@ -27,7 +27,7 @@ const ReviewForm: React.FC = () => { const { enqueueSnackbar } = useSnackbar(); const handleSubmit = (): void => { - if (contents && score) { + if (score) { post('/feedback', { contents, score, version }).then(() => { enqueueSnackbar('Your feedback has been submitted!', { variant: 'success' diff --git a/src/pages/ProfilePage/ProfilePage.tsx b/src/pages/ProfilePage/ProfilePage.tsx index 3beeb00..34c9efa 100644 --- a/src/pages/ProfilePage/ProfilePage.tsx +++ b/src/pages/ProfilePage/ProfilePage.tsx @@ -16,16 +16,19 @@ const ProfilePage: React.FC = () => { const { page, navigate } = useNavigate(); const { user } = useAuth(); const [isInfoLoading, setIsInfoLoading] = useState(false); + const [isPollsLoading, setIsPollsLoading] = useState(false); useEffect(() => { const id = page?.id || user?._id; setIsInfoLoading(true); + setIsPollsLoading(true); if (id) { get(`/users/${id}`).then(response => { setUserInfo(response.data); setIsInfoLoading(false); }); get(`/profiles/${id}`).then(response => { + setIsPollsLoading(false); setPolls([]); setPolls(response.data); setTotalVotes(response.data.reduce( @@ -47,7 +50,7 @@ const ProfilePage: React.FC = () => { totalVotes={totalVotes} isLoading={isInfoLoading} /> - <Feed polls={[...polls]} /> + {isPollsLoading ? <Feed polls={[]} /> : (polls.length > 0 && <Feed polls={polls} />)} </Container> ); }; |