Profile page kinda works on mobile

This commit is contained in:
Clayton Wilson 2019-11-05 17:35:16 -05:00
parent 80670d054e
commit 6149e15b35

View File

@ -6,16 +6,16 @@ import axios from 'axios';
//import '../App.css'; //import '../App.css';
// Material UI and React Router // 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 { 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';
@ -33,7 +33,7 @@ import Writing_Microblogs from '../Writing_Microblogs';
const MyChip = styled(Chip)({ const MyChip = styled(Chip)({
margin: 2, margin: 2,
color: "primary" color: 'primary'
}); });
const styles = { const styles = {
@ -47,11 +47,14 @@ const styles = {
// marginLeft: "10%", // marginLeft: "10%",
// marginRight: "10%" // marginRight: "10%"
}, },
card: {
marginBottom: 10
},
profileImage: { profileImage: {
marginTop: 20 marginTop: 20
}, },
topicsContainer: { topicsContainer: {
border: "lightgray solid 1px", border: 'lightgray solid 1px',
marginTop: 20, marginTop: 20,
paddingTop: 10, paddingTop: 10,
paddingBottom: 10, paddingBottom: 10,
@ -61,6 +64,9 @@ const styles = {
width: 65, width: 65,
height: 65, height: 65,
marginTop: 10 marginTop: 10
},
username: {
marginBottom: 100
} }
}; };
@ -72,7 +78,7 @@ class user extends Component {
newTopic: null newTopic: null
}; };
handleDelete = topic => { handleDelete = (topic) => {
axios axios
.delete(`/deleteTopic/${topic.id}`) .delete(`/deleteTopic/${topic.id}`)
.then(function() { .then(function() {
@ -85,7 +91,7 @@ class user extends Component {
handleAddCircle = () => { handleAddCircle = () => {
axios axios
.post("/putTopic", { .post('/putTopic', {
topic: this.state.newTopic topic: this.state.newTopic
}) })
.then(function() { .then(function() {
@ -104,7 +110,7 @@ class user extends Component {
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,
@ -115,23 +121,23 @@ class user extends Component {
.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() {
@ -140,16 +146,21 @@ class user extends Component {
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)
) )
@ -157,32 +168,48 @@ class user extends Component {
<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="50" width="50" />) : <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 variant="body2" color={'textSecondary'}>
{post.createdAt}
</Typography> </Typography>
<Typography variant="h7"><b>{post.userHandle}</b></Typography>
<Typography variant="body2" color={"textSecondary"}>{post.createdAt}</Typography>
<br /> <br />
<Typography variant="body1"><b>{post.microBlogTitle}</b></Typography> <Typography variant="body1">
<b>{post.microBlogTitle}</b>
</Typography>
<Typography variant="body2">{post.body}</Typography> <Typography variant="body2">{post.body}</Typography>
<br /> <br />
<Typography variant="body2"><b>Topics:</b> {post.microBlogTopics}</Typography> <Typography variant="body2">
<b>Topics:</b> {post.microBlogTopics}
</Typography>
<br /> <br />
<Typography variant="body2" color={"textSecondary"}>Likes {post.likeCount} Comments {post.commentCount}</Typography> <Typography variant="body2" color={'textSecondary'}>
Likes {post.likeCount} Comments {post.commentCount}
</Typography>
</CardContent> </CardContent>
</Card> </Card>
) ))
) : (<p>My Posts</p>); ) : (
<p>My Posts</p>
);
// FIX: This needs to check if user's profile page being displayed // FIX: This needs to check if user's profile page being displayed
// is the same as the user who is logged in // is the same as the user who is logged in
@ -198,26 +225,25 @@ class user extends Component {
return ( return (
<div> <div>
{/* <Paper className={classes.paper}> */} {/* <Paper className={classes.paper}> */}
<Grid container direction="column">
<Grid item>
<Grid container> <Grid container>
<Grid item sm> <Grid item sm>
{editButtonMarkup} {editButtonMarkup}
</Grid> </Grid>
<Grid item sm> <Grid item sm>
<Grid container direction="column"> {/* <Grid container direction="column"> */}
<Grid item sm> {/* <Grid item sm> */}
{imageMarkup} {imageMarkup}
{profileMarkup} {profileMarkup}
{/* </Grid> */}
{/* <Grid item sm> */}
{/* {postMarkup} */}
{/* </Grid> */}
{/* </Grid> */}
</Grid> </Grid>
<Grid item sm> <Grid item sm>
{postMarkup} <Container className={classes.topicsContainer} maxWidth="xs">
</Grid>
</Grid>
</Grid>
<Grid item sm>
<Container
className={classes.topicsContainer}
maxWidth="xs">
{topicsMarkup} {topicsMarkup}
</Container> </Container>
<TextField <TextField
@ -234,7 +260,17 @@ class user extends Component {
color="primary" color="primary"
// iconStyle={classes.addCircle} // iconStyle={classes.addCircle}
clickable clickable
onClick={this.handleAddCircle} /> onClick={this.handleAddCircle}
/>
</Grid>
</Grid>
</Grid>
<Grid item>
<Grid container>
<Grid item sm />
<Grid item>{postMarkup}</Grid>
<Grid item sm />
</Grid>
</Grid> </Grid>
</Grid> </Grid>
</div> </div>
@ -244,10 +280,10 @@ class user extends Component {
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)(withStyles(styles)(user)); export default connect(mapStateToProps)(withStyles(styles)(user));