aboutsummaryrefslogtreecommitdiff
path: root/src/pages/ProfilePage
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-06-14 20:39:16 +0300
committereug-vs <eug-vs@keemail.me>2020-06-14 20:39:16 +0300
commit61a424debfbfa98570e070fbf25d03aa9c56d679 (patch)
tree0c032edf74571350fd0f5f9251a3493a487b6008 /src/pages/ProfilePage
parentc7f2999ee797ea5e3bfb29517a4f13206162cc6f (diff)
downloadwhich-ui-61a424debfbfa98570e070fbf25d03aa9c56d679.tar.gz
refactor: structurize pages
Diffstat (limited to 'src/pages/ProfilePage')
-rw-r--r--src/pages/ProfilePage/ProfileInfo.tsx26
-rw-r--r--src/pages/ProfilePage/ProfilePage.tsx37
-rw-r--r--src/pages/ProfilePage/SignInForm.tsx54
3 files changed, 29 insertions, 88 deletions
diff --git a/src/pages/ProfilePage/ProfileInfo.tsx b/src/pages/ProfilePage/ProfileInfo.tsx
index 8fce8df..c2f242a 100644
--- a/src/pages/ProfilePage/ProfileInfo.tsx
+++ b/src/pages/ProfilePage/ProfileInfo.tsx
@@ -1,13 +1,12 @@
-import React, { useState } from 'react';
+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 { get } from '../../requests';
interface PropTypes {
- id: string;
- setUser: (newUser: User | undefined) => void;
+ user: User | undefined;
+ logOut: () => void;
}
const useStyles = makeStyles({
@@ -36,25 +35,14 @@ const useStyles = makeStyles({
}
});
-const ProfileInfo: React.FC<PropTypes> = ({ id, setUser }) => {
- const [userInfo, setUserInfo] = useState<User>();
-
- get(`/users/${id}`).then(response => {
- setUserInfo(response.data);
- });
-
+const ProfileInfo: React.FC<PropTypes> = ({ user, logOut }) => {
const classes = useStyles();
- const LogOut = () => {
- localStorage.clear();
- setUser(undefined);
- };
-
return (
<div>
- <Avatar className={classes.avatar} src={userInfo?.avatarUrl} />
+ <Avatar className={classes.avatar} src={user?.avatarUrl} />
<div className={classes.name}>
- {userInfo?.name}
+ {user?.name}
</div>
<div className={classes.profileMenu}>
<div style={{ borderBottom: '1px solid green', color: 'green' }} className={classes.menuButton}>
@@ -67,7 +55,7 @@ const ProfileInfo: React.FC<PropTypes> = ({ id, setUser }) => {
Following
</div>
</div>
- <Button variant="contained" onClick={LogOut}>Log Out</Button>
+ <Button variant="contained" onClick={logOut}>Log Out</Button>
</div>
);
};
diff --git a/src/pages/ProfilePage/ProfilePage.tsx b/src/pages/ProfilePage/ProfilePage.tsx
index ee95769..023f37c 100644
--- a/src/pages/ProfilePage/ProfilePage.tsx
+++ b/src/pages/ProfilePage/ProfilePage.tsx
@@ -1,25 +1,32 @@
-import React from 'react';
-import { User } from '../../types';
-import SignInForm from './SignInForm';
+import React, { useState } from 'react';
+import { User, Poll } from '../../types';
import ProfileInfo from './ProfileInfo';
import Feed from '../../components/Feed/Feed';
+import { get } from '../../requests';
interface PropTypes {
- setUser: (newUser: User | undefined) => void;
- user: User | undefined;
+ logOut: () => void;
+ id: string;
}
-const ProfilePage: React.FC<PropTypes> = ({ setUser, user }) => {
+const ProfilePage: React.FC<PropTypes> = ({ logOut, id }) => {
+ const [userInfo, setUserInfo] = useState<User>();
+ const [polls, setPolls] = useState<Poll[]>([]);
+
+ get(`/users/${id}`).then(response => {
+ setUserInfo(response.data);
+ });
+
+ get(`/profiles/${id}`).then(response => {
+ setPolls(response.data);
+ });
+
return (
- user
- ? (
- <>
- <ProfileInfo id={user?._id} setUser={setUser} />
- <Feed page="Feed" />
- </>
- )
- : <SignInForm setUser={setUser} />
- );
+ <>
+ <ProfileInfo user={userInfo} logOut={logOut} />
+ <Feed polls={polls} />
+ </>
+ )
};
export default ProfilePage;
diff --git a/src/pages/ProfilePage/SignInForm.tsx b/src/pages/ProfilePage/SignInForm.tsx
deleted file mode 100644
index 6e27535..0000000
--- a/src/pages/ProfilePage/SignInForm.tsx
+++ /dev/null
@@ -1,54 +0,0 @@
-import React, { useRef } from 'react';
-import { makeStyles } from '@material-ui/core/styles';
-import TextField from '@material-ui/core/TextField';
-import Button from '@material-ui/core/Button';
-import { User } from '../../types';
-import { get } from '../../requests';
-
-interface PropTypes {
- setUser: (newUser: User) => void;
-}
-
-const useStyles = makeStyles(theme => ({
- root: {
- '& > *': {
- margin: theme.spacing(1),
- width: '25ch'
- },
- display: 'flex',
- flexDirection: 'column',
- alignItems: 'center',
- textAlign: 'center'
- }
-}));
-
-const SignInForm: React.FC<PropTypes> = ({ setUser }) => {
- const classes = useStyles();
- const inputRef = useRef<HTMLInputElement>();
-
- const onClick = () => {
- const username = inputRef.current?.value;
- if (username) {
- get(`/users?name=${username}`).then(response => {
- const user = response.data[0];
- setUser(user);
- localStorage.setItem('userId', user._id);
- });
- }
- };
-
- return (
- <form className={classes.root} noValidate autoComplete="off">
- <h1>Sign In</h1>
- <TextField inputRef={inputRef} id="standard-basic" label="Login" />
- <TextField
- id="standard-password-input"
- label="Password"
- type="password"
- />
- <Button variant="contained" onClick={onClick}>submit</Button>
- </form>
- );
-};
-
-export default SignInForm;