From c7f2999ee797ea5e3bfb29517a4f13206162cc6f Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 14 Jun 2020 19:52:35 +0300 Subject: refactor: use lowercase in folder names --- src/pages/ProfilePage/ProfileInfo.tsx | 75 +++++++++++++++++++++++++++++++++++ src/pages/ProfilePage/ProfilePage.tsx | 25 ++++++++++++ src/pages/ProfilePage/SignInForm.tsx | 54 +++++++++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100644 src/pages/ProfilePage/ProfileInfo.tsx create mode 100644 src/pages/ProfilePage/ProfilePage.tsx create mode 100644 src/pages/ProfilePage/SignInForm.tsx (limited to 'src/pages') 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/ProfilePage.tsx b/src/pages/ProfilePage/ProfilePage.tsx new file mode 100644 index 0000000..ee95769 --- /dev/null +++ b/src/pages/ProfilePage/ProfilePage.tsx @@ -0,0 +1,25 @@ +import React from 'react'; +import { User } from '../../types'; +import SignInForm from './SignInForm'; +import ProfileInfo from './ProfileInfo'; +import Feed from '../../components/Feed/Feed'; + +interface PropTypes { + setUser: (newUser: User | undefined) => void; + user: User | undefined; +} + +const ProfilePage: React.FC = ({ setUser, user }) => { + 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; -- cgit v1.2.3 From 61a424debfbfa98570e070fbf25d03aa9c56d679 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 14 Jun 2020 20:39:16 +0300 Subject: refactor: structurize pages --- src/pages/AuthPage/AuthPage.tsx | 14 +++++++++ src/pages/AuthPage/SignInForm.tsx | 54 +++++++++++++++++++++++++++++++++++ src/pages/FeedPage/FeedPage.tsx | 19 ++++++++++++ src/pages/ProfilePage/ProfileInfo.tsx | 26 +++++------------ src/pages/ProfilePage/ProfilePage.tsx | 37 ++++++++++++++---------- src/pages/ProfilePage/SignInForm.tsx | 54 ----------------------------------- 6 files changed, 116 insertions(+), 88 deletions(-) create mode 100644 src/pages/AuthPage/AuthPage.tsx create mode 100644 src/pages/AuthPage/SignInForm.tsx create mode 100644 src/pages/FeedPage/FeedPage.tsx delete mode 100644 src/pages/ProfilePage/SignInForm.tsx (limited to 'src/pages') diff --git a/src/pages/AuthPage/AuthPage.tsx b/src/pages/AuthPage/AuthPage.tsx new file mode 100644 index 0000000..d9c43d3 --- /dev/null +++ b/src/pages/AuthPage/AuthPage.tsx @@ -0,0 +1,14 @@ +import React from 'react'; +import { User } from '../../types'; +import SignInForm from './SignInForm'; + +interface PropTypes { + setUser: (newUser: User | undefined) => void; +} + +const AuthPage: React.FC = ({ setUser }) => { + return ; +}; + +export default AuthPage; + diff --git a/src/pages/AuthPage/SignInForm.tsx b/src/pages/AuthPage/SignInForm.tsx new file mode 100644 index 0000000..6e27535 --- /dev/null +++ b/src/pages/AuthPage/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/pages/FeedPage/FeedPage.tsx b/src/pages/FeedPage/FeedPage.tsx new file mode 100644 index 0000000..03bacfd --- /dev/null +++ b/src/pages/FeedPage/FeedPage.tsx @@ -0,0 +1,19 @@ +import React, { useState, useEffect } from 'react'; +import { Poll } from '../../types'; +import Feed from '../../components/Feed/Feed'; +import { get } from '../../requests'; + +const FeedPage: React.FC = () => { + const [polls, setPolls] = useState([]); + + useEffect(() => { + get('/polls').then(response => { + setPolls(response.data); + }); + }, []); + + return ; +}; + +export default FeedPage; + 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 = ({ id, setUser }) => { - const [userInfo, setUserInfo] = useState(); - - get(`/users/${id}`).then(response => { - setUserInfo(response.data); - }); - +const ProfileInfo: React.FC = ({ user, logOut }) => { const classes = useStyles(); - const LogOut = () => { - localStorage.clear(); - setUser(undefined); - }; - return (
- +
- {userInfo?.name} + {user?.name}
@@ -67,7 +55,7 @@ const ProfileInfo: React.FC = ({ id, setUser }) => { Following
- +
); }; 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 = ({ setUser, user }) => { +const ProfilePage: React.FC = ({ logOut, id }) => { + const [userInfo, setUserInfo] = useState(); + const [polls, setPolls] = useState([]); + + get(`/users/${id}`).then(response => { + setUserInfo(response.data); + }); + + get(`/profiles/${id}`).then(response => { + setPolls(response.data); + }); + return ( - user - ? ( - <> - - - - ) - : - ); + <> + + + + ) }; 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 = ({ 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; -- cgit v1.2.3 From fbe489c83e9ef4c03b87624a4dec66de61af364a Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 14 Jun 2020 20:43:05 +0300 Subject: style: fix eslint errors --- src/pages/ProfilePage/ProfilePage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pages') diff --git a/src/pages/ProfilePage/ProfilePage.tsx b/src/pages/ProfilePage/ProfilePage.tsx index 023f37c..1dd71d3 100644 --- a/src/pages/ProfilePage/ProfilePage.tsx +++ b/src/pages/ProfilePage/ProfilePage.tsx @@ -26,7 +26,7 @@ const ProfilePage: React.FC = ({ logOut, id }) => { - ) + ); }; export default ProfilePage; -- cgit v1.2.3