From 5b08023e0aa0e626264673ebb86dc82299a3b54b Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 27 Jun 2020 19:15:41 +0300 Subject: style: fix ALL linting errors --- src/pages/ProfilePage/Highlight.tsx | 39 ++++++++++++++++++ src/pages/ProfilePage/MoreMenu.tsx | 12 +++--- src/pages/ProfilePage/ProfileInfo.tsx | 77 ++++++++++++++++++----------------- src/pages/ProfilePage/ProfilePage.tsx | 31 ++++++++------ 4 files changed, 103 insertions(+), 56 deletions(-) create mode 100644 src/pages/ProfilePage/Highlight.tsx (limited to 'src/pages/ProfilePage') diff --git a/src/pages/ProfilePage/Highlight.tsx b/src/pages/ProfilePage/Highlight.tsx new file mode 100644 index 0000000..ebc3f56 --- /dev/null +++ b/src/pages/ProfilePage/Highlight.tsx @@ -0,0 +1,39 @@ +import React from 'react'; +import { makeStyles } from '@material-ui/core/styles'; + +interface PropTypes { + text: string; + value: string | number; +} + +const useStyles = makeStyles({ + root: { + position: 'relative' + }, + menuButton: { + width: 200, + height: 50, + textAlign: 'center' + }, + menuNumber: { + fontWeight: 800, + color: 'black' + }, + menuText: { + color: 'darkgray' + } +}); + + +const Highlight: React.FC = ({ text, value }) => { + const classes = useStyles(); + + return ( +
+
{value}
+
{text}
+
+ ); +}; + +export default Highlight; diff --git a/src/pages/ProfilePage/MoreMenu.tsx b/src/pages/ProfilePage/MoreMenu.tsx index a4bc993..bf3347b 100644 --- a/src/pages/ProfilePage/MoreMenu.tsx +++ b/src/pages/ProfilePage/MoreMenu.tsx @@ -3,7 +3,7 @@ import IconButton from '@material-ui/core/IconButton'; import Menu from '@material-ui/core/Menu'; import MenuItem from '@material-ui/core/MenuItem'; import MoreHorizIcon from '@material-ui/icons/MoreHoriz'; -import {makeStyles} from "@material-ui/core"; +import { makeStyles } from '@material-ui/core'; interface PropTypes { logOut: () => void; @@ -21,10 +21,10 @@ const useStyles = makeStyles({ const MoreMenu: React.FC = ({ logOut }) => { const classes = useStyles(); - const [anchorEl, setAnchorEl] = React.useState(null); + const [anchorEl, setAnchorEl] = React.useState(null); const open = Boolean(anchorEl); - const handleClick = (event: any) => { + const handleClick = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget); }; @@ -41,7 +41,7 @@ const MoreMenu: React.FC = ({ logOut }) => { aria-haspopup="true" onClick={handleClick} > - + = ({ logOut }) => { PaperProps={{ style: { maxHeight: ITEM_HEIGHT * 4.5, - width: '20ch', - }, + width: '20ch' + } }} > Log out diff --git a/src/pages/ProfilePage/ProfileInfo.tsx b/src/pages/ProfilePage/ProfileInfo.tsx index 27966e9..f52e374 100644 --- a/src/pages/ProfilePage/ProfileInfo.tsx +++ b/src/pages/ProfilePage/ProfileInfo.tsx @@ -1,12 +1,11 @@ -import React, {useRef, useState} from 'react'; -import {Avatar, Badge, TextField, withStyles} from '@material-ui/core/'; -import {makeStyles} from '@material-ui/core/styles'; -import {User} from 'which-types'; +import React, { useState } from 'react'; +import { Avatar, Badge } from '@material-ui/core/'; +import { makeStyles } from '@material-ui/core/styles'; +import { User } from 'which-types'; import CameraAltIcon from '@material-ui/icons/CameraAlt'; -import MoreMenu from "./MoreMenu"; -import {patch} from '../../requests'; -import Highlight from "../../components/Highlight/Highlight"; -import UploadImage from "../../components/UploadImage/UploadImage"; +import MoreMenu from './MoreMenu'; +import Highlight from './Highlight'; +import UploadImage from '../../components/UploadImage/UploadImage'; interface PropTypes { @@ -70,50 +69,54 @@ const useStyles = makeStyles(theme => ({ })); -const ProfileInfo: React.FC = ({user, logOut,savedPolls, totalVotes, setUserInfo,setUser}) => { +const ProfileInfo: React.FC = ({ + user, logOut, savedPolls, totalVotes, setUserInfo, setUser +}) => { const classes = useStyles(); - const [input,setInput] = useState(false); + const [input, setInput] = useState(false); + + const dateSince = new Date(user?.createdAt || '').toLocaleDateString(); const handleClick = () => { - input === false ? setInput(true) : setInput(false); + setInput(!input); }; return (
{ user?._id === localStorage.getItem('userId') - ? -
- -
- - -
- } - > - - + ? ( +
+ +
+ + +
+ )} + > + + +
+
- -
- : +) + : }
{user?.username}
- - - + + +
); diff --git a/src/pages/ProfilePage/ProfilePage.tsx b/src/pages/ProfilePage/ProfilePage.tsx index 479fd5c..b0ac103 100644 --- a/src/pages/ProfilePage/ProfilePage.tsx +++ b/src/pages/ProfilePage/ProfilePage.tsx @@ -12,7 +12,9 @@ interface PropTypes { setUser:(a:User)=>void; } -const ProfilePage: React.FC = ({ logOut, id, navigate,setUser }) => { +const ProfilePage: React.FC = ({ + logOut, id, navigate, setUser +}) => { const [userInfo, setUserInfo] = useState(); const [polls, setPolls] = useState([]); const [totalVotes, setTotalVotes] = useState(0); @@ -25,23 +27,26 @@ const ProfilePage: React.FC = ({ logOut, id, navigate,setUser }) => { useEffect(() => { get(`/profiles/${id}`).then(response => { - setPolls([]); - setPolls([...response.data]); - - // const x = response.data.reduce((a: any, c: any) => a.contents.left.votes + c.contents.left.votes); - // const y = response.data.reduce((a: any, c: any) => a.contents.right.votes + c.contents.right.votes); - let sum = 0; - for(let i = 0;i { + const { left, right } = current.contents; + return total + left.votes + right.votes; + }, 0 + )); }); }, [id, userInfo]); return ( <> - + ); -- cgit v1.2.3