diff --git a/functions/handlers/post.js b/functions/handlers/post.js
index b431e0a..407a85c 100644
--- a/functions/handlers/post.js
+++ b/functions/handlers/post.js
@@ -67,6 +67,102 @@ exports.getallPosts = (req, res) => {
});
};
+exports.quoteWithPost = (req, res) => {
+
+ let quoteData;
+ const quoteDoc = admin.firestore().collection('quote').
+ where('userHandle', '==', req.user.handle).
+ where('postId', '==', req.params.postId).limit(1);
+
+ const postDoc = db.doc(`/posts/${req.params.postId}`);
+
+ postDoc.get()
+ .then((doc) => {
+ if(doc.exists) {
+ quoteData = doc.data();
+ return quoteDoc.get();
+ }
+ else
+ {
+ return res.status(404).json({error: 'Post not found'});
+ }
+ })
+ .then((data) => {
+ if(data.empty) {
+ return admin.firestore().collection('quote').add({
+ postId : req.params.postId,
+ userHandle : req.user.handle,
+ quotePost : req.body.quotePost
+ })
+ .then(() => {
+ return admin.firestore().collection('posts').add({
+ quoteData,
+ quoteUser : req.user.handle,
+ quotePost : req.body.quotePost,
+ quotedAt : new Date().toISOString()
+
+ })
+ })
+ }
+ else {
+ console.log("Post has already been quoted.");
+ return res.status(400).json({ error: 'Post has already been quoted.' });
+ }
+ })
+ .catch((err) => {
+ return res.status(500).json({error: 'Something is wrong'});
+
+ })
+
+}
+
+exports.quoteWithoutPost = (req, res) => {
+ let quoteData;
+ const quoteDoc = admin.firestore().collection('quote').
+ where('userHandle', '==', req.user.handle).
+ where('postId', '==', req.params.postId).limit(1);
+
+ const postDoc = db.doc(`/posts/${req.params.postId}`);
+
+ postDoc.get()
+ .then((doc) => {
+ if(doc.exists) {
+ quoteData = doc.data();
+ return quoteDoc.get();
+ }
+ else
+ {
+ return res.status(404).json({error: 'Post not found'});
+ }
+ })
+ .then((data) => {
+ if(data.empty) {
+ return admin.firestore().collection('quote').add({
+ postId : req.params.postId,
+ userHandle : req.user.handle,
+ })
+ .then(() => {
+ return admin.firestore().collection('posts').add({
+ quoteData,
+ quoteUser : req.user.handle,
+ quotedAt : new Date().toISOString()
+
+ })
+ })
+ }
+ else {
+ console.log("Post has already been quoted.");
+ return res.status(400).json({ error: 'Post has already been quoted.' });
+ }
+ })
+ .catch((err) => {
+ return res.status(500).json({error: 'Something is wrong'});
+
+ })
+
+}
+
+
exports.likePost = (req, res) => {
let postData;
const likeDoc = admin.firestore().collection('likes').where('userHandle', '==', req.user.handle)
@@ -146,7 +242,6 @@ exports.unlikePost = (req, res) => {
}
-
exports.getFilteredPosts = (req, res) => {
admin.firestore().collection('posts').where('userHandle', '==', 'new user').where('microBlogTopics', '==')
};
diff --git a/functions/index.js b/functions/index.js
index 2dd66ae..cdea2d1 100644
--- a/functions/index.js
+++ b/functions/index.js
@@ -58,7 +58,7 @@ app.get("/getUserHandles", fbAuth, getUserHandles);
/*------------------------------------------------------------------*
* handlers/post.js *
*------------------------------------------------------------------*/
-const { getallPostsforUser, getallPosts, putPost, likePost, unlikePost} = require("./handlers/post");
+const { getallPostsforUser, getallPosts, putPost, likePost, unlikePost, quoteWithPost, quoteWithoutPost} = require("./handlers/post");
app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
@@ -70,6 +70,11 @@ app.post("/putPost", fbAuth, putPost);
app.get("/like/:postId", fbAuth, likePost);
app.get("/unlike/:postId", fbAuth, unlikePost);
+app.post("/quoteWithPost/:postId", fbAuth, quoteWithPost);
+app.post("/quoteWithoutPost/:postId", fbAuth, quoteWithoutPost);
+
+
+
/*------------------------------------------------------------------*
* handlers/topic.js *
*------------------------------------------------------------------*/
diff --git a/twistter-frontend/src/pages/Home.js b/twistter-frontend/src/pages/Home.js
index fb28409..ff90580 100644
--- a/twistter-frontend/src/pages/Home.js
+++ b/twistter-frontend/src/pages/Home.js
@@ -15,6 +15,8 @@ import '../App.css';
import logo from '../images/twistter-logo.png';
import noImage from '../images/no-img.png';
import Writing_Microblogs from '../Writing_Microblogs';
+import ReactModal from 'react-modal';
+
class Home extends Component {
state = {
@@ -58,6 +60,7 @@ class Home extends Component {
)
@@ -110,6 +113,118 @@ Home.propTypes = {
user: PropTypes.object.isRequired
}
+class Quote extends Component {
+ constructor(props) {
+ super(props);
+ this.state = {
+ characterCount: 250,
+ showModal: false,
+ value: ""
+ }
+
+ this.handleSubmitWithoutPost = this.handleSubmitWithoutPost.bind(this);
+ this.handleOpenModal = this.handleOpenModal.bind(this);
+ this.handleCloseModal = this.handleCloseModal.bind(this);
+ this.handleSubmit = this.handleSubmit.bind(this);
+ }
+
+ handleSubmitWithoutPost(event) {
+ const headers = {
+ headers: { "Content-Type": "application/json" }
+ };
+ axios.post(`/quoteWithoutPost/${this.props.microblog}`, headers)
+ .then((res) => {
+
+ console.log(res.data);
+ })
+ .catch(err => {
+
+ console.error(err);
+ });
+ event.preventDefault();
+ }
+
+ handleOpenModal() {
+ this.setState({ showModal: true });
+ }
+
+ handleCloseModal() {
+ this.setState({ showModal: false });
+ }
+
+ handleChangeforPost(event) {
+ this.setState({ value: event.target.value });
+ }
+
+ handleChangeforCharacterCount(event) {
+ const charCount = event.target.value.length;
+ const charRemaining = 250 - charCount;
+ this.setState({ characterCount: charRemaining });
+ }
+
+ handleSubmit(event) {
+ const quotedPost = {
+ quotePost: this.state.value,
+ };
+ const headers = {
+ headers: { "Content-Type": "application/json" }
+ };
+ axios.post(`/quoteWithPost/${this.props.microblog}`, quotedPost, headers)
+ .then((res) => {
+
+ console.log(res.data);
+ })
+ .catch(err => {
+
+ console.error(err);
+ });
+ event.preventDefault();
+ this.setState({ showModal: false, characterCount: 250, value: "" });
+ }
+
+ render() {
+ return (
+