diff --git a/twistter-frontend/src/pages/user.js b/twistter-frontend/src/pages/user.js index 82add8f..8733ae9 100644 --- a/twistter-frontend/src/pages/user.js +++ b/twistter-frontend/src/pages/user.js @@ -6,16 +6,16 @@ import axios from 'axios'; //import '../App.css'; // Material UI and React Router -import { makeStyles, styled } from "@material-ui/core/styles"; +import { makeStyles, styled } from '@material-ui/core/styles'; import { Link } from 'react-router-dom'; -import Card from "@material-ui/core/Card"; +import Card from '@material-ui/core/Card'; import CardMedia from '@material-ui/core/CardMedia'; import CardContent from '@material-ui/core/CardContent'; import Button from '@material-ui/core/Button'; -import Grid from "@material-ui/core/Grid"; +import Grid from '@material-ui/core/Grid'; -import Chip from "@material-ui/core/Chip"; -import Typography from "@material-ui/core/Typography"; +import Chip from '@material-ui/core/Chip'; +import Typography from '@material-ui/core/Typography'; import AddCircle from '@material-ui/icons/AddCircle'; import TextField from '@material-ui/core/TextField'; import VerifiedIcon from '@material-ui/icons/CheckSharp'; @@ -32,159 +32,186 @@ import noImage from '../images/no-img.png'; import Writing_Microblogs from '../Writing_Microblogs'; const MyChip = styled(Chip)({ - margin: 2, - color: "primary" + margin: 2, + color: 'primary' }); const styles = { - button: { - positon: 'relative', - float: 'left', - marginLeft: 30, - marginTop: 20 - }, - paper: { - // marginLeft: "10%", - // marginRight: "10%" - }, - profileImage: { - marginTop: 20 - }, - topicsContainer: { - border: "lightgray solid 1px", - marginTop: 20, - paddingTop: 10, - paddingBottom: 10, - height: 300 - }, - addCircle: { - width: 65, - height: 65, - marginTop: 10 - } + button: { + positon: 'relative', + float: 'left', + marginLeft: 30, + marginTop: 20 + }, + paper: { + // marginLeft: "10%", + // marginRight: "10%" + }, + card: { + marginBottom: 10 + }, + profileImage: { + marginTop: 20 + }, + topicsContainer: { + border: 'lightgray solid 1px', + marginTop: 20, + paddingTop: 10, + paddingBottom: 10, + height: 300 + }, + addCircle: { + width: 65, + height: 65, + marginTop: 10 + }, + username: { + marginBottom: 100 + } }; class user extends Component { - state = { - profile: null, - imageUrl: null, - topics: null, - newTopic: null - }; + state = { + profile: null, + imageUrl: null, + topics: null, + newTopic: null + }; - handleDelete = topic => { - axios - .delete(`/deleteTopic/${topic.id}`) - .then(function() { - location.reload(); - }) - .catch(function(err) { - console.log(err); - }); - }; + handleDelete = (topic) => { + axios + .delete(`/deleteTopic/${topic.id}`) + .then(function() { + location.reload(); + }) + .catch(function(err) { + console.log(err); + }); + }; - handleAddCircle = () => { - axios - .post("/putTopic", { - topic: this.state.newTopic - }) - .then(function() { - location.reload(); - }) - .catch(function(err) { - console.log(err); - }); - }; + handleAddCircle = () => { + axios + .post('/putTopic', { + topic: this.state.newTopic + }) + .then(function() { + location.reload(); + }) + .catch(function(err) { + console.log(err); + }); + }; - handleChange(event) { - this.setState({ - newTopic: event.target.value - }); - } + handleChange(event) { + this.setState({ + newTopic: event.target.value + }); + } - componentDidMount() { - axios - .get("/user") - .then((res) => { - this.setState({ - profile: res.data.credentials.handle, - imageUrl: res.data.credentials.imageUrl, - verified: res.data.credentials.verified ? res.data.credentials.verified : false - }); - }) - .catch((err) => console.log(err)); + componentDidMount() { + axios + .get('/user') + .then((res) => { + this.setState({ + profile: res.data.credentials.handle, + imageUrl: res.data.credentials.imageUrl, + verified: res.data.credentials.verified ? res.data.credentials.verified : false + }); + }) + .catch((err) => console.log(err)); - axios - .get("/getAllTopics") - .then((res) => { - this.setState({ - topics: res.data - }); - }) - .catch(err => console.log(err)); + axios + .get('/getAllTopics') + .then((res) => { + this.setState({ + topics: res.data + }); + }) + .catch((err) => console.log(err)); - axios - .get("/getallPostsforUser") - .then(res => { - console.log(res.data); - this.setState({ - posts: res.data - }) - }) - .catch(err => console.log(err)); - } + axios + .get('/getallPostsforUser') + .then((res) => { + console.log(res.data); + this.setState({ + posts: res.data + }); + }) + .catch((err) => console.log(err)); + } - render() { - const { classes } = this.props; - let authenticated = this.props.user.authenticated; + render() { + const { classes } = this.props; + let authenticated = this.props.user.authenticated; - let profileMarkup = this.state.profile ? ( -
loading username...
); - - let topicsMarkup = this.state.topics ? ( - this.state.topics.map( - topic => ( -loading topics...
- ); + let profileMarkup = this.state.profile ? ( +loading username...
+ ); - let imageMarkup = this.state.imageUrl ? (loading topics...
+ ); - let postMarkup = this.state.posts ? ( - this.state.posts.map(post => -My Posts
); + let imageMarkup = this.state.imageUrl ? ( +My Posts
+ ); + + // FIX: This needs to check if user's profile page being displayed // is the same as the user who is logged in // Can't check for that right now, because this page is always // showing the logged in users profile, instead of retreiving the @@ -195,59 +222,68 @@ class user extends Component { ) : null; - return ( -