Merge pull request #85 from ClaytonWWilson/microblogs-material-ui

Changing Writing_Microblogs to Material-UI and other UI tweaks
This commit is contained in:
Clayton Wilson 2019-12-03 13:35:27 -05:00 committed by GitHub
commit 3092fabfd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 162 additions and 101 deletions

View File

@ -3,6 +3,27 @@ import { BrowserRouter as Router } from "react-router-dom";
import Route from "react-router-dom/Route"; import Route from "react-router-dom/Route";
import axios from "axios"; import axios from "axios";
// Material-UI
import TextField from '@material-ui/core/TextField';
import Typography from '@material-ui/core/Typography';
import Button from '@material-ui/core/Button';
import withStyles from "@material-ui/styles/withStyles";
const styles = {
container: {
position: "fixed"
},
form: {
width: "300px",
height: "50px",
marginTop: "180px",
marginLeft: "50px"
},
textField: {
marginBottom: 15
}
}
class Writing_Microblogs extends Component { class Writing_Microblogs extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
@ -27,7 +48,7 @@ class Writing_Microblogs extends Component {
this.setState({ topics: event.target.value }); this.setState({ topics: event.target.value });
} }
handleSubmit(event) { handleSubmit = (event) => {
// alert('A title for the microblog was inputted: ' + this.state.title + '\nA microblog was posted: ' + this.state.value); // alert('A title for the microblog was inputted: ' + this.state.title + '\nA microblog was posted: ' + this.state.value);
const postData = { const postData = {
body: this.state.value, body: this.state.value,
@ -67,6 +88,7 @@ class Writing_Microblogs extends Component {
} }
handleChangeforPost(event) { handleChangeforPost(event) {
this.setState({ value: event.target.value }); this.setState({ value: event.target.value });
} }
@ -77,65 +99,68 @@ class Writing_Microblogs extends Component {
} }
render() { render() {
const { classes } = this.props;
return ( return (
<div> <div className={classes.container}>
<div <form noValidate className={classes.form}>
style={{ <TextField
width: "200px", id="title"
height: "50px", name="title"
marginTop: "180px", label="Title"
marginLeft: "50px" className={classes.textField}
}}
>
<form>
<textarea
placeholder="Enter Microblog Title"
value={this.state.title} value={this.state.title}
required variant="outlined"
onChange={this.handleChange} onChange={this.handleChange}
cols={30} fullWidth
rows={1} autoComplete='off'
/> />
</form>
</div>
<div style={{ width: "200px", height: "50px", marginLeft: "50px" }}>
<form>
<textarea
placeholder="Enter topics seperated by a comma"
value={this.state.topics}
required
onChange={this.handleChangeforTopics}
cols={40}
rows={1}
/>
</form>
</div>
<div style={{ width: "200px", marginLeft: "50px" }}> <TextField
<form onSubmit={this.handleSubmit}> id="topics"
<textarea name="topics"
label="Topics"
className={classes.textField}
value={this.state.topics}
variant="outlined"
onChange={this.handleChangeforTopics}
color="primary"
fullWidth
autoComplete='off'
/>
<TextField
id="content"
name="content"
label="Content"
color="primary"
className={classes.textField}
value={this.state.value} value={this.state.value}
required helperText={`${this.state.characterCount} characters left`}
maxLength="250" multiline
placeholder="Write Microblog here..." rows="9"
onChange={e => { variant="outlined"
inputProps={{
maxLength: 250
}}
onChange={(e) => {
this.handleChangeforPost(e); this.handleChangeforPost(e);
this.handleChangeforCharacterCount(e); this.handleChangeforCharacterCount(e);
}} }}
cols={40} fullWidth
rows={20} autoComplete='off'
/> />
<div style={{ fontSize: "14px", marginRight: "-100px" }}> <Button
<p2>Characters Left: {this.state.characterCount}</p2> onClick={this.handleSubmit}
</div> // disabled={loading}
<div style={{ marginRight: "-100px" }}> variant="outlined"
<button onClick>Share Post</button> color="primary"
</div> >
Share Post
</Button>
</form> </form>
</div> </div>
</div>
); );
} }
} }
export default Writing_Microblogs; export default withStyles(styles)(Writing_Microblogs);

View File

