Merge pull request #83 from ClaytonWWilson/edit-profile-linking

Changing profile page layout
This commit is contained in:
Leon Liang 2019-11-21 17:58:56 -05:00 committed by GitHub
commit 607ea3fd55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,222 +3,288 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import axios from 'axios'; import axios from 'axios';
//import '../App.css'; //import '../App.css';
// Material-UI
// Material UI and React Router import withStyles from '@material-ui/core/styles/withStyles';
import { makeStyles, styled } from "@material-ui/core/styles"; import { makeStyles, styled } from '@material-ui/core/styles';
import { Link } from 'react-router-dom'; 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 CardMedia from '@material-ui/core/CardMedia';
import CardContent from '@material-ui/core/CardContent'; import CardContent from '@material-ui/core/CardContent';
import Button from '@material-ui/core/Button'; 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 Chip from '@material-ui/core/Chip';
import Typography from "@material-ui/core/Typography"; import Typography from '@material-ui/core/Typography';
import AddCircle from '@material-ui/icons/AddCircle'; import AddCircle from '@material-ui/icons/AddCircle';
import TextField from '@material-ui/core/TextField'; import TextField from '@material-ui/core/TextField';
import VerifiedIcon from '@material-ui/icons/CheckSharp'; import VerifiedIcon from '@material-ui/icons/CheckSharp';
import Paper from '@material-ui/core/Paper';
import GridList from '@material-ui/core/GridList';
import GridListTile from '@material-ui/core/GridListTile';
import GridListTileBar from '@material-ui/core/GridListTileBar';
import Container from '@material-ui/core/Container';
// component // component
import '../App.css'; import '../App.css';
import noImage from '../images/no-img.png'; import noImage from '../images/no-img.png';
import Writing_Microblogs from '../Writing_Microblogs'; import Writing_Microblogs from '../Writing_Microblogs';
const MyChip = styled(Chip)({ const MyChip = styled(Chip)({
margin: 2, margin: 2,
color: "primary" color: 'primary'
}); });
const styles = {
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 { class user extends Component {
state = { state = {
profile: null, profile: null,
imageUrl: null, imageUrl: null,
topics: null, topics: null,
newTopic: null newTopic: null
}; };
handleDelete = topic => { handleDelete = (topic) => {
axios axios
.delete(`/deleteTopic/${topic.id}`) .delete(`/deleteTopic/${topic.id}`)
.then(function() { .then(function() {
location.reload(); location.reload();
}) })
.catch(function(err) { .catch(function(err) {
console.log(err); console.log(err);
}); });
}; };
handleAddCircle = () => { handleAddCircle = () => {
axios axios
.post("/putTopic", { .post('/putTopic', {
topic: this.state.newTopic topic: this.state.newTopic
}) })
.then(function() { .then(function() {
location.reload(); location.reload();
}) })
.catch(function(err) { .catch(function(err) {
console.log(err); console.log(err);
}); });
}; };
handleChange(event) { handleChange(event) {
this.setState({ this.setState({
newTopic: event.target.value newTopic: event.target.value
}); });
} }
componentDidMount() { componentDidMount() {
axios axios
.get("/user") .get('/user')
.then(res => { .then((res) => {
this.setState({ this.setState({
profile: res.data.credentials.handle, profile: res.data.credentials.handle,
imageUrl: res.data.credentials.imageUrl, imageUrl: res.data.credentials.imageUrl,
verified: res.data.credentials.verified ? res.data.credentials.verified : false verified: res.data.credentials.verified ? res.data.credentials.verified : false
}); });
}) })
.catch(err => console.log(err)); .catch((err) => console.log(err));
axios axios
.get("/getAllTopics") .get('/getAllTopics')
.then(res => { .then((res) => {
this.setState({ this.setState({
topics: res.data topics: res.data
}); });
}) })
.catch(err => console.log(err)); .catch((err) => console.log(err));
axios axios
.get("/getallPostsforUser") .get('/getallPostsforUser')
.then(res => { .then((res) => {
console.log(res.data); console.log(res.data);
this.setState({ this.setState({
posts: res.data posts: res.data
}) });
}) })
.catch(err => console.log(err)); .catch((err) => console.log(err));
} }
render() { render() {
let authenticated = this.props.user.authenticated; const { classes } = this.props;
let classes = this.props; let authenticated = this.props.user.authenticated;
let profileMarkup = this.state.profile ? ( let profileMarkup = this.state.profile ? (
<div> <div>
<Typography variant='h5'>@{this.state.profile} {this.state.verified ? (<VerifiedIcon style={{fill: "#1397D5"}}/>): (null)}</Typography> <Typography variant="h5" className={classes.username}>
</div>) : (<p>loading username...</p>); @{this.state.profile} {this.state.verified ? <VerifiedIcon style={{ fill: '#1397D5' }} /> : null}
</Typography>
</div>
) : (
<p className={classes.username}>loading username...</p>
);
let topicsMarkup = this.state.topics ? ( let topicsMarkup = this.state.topics ? (
this.state.topics.map( this.state.topics.map(
topic => ( (topic) => (
<MyChip <MyChip
label={{ topic }.topic.topic} label={{ topic }.topic.topic}
key={{ topic }.topic.id} key={{ topic }.topic.id}
onDelete={key => this.handleDelete(topic)} onDelete={(key) => this.handleDelete(topic)}
/> />
) // console.log({ topic }.topic.id) ) // console.log({ topic }.topic.id)
) )
) : ( ) : (
<p> loading topics...</p> <p> loading topics...</p>
); );
let imageMarkup = this.state.imageUrl ? (<img src={this.state.imageUrl} height="150" width="150" />) : let imageMarkup = this.state.imageUrl ? (
(<img src={noImage} height="150" width="150"/>); <img className={classes.profileImage} src={this.state.imageUrl} height="250" width="250" />
) : (
<img className={classes.profileImage} src={noImage} height="250" width="250" />
);
let postMarkup = this.state.posts ? ( let postMarkup = this.state.posts ? (
this.state.posts.map(post => this.state.posts.map((post) => (
<Card> <Card className={classes.card}>
<CardContent> <CardContent>
<Typography> <Typography>
{ {this.state.imageUrl ? (
this.state.imageUrl ? (<img src={this.state.imageUrl} height="250" width="250" />) : <img src={this.state.imageUrl} height="50" width="50" />
(<img src={noImage} height="50" width="50"/>) ) : (
} <img src={noImage} height="50" width="50" />
</Typography> )}
<Typography variant="h7"><b>{post.userHandle}</b></Typography> </Typography>
<Typography variant="body2" color={"textSecondary"}>{post.createdAt}</Typography> <Typography variant="h7">
<br /> <b>{post.userHandle}</b>
<Typography variant="body1"><b>{post.microBlogTitle}</b></Typography> </Typography>
<Typography variant="body2">{post.body}</Typography> <Typography variant="body2" color={'textSecondary'}>
<br /> {post.createdAt}
<Typography variant="body2"><b>Topics:</b> {post.microBlogTopics}</Typography> </Typography>
<br /> <br />
<Typography variant="body2" color={"textSecondary"}>Likes {post.likeCount} Comments {post.commentCount}</Typography> <Typography variant="body1">
</CardContent> <b>{post.microBlogTitle}</b>
</Card> </Typography>
) <Typography variant="body2">{post.body}</Typography>
) : (<p>My Posts</p>); <br />
<Typography variant="body2">
<b>Topics:</b> {post.microBlogTopics}
</Typography>
<br />
<Typography variant="body2" color={'textSecondary'}>
Likes {post.likeCount} Comments {post.commentCount}
</Typography>
</CardContent>
</Card>
))
) : (
<p>My Posts</p>
);
return ( // FIX: This needs to check if user's profile page being displayed
<Grid container spacing={24}> // is the same as the user who is logged in
<Grid item sm={4} xs={8}> // Can't check for that right now, because this page is always
{imageMarkup} // showing the logged in users profile, instead of retreiving the
{profileMarkup} // profile based on the URL entered
{topicsMarkup} let editButtonMarkup = true ? (
<TextField <Link to="/edit">
id="newTopic" <Button className={classes.button} variant="outlined" color="primary">
label="new topic" Edit Profile
defaultValue="" </Button>
margin="normal" </Link>
variant="outlined" ) : null;
value={this.state.newTopic}
onChange={(event) => this.handleChange(event)}
/>
<AddCircle
color="primary"
clickable
onClick={this.handleAddCircle}
/>
<br />
<Grid container direction="column">
<Grid item>
{
authenticated &&
<Button
style={{width:150, marginBottom: 10, marginTop: 5}}
component={ Link }
to='/edit'
variant="outlined"
color="primary"
>
Edit Profile
</Button>}
</Grid>
<Grid item>
{
authenticated &&
this.state.profile === 'Admin' &&
<Button
style={{width:150}}
component={ Link }
variant="outlined"
color="primary"
to='/verify' return (
> <div>
Verify Users {/* <Paper className={classes.paper}> */}
</Button>} <Grid container direction="column">
</Grid> <Grid item>
</Grid> <Grid container>
</Grid> <Grid item sm>
<Grid item sm={4} xs={8}> {editButtonMarkup}
{postMarkup} </Grid>
</Grid> <Grid item sm>
<Grid item sm={4} xs={8}> {/* <Grid container direction="column"> */}
<Writing_Microblogs /> {/* <Grid item sm> */}
</Grid> {imageMarkup}
       {profileMarkup}
</Grid> {/* </Grid> */}
); {/* <Grid item sm> */}
} {/* {postMarkup} */}
{/* </Grid> */}
{/* </Grid> */}
</Grid>
<Grid item sm>
<Container className={classes.topicsContainer} maxWidth="xs">
{topicsMarkup}
</Container>
<TextField
id="newTopic"
label="new topic"
defaultValue=""
margin="normal"
variant="outlined"
value={this.state.newTopic}
onChange={(event) => this.handleChange(event)}
/>
<AddCircle
className={classes.addCircle}
color="primary"
// iconStyle={classes.addCircle}
clickable
onClick={this.handleAddCircle}
/>
</Grid>
</Grid>
</Grid>
<Grid item>
<Grid container>
<Grid item sm />
<Grid item>{postMarkup}</Grid>
<Grid item sm />
</Grid>
</Grid>
</Grid>
</div>
);
}
} }
const mapStateToProps = (state) => ({ const mapStateToProps = (state) => ({
user: state.user user: state.user
}) });
user.propTypes = { user.propTypes = {
user: PropTypes.object.isRequired user: PropTypes.object.isRequired
} };
export default connect(mapStateToProps)(user); export default connect(mapStateToProps)(withStyles(styles)(user));