aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--package-lock.json6
-rw-r--r--package.json3
-rw-r--r--src/components/Feed/Feed.tsx2
-rw-r--r--src/components/PollCard/PollCard.tsx9
-rw-r--r--src/index.tsx7
-rw-r--r--src/pages/AuthPage/SignUpForm.tsx9
-rw-r--r--src/pages/FeedPage/FeedPage.tsx3
-rw-r--r--src/pages/ProfilePage/ProfileInfo.tsx4
-rw-r--r--src/pages/ProfilePage/ProfilePage.tsx3
-rw-r--r--src/types.d.ts19
10 files changed, 28 insertions, 37 deletions
diff --git a/package-lock.json b/package-lock.json
index 9b01055..dc8d8cd 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -14111,6 +14111,12 @@
"resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz",
"integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho="
},
+ "which-types": {
+ "version": "1.3.1",
+ "resolved": "https://registry.npmjs.org/which-types/-/which-types-1.3.1.tgz",
+ "integrity": "sha512-UU7+/FRfELIrUyZiTJkTDJ9dNxhW/ZVcWTjXn9TMtaqdIEDtu+NDFe13jZkFhlPVsVwwXa5R4n6MUa1iuLhAlg==",
+ "dev": true
+ },
"word-wrap": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz",
diff --git a/package.json b/package.json
index a8e1718..4584877 100644
--- a/package.json
+++ b/package.json
@@ -45,6 +45,7 @@
"eslint-plugin-react": "^7.20.0",
"eslint-plugin-react-hooks": "^2.5.1",
"gh-pages": "^3.0.0",
- "typescript": "^3.9.5"
+ "typescript": "^3.9.5",
+ "which-types": "^1.3.1"
}
}
diff --git a/src/components/Feed/Feed.tsx b/src/components/Feed/Feed.tsx
index 3b8e16f..c649935 100644
--- a/src/components/Feed/Feed.tsx
+++ b/src/components/Feed/Feed.tsx
@@ -1,6 +1,6 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
-import { Poll } from '../../types';
+import { Poll } from 'which-types';
import PollCard from '../PollCard/PollCard';
interface PropTypes {
diff --git a/src/components/PollCard/PollCard.tsx b/src/components/PollCard/PollCard.tsx
index 190d001..9f89d9a 100644
--- a/src/components/PollCard/PollCard.tsx
+++ b/src/components/PollCard/PollCard.tsx
@@ -7,7 +7,8 @@ import {
Avatar,
CardHeader
} from '@material-ui/core/';
-import { Poll } from '../../types';
+import { Which, Poll } from 'which-types';
+
import PercentageBar from './PercentageBar';
import {post} from '../../requests';
import teal from "@material-ui/core/colors/teal";
@@ -56,7 +57,7 @@ const PollCard: React.FC<PropTypes> = ({ poll, navigate }) => {
navigate('profile', poll.author._id);
};
- const vote = (which: 'left' | 'right') => {
+ const vote = (which: Which) => {
post(`polls/${ poll._id }/votes/`,{ which }).then((response)=>{
console.log(response.data);
const leftV = response.data.contents.left.votes;
@@ -78,12 +79,12 @@ const PollCard: React.FC<PropTypes> = ({ poll, navigate }) => {
<Avatar
aria-label="avatar"
src={author.avatarUrl}
- alt={author.name[0].toUpperCase()}
+ alt={author.username[0].toUpperCase()}
onClick={handleNavigate}
className={classes.avatar}
/>
)}
- title={author.name}
+ title={author.username}
/>
<div className={classes.imagesBlock}>
<CardActionArea onDoubleClick={() => vote('left')}>
diff --git a/src/index.tsx b/src/index.tsx
index 1777e90..4e6779a 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -13,7 +13,8 @@ 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 { User, Page } from './types';
+import { Page } from './types';
+import { User } from 'which-types';
import { get, post } from './requests';
import ScrollTopArrow from './components/ScrollTopArrow/ScrollTopArrow';
@@ -53,10 +54,10 @@ const App: React.FC = () => {
}
};
- const logIn = (name: string, password: string): Promise<boolean> => {
+ const logIn = (username: string, password: string): Promise<boolean> => {
return post('/authentication', {
strategy: 'local',
- name,
+ username,
password
}).then(response => {
const me = response.data.user;
diff --git a/src/pages/AuthPage/SignUpForm.tsx b/src/pages/AuthPage/SignUpForm.tsx
index 2769eb0..0e3d0c7 100644
--- a/src/pages/AuthPage/SignUpForm.tsx
+++ b/src/pages/AuthPage/SignUpForm.tsx
@@ -31,12 +31,11 @@ const SignUpForm: React.FC<PropTypes> = ({ logIn }) => {
const inputRefPassword = useRef<HTMLInputElement>();
const onClick = () => {
- const name = inputRef.current?.value;
+ const username = inputRef.current?.value;
const password = inputRefPassword.current?.value;
- const newUser = { name, password };
- if (name && password) {
- post('/users', newUser).then(() => {
- logIn(name, password);
+ if (username && password) {
+ post('/users', { username, password }).then(() => {
+ logIn(username, password);
});
}
};
diff --git a/src/pages/FeedPage/FeedPage.tsx b/src/pages/FeedPage/FeedPage.tsx
index fd75190..937b0a9 100644
--- a/src/pages/FeedPage/FeedPage.tsx
+++ b/src/pages/FeedPage/FeedPage.tsx
@@ -1,5 +1,6 @@
import React, { useState, useEffect } from 'react';
-import { Poll } from '../../types';
+import { Poll } from 'which-types';
+
import Feed from '../../components/Feed/Feed';
import { get } from '../../requests';
diff --git a/src/pages/ProfilePage/ProfileInfo.tsx b/src/pages/ProfilePage/ProfileInfo.tsx
index bddecd8..7208ec8 100644
--- a/src/pages/ProfilePage/ProfileInfo.tsx
+++ b/src/pages/ProfilePage/ProfileInfo.tsx
@@ -2,7 +2,7 @@ import React from 'react';
import { Avatar } from '@material-ui/core/';
import { makeStyles } from '@material-ui/core/styles';
import Button from '@material-ui/core/Button/Button';
-import { User } from '../../types';
+import { User } from 'which-types';
interface PropTypes {
user: User | undefined;
@@ -41,7 +41,7 @@ const ProfileInfo: React.FC<PropTypes> = ({ user, logOut }) => {
<div>
<Avatar className={classes.avatar} src={user?.avatarUrl} />
<div className={classes.name}>
- {user?.name}
+ {user?.username}
</div>
<div className={classes.profileMenu}>
<div style={{ borderBottom: '1px solid green', color: 'green' }} className={classes.menuButton}>
diff --git a/src/pages/ProfilePage/ProfilePage.tsx b/src/pages/ProfilePage/ProfilePage.tsx
index 0f5fb2b..363d4ff 100644
--- a/src/pages/ProfilePage/ProfilePage.tsx
+++ b/src/pages/ProfilePage/ProfilePage.tsx
@@ -1,5 +1,6 @@
import React, { useState, useEffect } from 'react';
-import { User, Poll } from '../../types';
+import { User, Poll } from 'which-types';
+
import ProfileInfo from './ProfileInfo';
import Feed from '../../components/Feed/Feed';
import { get } from '../../requests';
diff --git a/src/types.d.ts b/src/types.d.ts
index a62eec8..73346ce 100644
--- a/src/types.d.ts
+++ b/src/types.d.ts
@@ -2,23 +2,4 @@ export interface Page {
prefix: string;
id: string;
}
-export interface User {
- name: string;
- avatarUrl: string;
- _id: string;
-}
-
-interface ImageData {
- url: string;
- votes: number;
-}
-
-export interface Poll {
- _id: string;
- author: User;
- contents: {
- left: ImageData;
- right: ImageData;
- };
-}