@ -9,6 +9,7 @@ import Grid from "@material-ui/core/Grid";
import Card from "@material-ui/core/Card"; import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent"; import CardContent from "@material-ui/core/CardContent";
import Typography from "@material-ui/core/Typography"; import Typography from "@material-ui/core/Typography";
import withStyles from '@material-ui/styles/withStyles';
// component // component
import '../App.css'; import '../App.css';
@ -18,6 +19,12 @@ import Writing_Microblogs from '../Writing_Microblogs';
import ReactModal from 'react-modal'; import ReactModal from 'react-modal';
const styles = {
card: {
marginBottom: 5
}
}
class Home extends Component { class Home extends Component {
state = { state = {
@ -36,27 +43,28 @@ class Home extends Component {
.catch(err => console.log(err)); .catch(err => console.log(err));
} }
formatDate(dateString) {
let newDate = new Date(Date.parse(dateString));
return newDate.toDateString();
}
render() { render() {
let authenticated = this.props.user.authenticated; let authenticated = this.props.user.authenticated;
let {classes} = this.props;
let username = this.props.user.credentials.handle; let username = this.props.user.credentials.handle;
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 ? ( {
<img src={this.state.imageUrl} height="250" width="250" /> this.state.imageUrl ? (<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="h5"><b>{post.userHandle}</b></Typography>
<Typography variant="body2" color={"textSecondary"}>{this.formatDate(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.quoteBody}</Typography> <Typography variant="body2">{post.quoteBody}</Typography>
@ -70,7 +78,7 @@ class Home extends Component {
<Quote microblog = {post.postId}></Quote> <Quote microblog = {post.postId}></Quote>
</CardContent> </CardContent>
</Card> </Card>
)) )
) : ( ) : (
<p>Loading post...</p> <p>Loading post...</p>
); );
@ -333,8 +341,9 @@ const mapStateToProps = (state) => ({
}); });
Home.propTypes = { Home.propTypes = {
user: PropTypes.object.isRequired user: PropTypes.object.isRequired,
}; clases: PropTypes.object.isRequired
}
Like.propTypes = { Like.propTypes = {
user: PropTypes.object.isRequired user: PropTypes.object.isRequired
@ -344,4 +353,4 @@ Quote.propTypes = {
user: PropTypes.object.isRequired user: PropTypes.object.isRequired
} }
export default connect(mapStateToProps)(Home, Like, Quote); export default connect(mapStateToProps)(withStyles(styles)(Home, Like, Quote));

View File

@ -119,7 +119,7 @@ export class Login extends Component {
<TextField <TextField
id="email" id="email"
name="email" name="email"
label="Email*" label="Email or Username*"
className={classes.textField} className={classes.textField}
value={this.state.email} value={this.state.email}
helperText={errors.email} helperText={errors.email}
@ -127,6 +127,7 @@ export class Login extends Component {
variant="outlined" variant="outlined"
onChange={this.handleChange} onChange={this.handleChange}
fullWidth fullWidth
autoComplete='off'
/> />
<TextField <TextField
id="password" id="password"
@ -140,6 +141,7 @@ export class Login extends Component {
variant="outlined" variant="outlined"
onChange={this.handleChange} onChange={this.handleChange}
fullWidth fullWidth
autoComplete='off'
/> />
<Button <Button
type="submit" type="submit"

View File

@ -122,6 +122,7 @@ export class Signup extends Component {
variant="outlined" variant="outlined"
onChange={this.handleChange} onChange={this.handleChange}
fullWidth fullWidth
autoComplete='off'
/> />
<TextField <TextField
id="email" id="email"
@ -134,6 +135,7 @@ export class Signup extends Component {
variant="outlined" variant="outlined"
onChange={this.handleChange} onChange={this.handleChange}
fullWidth fullWidth
autoComplete='off'
/> />
<TextField <TextField
id="password" id="password"
@ -147,6 +149,7 @@ export class Signup extends Component {
variant="outlined" variant="outlined"
onChange={this.handleChange} onChange={this.handleChange}
fullWidth fullWidth
autoComplete='off'
/> />
<TextField <TextField
id="confirmPassword" id="confirmPassword"
@ -160,6 +163,7 @@ export class Signup extends Component {
variant="outlined" variant="outlined"
onChange={this.handleChange} onChange={this.handleChange}
fullWidth fullWidth
autoComplete='off'
/> />
<br></br> <br></br>
<br></br> <br></br>

View File

@ -28,6 +28,14 @@ const styles = {
positon: "relative", positon: "relative",
marginBottom: 30 marginBottom: 30
}, },
back: {
float: "left",
marginLeft: 15
},
delete: {
float: "right",
marginRight: 15
},
progress: { progress: {
position: "absolute" position: "absolute"
} }
@ -135,7 +143,17 @@ export class edit extends Component {
return ( return (
<Grid container className={classes.form}> <Grid container className={classes.form}>
<Grid item sm /> <Grid item sm >
<Button
variant="outlined"
color="primary"
className={classes.back}
component={ Link }
to='/user'
>
Back to Profile
</Button>
</Grid>
<Grid item sm> <Grid item sm>
<Typography variant="h2" className={classes.pageTitle}> <Typography variant="h2" className={classes.pageTitle}>
Edit Profile Edit Profile
@ -154,6 +172,7 @@ export class edit extends Component {
variant="outlined" variant="outlined"
onChange={this.handleChange} onChange={this.handleChange}
fullWidth fullWidth
autoComplete='off'
/> />
</Grid> </Grid>
<Grid item sm> <Grid item sm>
@ -168,6 +187,7 @@ export class edit extends Component {
variant="outlined" variant="outlined"
onChange={this.handleChange} onChange={this.handleChange}
fullWidth fullWidth
autoComplete='off'
/> />
</Grid> </Grid>
</Grid> </Grid>
@ -185,6 +205,7 @@ export class edit extends Component {
variant="outlined" variant="outlined"
onChange={this.handleChange} onChange={this.handleChange}
fullWidth fullWidth
autoComplete='off'
/> />
<TextField <TextField
id="handle" id="handle"
@ -200,6 +221,7 @@ export class edit extends Component {
variant="outlined" variant="outlined"
onChange={this.handleChange} onChange={this.handleChange}
fullWidth fullWidth
autoComplete='off'
/> />
<TextField <TextField
id="bio" id="bio"
@ -214,6 +236,7 @@ export class edit extends Component {
variant="outlined" variant="outlined"
onChange={this.handleChange} onChange={this.handleChange}
fullWidth fullWidth
autoComplete='off'
/> />
<Button <Button
type="submit" type="submit"
@ -229,29 +252,20 @@ export class edit extends Component {
<CircularProgress size={30} className={classes.progress} /> <CircularProgress size={30} className={classes.progress} />
)} )}
</Button> </Button>
<br />
</form>
</Grid>
<Grid item sm>
<Button <Button
//variant="contained" variant="outlined"
color="primary"
className={classes.button}
component={ Link }
to='/user'
>
Back to Profile
</Button>
<br />
<Button
variant="contained"
color="secondary" color="secondary"
className={classes.button} className={classes.delete}
component={ Link } component={ Link }
to='/delete' to='/delete'
> >
Delete Account Delete Account
</Button> </Button>
</form>
</Grid> </Grid>
<Grid item sm />
</Grid> </Grid>
); );
} }

View File

@ -47,7 +47,7 @@ const styles = {
// marginRight: "10%" // marginRight: "10%"
}, },
card: { card: {
marginBottom: 10 marginBottom: 5
}, },
profileImage: { profileImage: {
marginTop: 20 marginTop: 20
@ -152,6 +152,11 @@ class user extends Component {
.catch(err => console.log(err)); .catch(err => console.log(err));
} }
formatDate(dateString) {
let newDate = new Date(Date.parse(dateString));
return newDate.toDateString();
}
render() { render() {
const { classes } = this.props; const { classes } = this.props;
let authenticated = this.props.user.authenticated; let authenticated = this.props.user.authenticated;
@ -223,6 +228,7 @@ class user extends Component {
<b>{post.microBlogTitle}</b> <b>{post.microBlogTitle}</b>
</Typography> </Typography>
<Typography variant="body2">{post.quoteBody}</Typography> <Typography variant="body2">{post.quoteBody}</Typography>
<br /> <br />
<Typography variant="body2">{post.body}</Typography> <Typography variant="body2">{post.body}</Typography>
<br /> <br />
@ -311,7 +317,8 @@ const mapStateToProps = state => ({
}); });
user.propTypes = { user.propTypes = {
user: PropTypes.object.isRequired user: PropTypes.object.isRequired,
clases: PropTypes.object.isRequired
}; };
export default connect(mapStateToProps)(withStyles(styles)(user)); export default connect(mapStateToProps)(withStyles(styles)(user));