Merge branch 'master' into verify-profile

This commit is contained in:
2019-11-01 13:40:30 -04:00
committed by GitHub
11 changed files with 687 additions and 347 deletions

View File

@@ -10,11 +10,11 @@ import jwtDecode from "jwt-decode";
// Redux
import { Provider } from "react-redux";
import store from "./redux/store";
import MuiThemeProvider from '@material-ui/core/styles/MuiThemeProvider';
import createMuiTheme from '@material-ui/core/styles/createMuiTheme';
import themeObject from './util/theme';
import { SET_AUTHENTICATED } from './redux/types';
import { logoutUser, getUserData } from './redux/actions/userActions';
import MuiThemeProvider from "@material-ui/core/styles/MuiThemeProvider";
import createMuiTheme from "@material-ui/core/styles/createMuiTheme";
import themeObject from "./util/theme";
import { SET_AUTHENTICATED } from "./redux/types";
import { logoutUser, getUserData } from "./redux/actions/userActions";
// Components
import AuthRoute from "./util/AuthRoute";
@@ -22,21 +22,21 @@ import AuthRoute from "./util/AuthRoute";
// axios.defaults.baseURL = 'http://localhost:5006/twistter-e4649/us-central1/api';
// Pages
import home from './pages/Home';
import signup from './pages/Signup';
import login from './pages/Login';
import user from './pages/user';
import logout from './pages/Logout';
import Delete from './pages/Delete';
import writeMicroblog from './Writing_Microblogs.js';
import editProfile from './pages/editProfile';
import userLine from './Userline.js';
import home from "./pages/Home";
import signup from "./pages/Signup";
import login from "./pages/Login";
import user from "./pages/user";
import logout from "./pages/Logout";
import Delete from "./pages/Delete";
import writeMicroblog from "./Writing_Microblogs.js";
import editProfile from "./pages/editProfile";
import userLine from "./Userline.js";
import Search from "./pages/Search.js";
const theme = createMuiTheme(themeObject);
const token = localStorage.FBIdToken;
if (token) {
try {
const decodedToken = jwtDecode(token);
if (decodedToken.exp * 1000 < Date.now()) {
@@ -44,7 +44,7 @@ if (token) {
window.location.href = "/login";
} else {
store.dispatch({ type: SET_AUTHENTICATED });
axios.defaults.headers.common['Authorization'] = token;
axios.defaults.headers.common["Authorization"] = token;
store.dispatch(getUserData());
}
} catch (invalidTokenError) {
@@ -53,33 +53,35 @@ if (token) {
}
}
class App extends Component {
render() {
return (
<MuiThemeProvider theme={theme}>
<Provider store={store}>
<Router>
<div className='container' >
<div className="container">
<Navbar />
</div>
<div className="app">
<Switch>
{/* AuthRoute checks if the user is logged in and if they are it redirects them to /home */}
<AuthRoute exact path="/signup" component={signup} />
<AuthRoute exact path="/login" component={login} />
<Route exact path="/logout" component={logout} />
<Route exact path="/delete" component={Delete} />
<Route exact path="/user" component={user} />
<Route exact path="/home" component={writeMicroblog} />
<Route exact path="/edit" component={editProfile} />
{/* AuthRoute checks if the user is logged in and if they are it redirects them to /home */}
<AuthRoute exact path="/signup" component={signup} />
<AuthRoute exact path="/login" component={login} />
<AuthRoute exact path="/" component={home}/>
<Route exact path="/logout" component={logout} />
<Route exact path="/delete" component={Delete} />
<Route exact path="/home" component={home} />
<Route exact path="/user" component={user} />
<Route exact path="/edit" component={editProfile} />
<Route exact path="/search" component={Search} />
<AuthRoute exact path="/" component={home} />
<AuthRoute exact path="/" component={home}/>
</Switch>
</div>
</Router>
</Provider>
</MuiThemeProvider>

View File

@@ -1,107 +1,128 @@
import React, { Component } from "react";
import { BrowserRouter as Router } from 'react-router-dom';
import Route from 'react-router-dom/Route';
import axios from 'axios';
import { BrowserRouter as Router } from "react-router-dom";
import Route from "react-router-dom/Route";
import axios from "axios";
class Writing_Microblogs extends Component {
constructor(props) {
super(props);
this.state = {
value: "",
title: "",
topics: "",
characterCount: 250
};
constructor(props) {
super(props);
this.state = {
value: '',
title: '',
topics: '',
characterCount: 250
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
this.handleChangeforPost = this.handleChangeforPost.bind(this);
this.handleChangeforTopics = this.handleChangeforTopics.bind(this);
}
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
this.handleChangeforPost = this.handleChangeforPost.bind(this);
this.handleChangeforTopics = this.handleChangeforTopics.bind(this);
}
handleChange(event) {
this.setState({ title: event.target.value });
}
handleChange(event) {
this.setState( {title: event.target.value });
}
handleChangeforTopics(event) {
this.setState({ topics: event.target.value });
}
handleChangeforTopics(event) {
this.setState( {topics: event.target.value});
}
handleSubmit(event) {
// alert('A title for the microblog was inputted: ' + this.state.title + '\nA microblog was posted: ' + this.state.value);
const postData = {
body: this.state.value,
userImage: "bing-url",
microBlogTitle: this.state.title,
microBlogTopics: this.state.topics.split(", ")
};
const headers = {
headers: { "Content-Type": "application/json" }
};
handleSubmit(event) {
axios
.post("/putPost", postData, headers)
.then(res => {
alert("Post was shared successfully!");
console.log(res.data);
})
.catch(err => {
alert("An error occured.");
console.error(err);
});
event.preventDefault();
this.setState({ value: "", title: "", characterCount: 250, topics: "" });
}
const postData = {
body: this.state.value,
userImage: "bing-url",
microBlogTitle: this.state.title,
microBlogTopics: this.state.topics.split(', ')
}
const headers = {
headers: { 'Content-Type': 'application/json'}
}
axios
.post("/putPost", postData, headers)
.then((res) =>{
alert('Post was shared successfully!')
console.log(res.data);
})
.catch((err) => {
alert('An error occured.');
console.error(err);
})
event.preventDefault();
this.setState({value: '', title: '',characterCount: 250, topics: ''})
}
handleChangeforPost(event) {
this.setState({ value: event.target.value });
}
handleChangeforPost(event) {
this.setState({value: event.target.value })
}
handleChangeforCharacterCount(event) {
const charCount = event.target.value.length;
const charRemaining = 250 - charCount;
this.setState({ characterCount: charRemaining });
}
handleChangeforCharacterCount(event) {
const charCount = event.target.value.length
const charRemaining = 250 - charCount
this.setState({characterCount: charRemaining })
}
render() {
return (
<div>
<div
style={{
width: "200px",
height: "50px",
marginTop: "180px",
marginLeft: "50px"
}}
>
<form>
<textarea
placeholder="Enter Microblog Title"
value={this.state.title}
required
onChange={this.handleChange}
cols={30}
rows={1}
/>
</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>
render() {
return (
<div>
<div style={{ width: "200px", height: "50px", marginTop: "180px", marginLeft: "50px" }}>
<form>
<textarea placeholder="Enter Microblog Title" value={this.state.title} required onChange={this.handleChange} cols={30} rows={1} />
</form>
<div style={{ width: "200px", marginLeft: "50px" }}>
<form onSubmit={this.handleSubmit}>
<textarea
value={this.state.value}
required
maxLength="250"
placeholder="Write Microblog here..."
onChange={e => {
this.handleChangeforPost(e);
this.handleChangeforCharacterCount(e);
}}
cols={40}
rows={20}
/>
<div style={{ fontSize: "14px", marginRight: "-100px" }}>
<p2>Characters Left: {this.state.characterCount}</p2>
</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"}}>
<form onSubmit={this.handleSubmit}>
<textarea value={this.state.value} required maxLength="250" placeholder= "Write Microblog here..."
onChange = { (e) => { this.handleChangeforPost(e); this.handleChangeforCharacterCount(e) } } cols={40} rows={20} />
<div style={{ fontSize: "14px", marginRight: "-100px"}} >
<p2>Characters Left: {this.state.characterCount}</p2>
</div>
<div style={{ marginRight: "-100px" }}>
<button onClick>Share Post</button>
</div>
</form>
</div>
</div>
);
}
<div style={{ marginRight: "-100px" }}>
<button onClick>Share Post</button>
</div>
</form>
</div>
</div>
);
}
}
export default Writing_Microblogs;
export default Writing_Microblogs;

View File

@@ -10,7 +10,7 @@ import Button from '@material-ui/core/Button';
import withStyles from "@material-ui/core/styles/withStyles";
// Redux stuff
// import { logoutUser } from '../../redux/actions/userActions';
import { logoutUser } from '../../redux/actions/userActions';
import { connect } from 'react-redux';
const styles = {
@@ -41,6 +41,9 @@ export class Navbar extends Component {
<Button component={ Link } to='/'>
Home
</Button>
{authenticated && <Button component={ Link } to='/user'>
Profile
</Button>}
{!authenticated && <Button component={ Link } to='/login'>
Login
</Button>}
@@ -50,9 +53,6 @@ export class Navbar extends Component {
{authenticated && <Button component={ Link } to='/logout'>
Logout
</Button>}
{authenticated && <Button component={ Link } to='/delete'>
Delete Account
</Button>}
</ToolBar>
</AppBar>
)
@@ -63,13 +63,9 @@ const mapStateToProps = (state) => ({
user: state.user
})
// const mapActionsToProps = { logoutUser };
Navbar.propTypes = {
user: PropTypes.object.isRequired,
classes: PropTypes.object.isRequired
}
export default connect(mapStateToProps)(withStyles(styles)(Navbar));
// export default Navbar;

View File

@@ -1,12 +1,74 @@
/* eslint-disable */
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import axios from 'axios';
// Material UI and React Router
import Grid from '@material-ui/core/Grid';
import Card from '@material-ui/core/Card';
import CardContent from '@material-ui/core/CardContent';
import Typography from "@material-ui/core/Typography";
// component
import '../App.css';
import logo from '../images/twistter-logo.png';
import noImage from '../images/no-img.png';
import Writing_Microblogs from '../Writing_Microblogs';
class Home extends Component {
state = {};
componentDidMount() {
axios
.get("/getallPosts")
.then(res => {
console.log(res.data);
this.setState({
posts: res.data
})
})
.catch(err => console.log(err));
}
render() {
let authenticated = this.props.user.authenticated;
let postMarkup = this.state.posts ? (
this.state.posts.map(post =>
<Card>
<CardContent>
<Typography>
{
this.state.imageUrl ? (<img src={this.state.imageUrl} height="250" width="250" />) :
(<img src={noImage} height="50" width="50"/>)
}
</Typography>
<Typography variant="h7"><b>{post.userHandle}</b></Typography>
<Typography variant="body2" color={"textSecondary"}>{post.createdAt}</Typography>
<br />
<Typography variant="body1"><b>{post.microBlogTitle}</b></Typography>
<Typography variant="body2">{post.body}</Typography>
<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 (
authenticated ?
<Grid container spacing={16}>
<Grid item sm={4} xs={8}>
<Writing_Microblogs />
</Grid>
<Grid item sm={4} xs={8}>
{postMarkup}
</Grid>
</Grid>
:
<div>
<div>
<img src={logo} className="app-logo" alt="logo" />
@@ -31,7 +93,15 @@ class Home extends Component {
</div>
</div>
);
}
}
}
export default Home;
const mapStateToProps = (state) => ({
user: state.user
})
Home.propTypes = {
user: PropTypes.object.isRequired
}
export default connect(mapStateToProps)(Home);

View File

@@ -0,0 +1,74 @@
import React, { Component } from "react";
// import props
import { TextField, Paper } from "@material-ui/core";
import Grid from "@material-ui/core/Grid";
import Axios from "axios";
import user from "./user.js";
import {
BrowserRouter as Router,
Switch,
Route,
Link,
useRouteMatch
} from "react-router-dom";
export class Search extends Component {
state = {
searchPhase: null,
searchResult: null
};
handleSearch(event) {
Axios.get("/getUserHandles").then(res => {
this.setState({
searchResult: res.data
});
});
console.log(this.state.searchPhase);
}
handleInput(event) {
this.setState({
searchPhase: event.target.value
});
this.handleSearch();
}
handleRedirect() {
location.reload();
}
render() {
let resultMarkup = this.state.searchResult ? (
this.state.searchResult.map(result => (
<Router>
<div>
<Link to={`/user`}>{result}</Link>
</div>
</Router>
))
) : (
// console.log(this.state.searchResult)
<p> searching... </p>
);
return (
<Grid>
<Grid>
<TextField
id="standard-required"
label="Search"
defaultValue="username"
margin="normal"
value={this.state.searchPhase}
onChange={event => this.handleInput(event)}
/>
</Grid>
<Grid>{resultMarkup}</Grid>
</Grid>
);
}
}
export default Search;

View File

@@ -6,6 +6,7 @@ import PropTypes from "prop-types";
// Material-UI stuff
import Button from "@material-ui/core/Button";
import { Link } from 'react-router-dom';
import CircularProgress from "@material-ui/core/CircularProgress";
import Grid from "@material-ui/core/Grid";
import TextField from "@material-ui/core/TextField";
@@ -220,12 +221,34 @@ export class edit extends Component {
color="primary"
className={classes.button}
disabled={loading}
//component={ Link }
//to='/user'
>
Submit
{loading && (
<CircularProgress size={30} className={classes.progress} />
)}
</Button>
<br />
<Button
//variant="contained"
color="primary"
className={classes.button}
component={ Link }
to='/user'
>
Back to Profile
</Button>
<br />
<Button
variant="contained"
color="secondary"
className={classes.button}
component={ Link }
to='/delete'
>
Delete Account
</Button>
</form>
</Grid>
<Grid item sm />

View File

@@ -1,55 +1,70 @@
/* eslint-disable */
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import axios from 'axios';
//import '../App.css';
import { makeStyles, styled } from '@material-ui/core/styles';
import Grid from '@material-ui/core/Grid';
import Card from '@material-ui/core/Card';
import Chip from '@material-ui/core/Chip';
//import '../App.css';
// Material UI and React Router
import { makeStyles, styled } from "@material-ui/core/styles";
import { Link } from 'react-router-dom';
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 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';
// component
import Userline from '../Userline';
import '../App.css';
import noImage from '../images/no-img.png';
import Writing_Microblogs from '../Writing_Microblogs';
const MyChip = styled(Chip)({
margin: 2,
color: 'primary'
color: "primary"
});
class user extends Component {
class user extends Component {
state = {
profile: null,
imageUrl: null,
topics: null,
newTopic: null
};
handleDelete = (topic) => {
alert(`Delete topic: ${topic}!`);
}
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);
});
}
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
})
});
}
componentDidMount() {
@@ -63,44 +78,79 @@ class user extends Component {
});
})
.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));
}
render() {
const classes = this.props;
let authenticated = this.props.user.authenticated;
let classes = this.props;
let profileMarkup = this.state.profile ? (
<div>
<Typography variant='h5'>@{this.state.profile} {this.state.verified ? (<VerifiedIcon style={{fill: "#1397D5"}}/>): (null)}</Typography>
</div>) : (<p>loading username...</p>);
let topicsMarkup = this.state.topics ? (
this.state.topics.map(topic => <MyChip
label={{topic}.topic.topic}
key={{topic}.topic.topicId}
onDelete={ (topic) => this.handleDelete(topic)}/>)
) : (<p> loading topics...</p>);
this.state.topics.map(
topic => (
<MyChip
label={{ topic }.topic.topic}
key={{ topic }.topic.id}
onDelete={key => this.handleDelete(topic)}
/>
) // console.log({ topic }.topic.id)
)
) : (
<p> loading topics...</p>
);
let imageMarkup = this.state.imageUrl ? (
<img
src={this.state.imageUrl}
height="250"
width="250"
/>
) : (<img src={noImage}/>);
let imageMarkup = this.state.imageUrl ? (<img src={this.state.imageUrl} height="150" width="150" />) :
(<img src={noImage} height="150" width="150"/>);
let postMarkup = this.state.posts ? (
this.state.posts.map(post =>
<Card>
<CardContent>
<Typography>
{
this.state.imageUrl ? (<img src={this.state.imageUrl} height="250" width="250" />) :
(<img src={noImage} height="50" width="50"/>)
}
</Typography>
<Typography variant="h7"><b>{post.userHandle}</b></Typography>
<Typography variant="body2" color={"textSecondary"}>{post.createdAt}</Typography>
<br />
<Typography variant="body1"><b>{post.microBlogTitle}</b></Typography>
<Typography variant="body2">{post.body}</Typography>
<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 (
<Grid container spacing={16}>
<Grid item sm={8} xs={12}>
<p>Post</p>
</Grid>
<Grid item sm={4} xs={12}>
<Grid container spacing={24}>
<Grid item sm={4} xs={8}>
{imageMarkup}
{profileMarkup}
{topicsMarkup}
@@ -111,17 +161,34 @@ class user extends Component {
margin="normal"
variant="outlined"
value={this.state.newTopic}
onChange={ (event) => this.handleChange(event)}
onChange={(event) => this.handleChange(event)}
/>
<AddCircle
color="primary"
clickable
onClick={this.handleAddCircle}
/>
<br />
{authenticated && <Button component={ Link } to='/edit'>Edit Profile Info</Button>}
</Grid>
<Grid item sm={4} xs={8}>
{postMarkup}
</Grid>
<Grid item sm={4} xs={8}>
<Writing_Microblogs />
</Grid>
      
</Grid>
);
}
}
export default user;
const mapStateToProps = (state) => ({
user: state.user
})
user.propTypes = {
user: PropTypes.object.isRequired
}
export default connect(mapStateToProps)(user);