mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-15 18:08:46 +00:00
Merge branch 'master' of https://github.com/ClaytonWWilson/CS307-Team24
This commit is contained in:
commit
9449d3544b
@ -1,7 +1,7 @@
|
||||
/* eslint-disable prefer-arrow-callback */
|
||||
/* eslint-disable promise/always-return */
|
||||
const admin = require("firebase-admin");
|
||||
const { db } = require("../util/admin");
|
||||
const { admin, db } = require("../util/admin");
|
||||
|
||||
|
||||
exports.putPost = (req, res) => {
|
||||
const newPost = {
|
||||
@ -33,6 +33,18 @@ exports.putPost = (req, res) => {
|
||||
});
|
||||
};
|
||||
|
||||
exports.deletePost = (req, res) => {
|
||||
let posts = db.collection("posts")
|
||||
.where("userHandle", "==", req.user.handle)
|
||||
.get()
|
||||
.then((query) => {
|
||||
query.forEach((snap) => {
|
||||
snap.ref.delete();
|
||||
});
|
||||
return;
|
||||
})
|
||||
};
|
||||
|
||||
exports.getallPostsforUser = (req, res) => {
|
||||
var post_query = admin
|
||||
.firestore()
|
||||
@ -62,6 +74,23 @@ exports.getallPostsforUser = (req, res) => {
|
||||
});
|
||||
};
|
||||
|
||||
exports.hidePost = (req, res) => {
|
||||
/* db
|
||||
.collection("posts")
|
||||
.doc(${req.params.postId}) */
|
||||
const postId = req.body.postId;
|
||||
db.doc(`/posts/${postId}`)
|
||||
.update({
|
||||
hidden: true
|
||||
})
|
||||
.then(() => {
|
||||
return res.status(200).json({message: "ok"});
|
||||
})
|
||||
.catch((error) => {
|
||||
return res.status(500).json(error);
|
||||
})
|
||||
};
|
||||
|
||||
exports.getallPosts = (req, res) => {
|
||||
let posts = [];
|
||||
let users = {};
|
||||
@ -148,6 +177,11 @@ exports.getOtherUsersPosts = (req, res) => {
|
||||
.firestore()
|
||||
.collection("posts")
|
||||
.where("userHandle", "==", req.body.handle);
|
||||
|
||||
post_query += admin
|
||||
.firestore()
|
||||
.collection("posts")
|
||||
.where("microBlogTitle", "==", "Alert").where("userHandle", "==", "Admin");
|
||||
|
||||
post_query
|
||||
.get()
|
||||
|
||||
@ -104,10 +104,12 @@ app.post("/removeSub", fbAuth, removeSub);
|
||||
* handlers/post.js *
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
|
||||
const {
|
||||
getallPostsforUser,
|
||||
getallPosts,
|
||||
putPost,
|
||||
hidePost,
|
||||
likePost,
|
||||
unlikePost,
|
||||
getLikes,
|
||||
@ -122,6 +124,9 @@ app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
|
||||
|
||||
app.get("/getallPosts", getallPosts);
|
||||
|
||||
//Hides Post
|
||||
app.post("/hidePost", fbAuth, hidePost);
|
||||
|
||||
// Adds one post to the database
|
||||
app.post("/putPost", fbAuth, putPost);
|
||||
|
||||
|
||||
1177
twistter-frontend/package-lock.json
generated
1177
twistter-frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -86,8 +86,22 @@ class Home extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
handleClickLikeButton = event => {
|
||||
// Need the ternary if statement because the user can click on the text or body of the
|
||||
flagPost = (event) => {
|
||||
// Flags a post
|
||||
let postId = event.target.dataset.key ? event.target.dataset.key : event.target.parentNode.dataset.key;
|
||||
console.log(postId);
|
||||
axios.post(`/hidePost`, {postId})
|
||||
.then((res) => {
|
||||
console.log(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
// event.preventDefault();
|
||||
}
|
||||
|
||||
handleClickLikeButton = (event) => {
|
||||
// Need the ternary if statement because the user can click on the text or body of the
|
||||
// Button and they are two different html elements
|
||||
let postId = event.target.dataset.key
|
||||
? event.target.dataset.key
|
||||
@ -119,51 +133,49 @@ class Home extends Component {
|
||||
let authenticated = this.props.user.authenticated;
|
||||
let { classes } = this.props;
|
||||
let username = this.props.user.credentials.handle;
|
||||
console.log(this.state.following);
|
||||
console.log(username);
|
||||
var hiddenBool = true;
|
||||
if (username === "Admin") {
|
||||
hiddenBool = false;
|
||||
}
|
||||
|
||||
let postMarkup = this.state.posts ? (
|
||||
this.state.posts.map(post =>
|
||||
this.state.following ? (
|
||||
this.state.following.includes(post.userHandle) ? (
|
||||
console.log(hiddenBool);
|
||||
let postMarkup = this.state.posts ? ( this.state.following === undefined || this.state.following === null ? <Typography>You aren't following anybody right now</Typography> :
|
||||
this.state.posts.map(post => !post.hidden && this.state.following && this.state.following.includes(post.userHandle) ? (
|
||||
<Card className={classes.card} key={post.postId}>
|
||||
<CardContent>
|
||||
<Typography>
|
||||
{/* {
|
||||
this.state.imageUrl ? (<img src={this.state.imageUrl} height="50" width="50" />) :
|
||||
(<img src={noImage} height="50" width="50"/>)
|
||||
} */}
|
||||
{post.profileImage ? (
|
||||
<img src={post.profileImage} height="50" width="50" />
|
||||
) : (
|
||||
<img src={noImage} height="50" width="50" />
|
||||
)}
|
||||
</Typography>
|
||||
<Typography variant="h5">
|
||||
<b>{post.userHandle}</b>
|
||||
</Typography>
|
||||
<Typography variant="body2" color={"textSecondary"}>
|
||||
{this.formatDate(post.createdAt)}
|
||||
this.state.imageUrl ? (<img src={this.state.imageUrl} height="50" width="50" />) :
|
||||
(<img src={noImage} height="50" width="50"/>)
|
||||
} */}
|
||||
{
|
||||
post.profileImage ? (<img src={post.profileImage} height="50" width="50" />) :
|
||||
(<img src={noImage} height="50" width="50"/>)
|
||||
}
|
||||
</Typography>
|
||||
<Typography variant="h5"><b>{post.userHandle}</b></Typography>
|
||||
<Typography variant="body2" color={"textSecondary"}>{this.formatDate(post.createdAt)}</Typography>
|
||||
<br />
|
||||
<Typography variant="body1">
|
||||
<b>{post.microBlogTitle}</b>
|
||||
</Typography>
|
||||
<Typography variant="body1"><b>{post.microBlogTitle}</b></Typography>
|
||||
<Typography variant="body2">{post.quoteBody}</Typography>
|
||||
<br />
|
||||
<Typography variant="body2">{post.body}</Typography>
|
||||
<br />
|
||||
<Typography variant="body2">
|
||||
<b>Topics:</b> {post.microBlogTopics.join(", ")}
|
||||
</Typography>
|
||||
<Typography variant="body2"><b>Topics:</b> {post.microBlogTopics.join(", ")}</Typography>
|
||||
<br />
|
||||
<Typography
|
||||
id={post.postId}
|
||||
data-likes={post.likeCount}
|
||||
variant="body2"
|
||||
color={"textSecondary"}
|
||||
{!hiddenBool &&
|
||||
<Button
|
||||
onClick={this.flagPost}
|
||||
data-key={post.postId}
|
||||
variant = "contained"
|
||||
color = "primary"
|
||||
>
|
||||
Likes {post.likeCount}
|
||||
</Typography>
|
||||
Hide Post
|
||||
</Button>
|
||||
}
|
||||
|
||||
<Typography id={post.postId} data-likes={post.likeCount} variant="body2" color={"textSecondary"}>Likes {post.likeCount}</Typography>
|
||||
{/* <Like microBlog = {post.postId} count = {post.likeCount} name = {username}></Like> */}
|
||||
<Button
|
||||
onClick={this.handleClickLikeButton}
|
||||
@ -171,23 +183,21 @@ class Home extends Component {
|
||||
disabled={loading}
|
||||
variant="outlined"
|
||||
color="primary"
|
||||
>
|
||||
{this.state.likes && this.state.likes.includes(post.postId)
|
||||
? "Unlike"
|
||||
: "Like"}
|
||||
</Button>
|
||||
<Quote microblog={post.postId}></Quote>
|
||||
>{
|
||||
this.state.likes && this.state.likes.includes(post.postId) ? 'Unlike' : 'Like'
|
||||
}</Button>
|
||||
<Quote microblog = {post.postId}></Quote>
|
||||
|
||||
{/* <button>Quote</button> */}
|
||||
|
||||
<Typography variant="body2" color={"textSecondary"}>Likes {post.likeCount} Comments {post.commentCount}</Typography>
|
||||
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : (
|
||||
<p></p>
|
||||
)
|
||||
) : (
|
||||
<p></p>
|
||||
)
|
||||
)
|
||||
<p></p>
|
||||
)
|
||||
)
|
||||
) : (
|
||||
<p>Loading post...</p>
|
||||
);
|
||||
@ -425,7 +435,7 @@ class Like extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
handleClick() {
|
||||
handleClick(){
|
||||
this.setState({
|
||||
like: !this.state.like
|
||||
});
|
||||
|
||||
@ -83,6 +83,10 @@ const styles = {
|
||||
wordBreak: "break-all",
|
||||
color: 'black'
|
||||
},
|
||||
dmRecentMessageDisabled: {
|
||||
wordBreak: "break-all",
|
||||
color: 'red'
|
||||
},
|
||||
dmListItemContainer: {
|
||||
height: 100
|
||||
},
|
||||
@ -105,7 +109,7 @@ const styles = {
|
||||
fontSize: 20,
|
||||
backgroundColor: '#1da1f2',
|
||||
width: 300
|
||||
},
|
||||
},
|
||||
messagesGrid: {
|
||||
// // margin: "auto"
|
||||
// height: "auto",
|
||||
@ -426,9 +430,15 @@ export class directMessages extends Component {
|
||||
<Typography
|
||||
className={
|
||||
this.state.selectedChannel && this.state.selectedChannel.dmId === channel.dmId ? (
|
||||
classes.dmRecentMessageSelected
|
||||
channel.hasDirectMessagesEnabled ?
|
||||
classes.dmRecentMessageSelected
|
||||
:
|
||||
classes.dmRecentMessageDisabled
|
||||
) : (
|
||||
classes.dmRecentMessageUnselected
|
||||
channel.hasDirectMessagesEnabled ?
|
||||
classes.dmRecentMessageUnselected
|
||||
:
|
||||
classes.dmRecentMessageDisabled
|
||||
)
|
||||
}
|
||||
>
|
||||
|
||||
@ -36,6 +36,7 @@ export const getUserData = () => (dispatch) => {
|
||||
|
||||
// Sends login data to firebase and sets the user data in Redux
|
||||
export const loginUser = (loginData, history) => (dispatch) => {
|
||||
dispatch({type: CLEAR_ERRORS});
|
||||
dispatch({ type: LOADING_UI });
|
||||
axios
|
||||
.post("/login", loginData)
|
||||
@ -57,6 +58,7 @@ export const loginUser = (loginData, history) => (dispatch) => {
|
||||
|
||||
// Sends signup data to firebase and sets the user data in Redux
|
||||
export const signupUser = (newUserData, history) => (dispatch) => {
|
||||
dispatch({type: CLEAR_ERRORS});
|
||||
dispatch({ type: LOADING_UI });
|
||||
axios
|
||||
.post("/signup", newUserData)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user