mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 02:08:47 +00:00
Merge branch 'master' into search_page
This commit is contained in:
commit
f60c045483
@ -23,23 +23,46 @@ exports.putPost = (req, res) => {
|
|||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return res.status(500).json({ error: 'something is wrong'});
|
return res.status(500).json({ error: 'something went wrong'});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getallPostsforUser = (req, res) => {
|
exports.getallPostsforUser = (req, res) => {
|
||||||
admin.firestore().collection('posts').where('userHandle', '==', req.userData.handle ).get()
|
var post_query = admin.firestore().collection("posts").where("userHandle", "==", req.user.handle);
|
||||||
.then((data) => {
|
post_query.get()
|
||||||
|
.then(function(myPosts) {
|
||||||
let posts = [];
|
let posts = [];
|
||||||
data.forEach(function(doc) {
|
myPosts.forEach(function(doc) {
|
||||||
posts.push(doc.data());
|
posts.push(doc.data());
|
||||||
});
|
});
|
||||||
return res.status(200).json(posts);
|
return res.status(200).json(posts);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.then(function() {
|
||||||
console.error(err);
|
res.status(200).send("Successfully retrieved all user's posts from database.");
|
||||||
return res.status(500).json({error: 'Failed to fetch all posts written by specific user.'})
|
return;
|
||||||
})
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
res.status(500).send("Failed to retrieve user's posts from database.", err);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.getallPosts = (req, res) => {
|
||||||
|
var post_query = admin.firestore().collection("posts");
|
||||||
|
post_query.get()
|
||||||
|
.then(function(allPosts) {
|
||||||
|
let posts = [];
|
||||||
|
allPosts.forEach(function(doc) {
|
||||||
|
posts.push(doc.data());
|
||||||
|
});
|
||||||
|
return res.status(200).json(posts);
|
||||||
|
})
|
||||||
|
.then(function() {
|
||||||
|
res.status(200).send("Successfully retrieved every post from database.");
|
||||||
|
return;
|
||||||
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
res.status(500).send("Failed to retrieve posts from database.", err);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getFilteredPosts = (req, res) => {
|
exports.getFilteredPosts = (req, res) => {
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
/* eslint-disable promise/catch-or-return */
|
/* eslint-disable promise/catch-or-return */
|
||||||
|
|
||||||
const { admin, db } = require("../util/admin");
|
const { admin, db } = require("../util/admin");
|
||||||
const config = require("../util/config");
|
const config = require("../util/config");
|
||||||
const { validateUpdateProfileInfo } = require("../util/validator");
|
const { validateUpdateProfileInfo } = require("../util/validator");
|
||||||
|
|||||||
@ -48,9 +48,11 @@ app.get("/getUserHandles", fbAuth, getUserHandles);
|
|||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
* handlers/post.js *
|
* handlers/post.js *
|
||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
const { getallPostsforUser, putPost } = require("./handlers/post");
|
const { getallPostsforUser, getallPosts, putPost } = require("./handlers/post");
|
||||||
|
|
||||||
app.get("/getallPostsforUser", getallPostsforUser);
|
app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
|
||||||
|
|
||||||
|
app.get("/getallPosts", getallPosts);
|
||||||
|
|
||||||
// Adds one post to the database
|
// Adds one post to the database
|
||||||
app.post("/putPost", fbAuth, putPost);
|
app.post("/putPost", fbAuth, putPost);
|
||||||
|
|||||||
@ -62,20 +62,24 @@ class App extends Component {
|
|||||||
<div className="container">
|
<div className="container">
|
||||||
<Navbar />
|
<Navbar />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="app">
|
<div className="app">
|
||||||
<Switch>
|
<Switch>
|
||||||
|
|
||||||
{/* AuthRoute checks if the user is logged in and if they are it redirects them to /home */}
|
{/* 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="/signup" component={signup} />
|
||||||
<AuthRoute exact path="/login" component={login} />
|
<AuthRoute exact path="/login" component={login} />
|
||||||
|
<AuthRoute exact path="/" component={home}/>
|
||||||
|
|
||||||
<Route exact path="/logout" component={logout} />
|
<Route exact path="/logout" component={logout} />
|
||||||
<Route exact path="/delete" component={Delete} />
|
<Route exact path="/delete" component={Delete} />
|
||||||
|
|
||||||
|
<Route exact path="/home" component={home} />
|
||||||
<Route exact path="/user" component={user} />
|
<Route exact path="/user" component={user} />
|
||||||
<Route exact path="/home" component={writeMicroblog} />
|
|
||||||
<Route exact path="/edit" component={editProfile} />
|
<Route exact path="/edit" component={editProfile} />
|
||||||
<Route exact path="/search" component={Search} />
|
<Route exact path="/search" component={Search} />
|
||||||
|
|
||||||
<AuthRoute exact path="/" component={home} />
|
<AuthRoute exact path="/" component={home} />
|
||||||
|
|
||||||
</Switch>
|
</Switch>
|
||||||
</div>
|
</div>
|
||||||
</Router>
|
</Router>
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import Button from '@material-ui/core/Button';
|
|||||||
import withStyles from "@material-ui/core/styles/withStyles";
|
import withStyles from "@material-ui/core/styles/withStyles";
|
||||||
|
|
||||||
// Redux stuff
|
// Redux stuff
|
||||||
// import { logoutUser } from '../../redux/actions/userActions';
|
import { logoutUser } from '../../redux/actions/userActions';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
@ -41,6 +41,9 @@ export class Navbar extends Component {
|
|||||||
<Button component={ Link } to='/'>
|
<Button component={ Link } to='/'>
|
||||||
Home
|
Home
|
||||||
</Button>
|
</Button>
|
||||||
|
{authenticated && <Button component={ Link } to='/user'>
|
||||||
|
Profile
|
||||||
|
</Button>}
|
||||||
{!authenticated && <Button component={ Link } to='/login'>
|
{!authenticated && <Button component={ Link } to='/login'>
|
||||||
Login
|
Login
|
||||||
</Button>}
|
</Button>}
|
||||||
@ -50,9 +53,6 @@ export class Navbar extends Component {
|
|||||||
{authenticated && <Button component={ Link } to='/logout'>
|
{authenticated && <Button component={ Link } to='/logout'>
|
||||||
Logout
|
Logout
|
||||||
</Button>}
|
</Button>}
|
||||||
{authenticated && <Button component={ Link } to='/delete'>
|
|
||||||
Delete Account
|
|
||||||
</Button>}
|
|
||||||
</ToolBar>
|
</ToolBar>
|
||||||
</AppBar>
|
</AppBar>
|
||||||
)
|
)
|
||||||
@ -63,13 +63,9 @@ const mapStateToProps = (state) => ({
|
|||||||
user: state.user
|
user: state.user
|
||||||
})
|
})
|
||||||
|
|
||||||
// const mapActionsToProps = { logoutUser };
|
|
||||||
|
|
||||||
Navbar.propTypes = {
|
Navbar.propTypes = {
|
||||||
user: PropTypes.object.isRequired,
|
user: PropTypes.object.isRequired,
|
||||||
classes: PropTypes.object.isRequired
|
classes: PropTypes.object.isRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connect(mapStateToProps)(withStyles(styles)(Navbar));
|
export default connect(mapStateToProps)(withStyles(styles)(Navbar));
|
||||||
|
|
||||||
// export default Navbar;
|
|
||||||
|
|||||||
@ -1,12 +1,74 @@
|
|||||||
|
/* eslint-disable */
|
||||||
import React, { Component } from 'react';
|
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 '../App.css';
|
||||||
|
|
||||||
import logo from '../images/twistter-logo.png';
|
import logo from '../images/twistter-logo.png';
|
||||||
|
import noImage from '../images/no-img.png';
|
||||||
|
import Writing_Microblogs from '../Writing_Microblogs';
|
||||||
|
|
||||||
class Home extends Component {
|
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() {
|
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 (
|
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>
|
||||||
<div>
|
<div>
|
||||||
<img src={logo} className="app-logo" alt="logo" />
|
<img src={logo} className="app-logo" alt="logo" />
|
||||||
@ -31,7 +93,15 @@ class Home extends Component {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default Home;
|
const mapStateToProps = (state) => ({
|
||||||
|
user: state.user
|
||||||
|
})
|
||||||
|
|
||||||
|
Home.propTypes = {
|
||||||
|
user: PropTypes.object.isRequired
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(mapStateToProps)(Home);
|
||||||
@ -6,6 +6,7 @@ import PropTypes from "prop-types";
|
|||||||
|
|
||||||
// Material-UI stuff
|
// Material-UI stuff
|
||||||
import Button from "@material-ui/core/Button";
|
import Button from "@material-ui/core/Button";
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
import CircularProgress from "@material-ui/core/CircularProgress";
|
import CircularProgress from "@material-ui/core/CircularProgress";
|
||||||
import Grid from "@material-ui/core/Grid";
|
import Grid from "@material-ui/core/Grid";
|
||||||
import TextField from "@material-ui/core/TextField";
|
import TextField from "@material-ui/core/TextField";
|
||||||
@ -220,12 +221,34 @@ export class edit extends Component {
|
|||||||
color="primary"
|
color="primary"
|
||||||
className={classes.button}
|
className={classes.button}
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
|
//component={ Link }
|
||||||
|
//to='/user'
|
||||||
>
|
>
|
||||||
Submit
|
Submit
|
||||||
{loading && (
|
{loading && (
|
||||||
<CircularProgress size={30} className={classes.progress} />
|
<CircularProgress size={30} className={classes.progress} />
|
||||||
)}
|
)}
|
||||||
</Button>
|
</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>
|
</form>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item sm />
|
<Grid item sm />
|
||||||
|
|||||||
@ -1,19 +1,28 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
import React, { Component } from "react";
|
import React, { Component } from 'react';
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from 'prop-types';
|
||||||
import axios from "axios";
|
import { connect } from 'react-redux';
|
||||||
|
import axios from 'axios';
|
||||||
//import '../App.css';
|
//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 Grid from "@material-ui/core/Grid";
|
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 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";
|
||||||
|
|
||||||
// component
|
// component
|
||||||
import noImage from "../images/no-img.png";
|
import '../App.css';
|
||||||
|
import noImage from '../images/no-img.png';
|
||||||
|
import Writing_Microblogs from '../Writing_Microblogs';
|
||||||
const MyChip = styled(Chip)({
|
const MyChip = styled(Chip)({
|
||||||
margin: 2,
|
margin: 2,
|
||||||
color: "primary"
|
color: "primary"
|
||||||
@ -67,6 +76,7 @@ class user extends Component {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.get("/getAllTopics")
|
.get("/getAllTopics")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
@ -75,17 +85,25 @@ class user extends Component {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.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() {
|
render() {
|
||||||
|
let authenticated = this.props.user.authenticated;
|
||||||
|
let classes = this.props;
|
||||||
let profileMarkup = this.state.profile ? (
|
let profileMarkup = this.state.profile ? (
|
||||||
<p>
|
<p>
|
||||||
<Typography variant="h5">{this.state.profile}</Typography>
|
<Typography variant='h5'>{this.state.profile}</Typography>
|
||||||
|
</p>) : (<p>loading username...</p>);
|
||||||
</p>
|
|
||||||
) : (
|
|
||||||
<p>loading username...</p>
|
|
||||||
);
|
|
||||||
|
|
||||||
let topicsMarkup = this.state.topics ? (
|
let topicsMarkup = this.state.topics ? (
|
||||||
this.state.topics.map(
|
this.state.topics.map(
|
||||||
topic => (
|
topic => (
|
||||||
@ -100,37 +118,61 @@ class user extends Component {
|
|||||||
<p> loading topics...</p>
|
<p> loading topics...</p>
|
||||||
);
|
);
|
||||||
|
|
||||||
let imageMarkup = this.state.imageUrl ? (
|
let imageMarkup = this.state.imageUrl ? (<img src={this.state.imageUrl} height="150" width="150" />) :
|
||||||
<img src={this.state.imageUrl} height="250" width="250" />
|
(<img src={noImage} height="150" width="150"/>);
|
||||||
) : (
|
|
||||||
<img src={noImage} />
|
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 (
|
return (
|
||||||
<Grid container spacing={16}>
|
<Grid container spacing={24}>
|
||||||
|
<Grid item sm={4} xs={8}>
|
||||||
<Grid item sm={8} xs={12}>
|
{imageMarkup}
|
||||||
<p>Post</p>
|
{profileMarkup}
|
||||||
|
{topicsMarkup}
|
||||||
</Grid>
|
|
||||||
|
|
||||||
<Grid item sm={4} xs={12}>
|
|
||||||
{imageMarkup}
|
|
||||||
{profileMarkup}
|
|
||||||
{topicsMarkup}
|
|
||||||
|
|
||||||
<TextField
|
<TextField
|
||||||
id="newTopic"
|
id="newTopic"
|
||||||
label="new topic"
|
label="new topic"
|
||||||
defaultValue=""
|
defaultValue=""
|
||||||
margin="normal"
|
margin="normal"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
value={this.state.newTopic}
|
value={this.state.newTopic}
|
||||||
onChange={event => this.handleChange(event)}
|
onChange={(event) => this.handleChange(event)}
|
||||||
/>
|
/>
|
||||||
|
<AddCircle
|
||||||
<AddCircle color="primary" clickable onClick={this.handleAddCircle} />
|
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>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
@ -138,4 +180,12 @@ class user extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default user;
|
const mapStateToProps = (state) => ({
|
||||||
|
user: state.user
|
||||||
|
})
|
||||||
|
|
||||||
|
user.propTypes = {
|
||||||
|
user: PropTypes.object.isRequired
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(mapStateToProps)(user);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user