From 657c340ea9e244b7f1041bac5be240d428d758e5 Mon Sep 17 00:00:00 2001 From: ilyayudovin Date: Sun, 14 Jun 2020 17:28:24 +0300 Subject: feat: add profilePage to render ProfileInfo and SignInForm --- src/Pages/ProfilePage/Form/SignInForm.tsx | 54 ---------------- src/Pages/ProfilePage/ProfileInfo.tsx | 75 +++++++++++++++++++++++ src/Pages/ProfilePage/ProfileInfo/ProfileInfo.tsx | 75 ----------------------- src/Pages/ProfilePage/ProfilePage.tsx | 30 +++++++++ src/Pages/ProfilePage/SignInForm.tsx | 54 ++++++++++++++++ src/index.tsx | 19 ++---- 6 files changed, 163 insertions(+), 144 deletions(-) delete mode 100644 src/Pages/ProfilePage/Form/SignInForm.tsx create mode 100644 src/Pages/ProfilePage/ProfileInfo.tsx delete mode 100644 src/Pages/ProfilePage/ProfileInfo/ProfileInfo.tsx create mode 100644 src/Pages/ProfilePage/ProfilePage.tsx create mode 100644 src/Pages/ProfilePage/SignInForm.tsx (limited to 'src') diff --git a/src/Pages/ProfilePage/Form/SignInForm.tsx b/src/Pages/ProfilePage/Form/SignInForm.tsx deleted file mode 100644 index bfdc283..0000000 --- a/src/Pages/ProfilePage/Form/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 = ({ setUser }) => { - const classes = useStyles(); - const inputRef = useRef(); - - 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 ( -
-

Sign In

- - - - - ); -}; - -export default SignInForm; diff --git a/src/Pages/ProfilePage/ProfileInfo.tsx b/src/Pages/ProfilePage/ProfileInfo.tsx new file mode 100644 index 0000000..8fce8df --- /dev/null +++ b/src/Pages/ProfilePage/ProfileInfo.tsx @@ -0,0 +1,75 @@ +import React, { useState } 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; +} + +const useStyles = makeStyles({ + avatar: { + margin: '0 auto', + width: 150, + height: 150, + marginBottom: 10 + }, + name: { + fontSize: 20, + textAlign: 'center' + }, + profileMenu: { + display: 'flex', + width: '100%', + height: 50, + borderBottom: '1px solid lightgray', + margin: '50px 0' + }, + menuButton: { + width: 200, + height: 50, + paddingTop: 15, + textAlign: 'center' + } +}); + +const ProfileInfo: React.FC = ({ id, setUser }) => { + const [userInfo, setUserInfo] = useState(); + + get(`/users/${id}`).then(response => { + setUserInfo(response.data); + }); + + const classes = useStyles(); + + const LogOut = () => { + localStorage.clear(); + setUser(undefined); + }; + + return ( +
+ +
+ {userInfo?.name} +
+
+
+ Polls +
+
+ Followers +
+
+ Following +
+
+ +
+ ); +}; + +export default ProfileInfo; diff --git a/src/Pages/ProfilePage/ProfileInfo/ProfileInfo.tsx b/src/Pages/ProfilePage/ProfileInfo/ProfileInfo.tsx deleted file mode 100644 index af866f8..0000000 --- a/src/Pages/ProfilePage/ProfileInfo/ProfileInfo.tsx +++ /dev/null @@ -1,75 +0,0 @@ -import React, { useState } 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; -} - -const useStyles = makeStyles({ - avatar: { - margin: '0 auto', - width: 150, - height: 150, - marginBottom: 10 - }, - name: { - fontSize: 20, - textAlign: 'center' - }, - profileMenu: { - display: 'flex', - width: '100%', - height: 50, - borderBottom: '1px solid lightgray', - margin: '50px 0' - }, - menuButton: { - width: 200, - height: 50, - paddingTop: 15, - textAlign: 'center' - } -}); - -const ProfileInfo: React.FC = ({ id, setUser }) => { - const [userInfo, setUserInfo] = useState(); - - get(`/users/${id}`).then(response => { - setUserInfo(response.data); - }); - - const classes = useStyles(); - - const LogOut = () => { - localStorage.clear(); - setUser(undefined); - }; - - return ( -
- -
- {userInfo?.name} -
-
-
- Polls -
-
- Followers -
-
- Following -
-
- -
- ); -}; - -export default ProfileInfo; diff --git a/src/Pages/ProfilePage/ProfilePage.tsx b/src/Pages/ProfilePage/ProfilePage.tsx new file mode 100644 index 0000000..8d082dc --- /dev/null +++ b/src/Pages/ProfilePage/ProfilePage.tsx @@ -0,0 +1,30 @@ +import React, {useState} from 'react'; +import {makeStyles} from '@material-ui/core/styles'; +import {User} from '../../types'; +import SignInForm from "./SignInForm"; +import ProfileInfo from "./ProfileInfo"; + +interface PropTypes { + id: string; + setUser: (newUser: User | undefined) => void; + user: User | undefined; +} + +const useStyles = makeStyles({ + +}); + +const ProfilePage: React.FC = ({id, setUser, user}) => { + const classes = useStyles(); + + return ( + user ? ( + <> + + + ) + : + ) +}; + +export default ProfilePage; diff --git a/src/Pages/ProfilePage/SignInForm.tsx b/src/Pages/ProfilePage/SignInForm.tsx new file mode 100644 index 0000000..6e27535 --- /dev/null +++ b/src/Pages/ProfilePage/SignInForm.tsx @@ -0,0 +1,54 @@ +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 = ({ setUser }) => { + const classes = useStyles(); + const inputRef = useRef(); + + 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 ( +
+

Sign In

+ + + + + ); +}; + +export default SignInForm; diff --git a/src/index.tsx b/src/index.tsx index ec31728..a5e1168 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -11,9 +11,9 @@ import 'typeface-roboto'; import Header from './Components/Header/Header'; import Feed from './Components/Feed/Feed'; -import ProfileInfo from './Pages/ProfilePage/ProfileInfo/ProfileInfo'; - -import SignInForm from './Pages/ProfilePage/Form/SignInForm'; +import ProfileInfo from './Pages/ProfilePage/ProfileInfo'; +import ProfilePage from './Pages/ProfilePage/ProfilePage'; +import SignInForm from './Pages/ProfilePage/SignInForm'; import { User } from './types'; import { get } from './requests'; @@ -53,18 +53,7 @@ const App: React.FC = () => {
{ - page === 'profile' - ? ( - user - ? ( - <> - - - - ) - : - ) - : + page === 'profile' ? : }
-- cgit v1.2.3