aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/Feed/Feed.tsx2
-rw-r--r--src/components/Header/SearchBar.tsx5
-rw-r--r--src/components/PollCard/PollCard.tsx26
-rw-r--r--src/components/UploadImage/UploadImage.tsx23
-rw-r--r--src/hooks/useNavigate.tsx1
-rw-r--r--src/pages/FeedPage/FeedPage.tsx3
-rw-r--r--src/pages/ProfilePage/ProfilePage.tsx1
7 files changed, 33 insertions, 28 deletions
diff --git a/src/components/Feed/Feed.tsx b/src/components/Feed/Feed.tsx
index c532f45..5814711 100644
--- a/src/components/Feed/Feed.tsx
+++ b/src/components/Feed/Feed.tsx
@@ -46,6 +46,8 @@ const Feed: React.FC<PropTypes> = ({ polls }) => {
rowRenderer={RenderItem}
scrollTop={scrollTop}
width={width}
+ containerStyle={{ pointerEvents: 'auto' }}
+ overscanRowCount={1}
/>
</div>
)}
diff --git a/src/components/Header/SearchBar.tsx b/src/components/Header/SearchBar.tsx
index 253e77f..ba0943b 100644
--- a/src/components/Header/SearchBar.tsx
+++ b/src/components/Header/SearchBar.tsx
@@ -31,6 +31,9 @@ const useStyles = makeStyles(theme => ({
position: 'absolute',
width: '100%',
top: theme.spacing(5)
+ },
+ listItem: {
+ padding: 0
}
}));
@@ -77,7 +80,7 @@ const SearchBar: React.FC = () => {
{
results.map((result, index) => (
<div key={result._id}>
- <ListItem button onClick={handleNavigate(index)}>
+ <ListItem button onClick={handleNavigate(index)} className={classes.listItem}>
<UserStrip user={result} />
</ListItem>
{(index < results.length - 1) && <Divider />}
diff --git a/src/components/PollCard/PollCard.tsx b/src/components/PollCard/PollCard.tsx
index 12f7198..f5a5762 100644
--- a/src/components/PollCard/PollCard.tsx
+++ b/src/components/PollCard/PollCard.tsx
@@ -7,9 +7,11 @@ import {
} from '@material-ui/core/';
import { Which, Poll } from 'which-types';
import { useSnackbar } from 'notistack';
+
import PercentageBar from './PercentageBar';
import UserStrip from '../UserStrip/UserStrip';
import { post } from '../../requests';
+import { useAuth } from '../../hooks/useAuth';
interface PropTypes {
initialPoll: Poll;
@@ -58,20 +60,30 @@ const PollCard: React.FC<PropTypes> = ({ initialPoll }) => {
const classes = useStyles();
const { author, contents: { left, right }, vote } = poll;
const { enqueueSnackbar } = useSnackbar();
+ const { isAuthenticated } = useAuth();
const date: string = new Date(poll.createdAt).toLocaleString('default', DATE_FORMAT);
const handleVote = (which: Which) => {
- if (vote) {
- enqueueSnackbar('You have already voted', {
+ if (!isAuthenticated()) {
+ enqueueSnackbar('Unauthorized users can not vote in polls', {
variant: 'error'
});
- return;
- }
- post('votes/', { which, pollId: poll._id }).then(response => {
+ } else if (vote) {
+ enqueueSnackbar('You have already voted in this poll', {
+ variant: 'error'
+ });
+ } else {
+ const newVote = ({ which, pollId: poll._id });
+ post('votes/', newVote);
poll.contents[which].votes += 1;
- poll.vote = response.data;
+ poll.vote = {
+ _id: '',
+ authorId: '',
+ createdAt: new Date(),
+ ...newVote
+ };
setPoll({ ...poll });
- });
+ }
};
const handleLeft = () => handleVote('left');
diff --git a/src/components/UploadImage/UploadImage.tsx b/src/components/UploadImage/UploadImage.tsx
index f5e680d..8ad65d5 100644
--- a/src/components/UploadImage/UploadImage.tsx
+++ b/src/components/UploadImage/UploadImage.tsx
@@ -6,7 +6,6 @@ import DialogActions from '@material-ui/core/DialogActions';
import DialogContent from '@material-ui/core/DialogContent';
import DialogContentText from '@material-ui/core/DialogContentText';
import DialogTitle from '@material-ui/core/DialogTitle';
-import get from 'axios';
interface PropTypes {
isOpen: boolean;
@@ -15,8 +14,7 @@ interface PropTypes {
}
const UploadImage: React.FC<PropTypes> = ({ setIsOpen, isOpen, callback }) => {
- const [url, setUrl] = useState('');
- const [isError, setIsError] = useState(false);
+ const [url, setUrl] = useState<string>('');
const handleClose = () => {
@@ -24,19 +22,8 @@ const UploadImage: React.FC<PropTypes> = ({ setIsOpen, isOpen, callback }) => {
};
const handleSubmit = () => {
- get(url).then(res => {
- if (res.headers['content-type'] === 'image/jpeg') {
- callback(url || '');
- setIsOpen(false);
- setIsError(false);
- } else {
- // console.warn(res); TODO: handle error if response status is ok but not an image
- setIsError(true);
- }
- }).catch(() => {
- // console.warn(err); TODO: handle error if resposne status is not ok
- setIsError(true);
- });
+ handleClose();
+ callback(url || '');
};
const handleChange = (event:React.ChangeEvent<HTMLInputElement>) => {
@@ -49,7 +36,7 @@ const UploadImage: React.FC<PropTypes> = ({ setIsOpen, isOpen, callback }) => {
<DialogTitle>Upload an Image</DialogTitle>
<DialogContent>
<DialogContentText>
- Unfortunetly we do not support uploading images yet. Please provide a valid URL to your image.
+ Unfortunetly we do not support uploading images yet. Please provide a valid URL to your image:
</DialogContentText>
<TextField
autoFocus
@@ -60,8 +47,6 @@ const UploadImage: React.FC<PropTypes> = ({ setIsOpen, isOpen, callback }) => {
fullWidth
autoComplete="off"
onChange={handleChange}
- error={isError}
- helperText={isError === true ? 'invalid Url!' : ''}
/>
</DialogContent>
<DialogActions>
diff --git a/src/hooks/useNavigate.tsx b/src/hooks/useNavigate.tsx
index befc529..47de4df 100644
--- a/src/hooks/useNavigate.tsx
+++ b/src/hooks/useNavigate.tsx
@@ -24,6 +24,7 @@ const useProvideNavigation = () => {
const navigate: ContextType['navigate'] = (prefix, id?) => {
setPage({ prefix, id });
+ window.scrollTo(0, 0);
};
return { page, setPage, navigate };
diff --git a/src/pages/FeedPage/FeedPage.tsx b/src/pages/FeedPage/FeedPage.tsx
index d29103a..b591141 100644
--- a/src/pages/FeedPage/FeedPage.tsx
+++ b/src/pages/FeedPage/FeedPage.tsx
@@ -19,7 +19,8 @@ const FeedPage: React.FC = () => {
const addPoll = (poll: Poll): void => {
polls.unshift(poll);
- setPolls([...polls]);
+ setPolls([]);
+ setPolls(polls);
};
diff --git a/src/pages/ProfilePage/ProfilePage.tsx b/src/pages/ProfilePage/ProfilePage.tsx
index 2c18466..b7106bb 100644
--- a/src/pages/ProfilePage/ProfilePage.tsx
+++ b/src/pages/ProfilePage/ProfilePage.tsx
@@ -22,6 +22,7 @@ const ProfilePage: React.FC = () => {
setUserInfo(response.data);
});
get(`/profiles/${id}`).then(response => {
+ setPolls([]);
setPolls(response.data);
setTotalVotes(response.data.reduce(
(total: number, current: Poll) => {