diff options
-rw-r--r-- | package-lock.json | 9 | ||||
-rw-r--r-- | package.json | 8 | ||||
-rw-r--r-- | src/components/PollCard/PollCard.tsx | 18 | ||||
-rw-r--r-- | src/index.tsx | 2 | ||||
-rw-r--r-- | src/requests.ts | 7 |
5 files changed, 25 insertions, 19 deletions
diff --git a/package-lock.json b/package-lock.json index 572165e..f9311e4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1629,6 +1629,12 @@ "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.4.tgz", "integrity": "sha512-8+KAKzEvSUdeo+kmqnKrqgeE+LcA0tjYWFY7RPProVYwnqDjukzO+3b6dLD56rYX5TdWejnEOLJYOIeh4CXKuA==" }, + "@types/lodash": { + "version": "4.14.157", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.157.tgz", + "integrity": "sha512-Ft5BNFmv2pHDgxV5JDsndOWTRJ+56zte0ZpYLowp03tW+K+t8u8YMOzAnpuqPgzX6WO1XpDIUm7u04M8vdDiVQ==", + "dev": true + }, "@types/minimatch": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz", @@ -14114,8 +14120,7 @@ "which-types": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/which-types/-/which-types-1.4.1.tgz", - "integrity": "sha512-ZtN3cDwz/fQbJBwrItsZ0jpGafReTd/fIffHNQtFW4THrZqi8z4qnFTbyu1M6LnAmPlwU/FaRLZPfd67ZQ4mFw==", - "dev": true + "integrity": "sha512-ZtN3cDwz/fQbJBwrItsZ0jpGafReTd/fIffHNQtFW4THrZqi8z4qnFTbyu1M6LnAmPlwU/FaRLZPfd67ZQ4mFw==" }, "word-wrap": { "version": "1.2.3", diff --git a/package.json b/package.json index 22e3488..98f44df 100644 --- a/package.json +++ b/package.json @@ -6,11 +6,13 @@ "@material-ui/core": "^4.10.1", "@material-ui/icons": "^4.9.1", "axios": "^0.19.2", + "lodash": "^4.17.15", "react": "^16.13.1", "react-dom": "^16.13.1", "react-icons": "^3.10.0", "react-scripts": "3.4.1", - "typeface-roboto": "0.0.75" + "typeface-roboto": "0.0.75", + "which-types": "^1.4.1" }, "scripts": { "start": "react-scripts start", @@ -32,6 +34,7 @@ ] }, "devDependencies": { + "@types/lodash": "^4.14.157", "@types/node": "^12.12.44", "@types/react": "^16.9.35", "@types/react-dom": "^16.9.8", @@ -45,7 +48,6 @@ "eslint-plugin-react": "^7.20.0", "eslint-plugin-react-hooks": "^2.5.1", "gh-pages": "^3.0.0", - "typescript": "^3.9.5", - "which-types": "^1.4.1" + "typescript": "^3.9.5" } } diff --git a/src/components/PollCard/PollCard.tsx b/src/components/PollCard/PollCard.tsx index 82d94e9..06d33d5 100644 --- a/src/components/PollCard/PollCard.tsx +++ b/src/components/PollCard/PollCard.tsx @@ -1,4 +1,4 @@ -import React, {useState} from 'react'; +import React, { useState } from 'react'; import { makeStyles } from '@material-ui/core/styles'; import { Card, @@ -21,7 +21,7 @@ const useStyles = makeStyles(theme => ({ root: { maxWidth: theme.spacing(75), height: 488, - margin: '40px auto', + margin: '40px auto' }, images: { height: theme.spacing(50), @@ -34,7 +34,7 @@ const useStyles = makeStyles(theme => ({ cursor: 'pointer' }, rateLine: { - position:'relative', + position: 'relative', margin: '0 auto', width: '100%', height: theme.spacing(2), @@ -61,12 +61,10 @@ const PollCard: React.FC<PropTypes> = ({ initialPoll, navigate }) => { post('votes/', { which, pollId: poll._id }).then(() => { poll.contents[which].votes += 1; poll.userChoice = which; - setPoll({ ...poll}); - }).catch(error => { - console.log(error.response) + setPoll({ ...poll }); }); }; - + const handleLeft = () => vote('left'); const handleRight = () => vote('right'); @@ -93,18 +91,18 @@ const PollCard: React.FC<PropTypes> = ({ initialPoll, navigate }) => { className={classes.images} image={left.url} /> - <PercentageBar value={leftPercentage} which="left" like={userChoice === 'left'}/> + <PercentageBar value={leftPercentage} which="left" like={userChoice === 'left'} /> </CardActionArea> <CardActionArea onDoubleClick={handleRight}> <CardMedia className={classes.images} image={right.url} /> - <PercentageBar value={rightPercentage} which="right" like={userChoice === 'right'}/> + <PercentageBar value={rightPercentage} which="right" like={userChoice === 'right'} /> </CardActionArea> </div> <div className={classes.rateLine}> - <div className={classes.fillRateLine} style={{width: `${leftPercentage}%`}} /> + <div className={classes.fillRateLine} style={{ width: `${leftPercentage}%` }} /> </div> </Card> ); diff --git a/src/index.tsx b/src/index.tsx index 2b7c689..50b19f7 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -9,12 +9,12 @@ import { CssBaseline } from '@material-ui/core'; import teal from '@material-ui/core/colors/teal'; import 'typeface-roboto'; +import { User } from 'which-types'; import Header from './components/Header/Header'; import ProfilePage from './pages/ProfilePage/ProfilePage'; import FeedPage from './pages/FeedPage/FeedPage'; import AuthPage from './pages/AuthPage/AuthPage'; import { Page } from './types'; -import { User } from 'which-types'; import { get, post } from './requests'; import ScrollTopArrow from './components/ScrollTopArrow/ScrollTopArrow'; diff --git a/src/requests.ts b/src/requests.ts index fa84c4a..4cfd37b 100644 --- a/src/requests.ts +++ b/src/requests.ts @@ -1,12 +1,13 @@ import axios from 'axios'; +import _ from 'lodash'; const requests = axios.create({ - baseURL: 'http://localhost:3030', + baseURL: 'http://localhost:3030' }); requests.interceptors.request.use(config => { - config.headers.Authorization = localStorage.getItem('token'); - return config; + const token = localStorage.getItem('token'); + return _.set(config, 'headers.Authorization', token); }); export const { get, post, put } = requests; |