diff options
Diffstat (limited to 'src/actions/firebaseFirestore.js')
-rw-r--r-- | src/actions/firebaseFirestore.js | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/actions/firebaseFirestore.js b/src/actions/firebaseFirestore.js index 1e2296c..636c944 100644 --- a/src/actions/firebaseFirestore.js +++ b/src/actions/firebaseFirestore.js @@ -93,7 +93,18 @@ export const snapshotForums = () => (dispatch) => { docRef.onSnapshot((query) => { var forumPosts = []; query.forEach((doc) => { - forumPosts.push(doc.data()); + var comments = []; + docRef.doc(doc.id).collection('comments') + .onSnapshot((queryComments)=> { + queryComments.forEach((comment) => { + comments.push(comment.data()); + }); + }); + forumPosts.push({ + ...doc.data(), + comments, + postId: doc.id + }); }); dispatch(updateForumPosts(forumPosts)); }); @@ -116,7 +127,7 @@ export const setUserData = (_divison) => (dispatch, getState) => { export const requestHours = (_time, _trainee, _location, _subject, _date, _pictureName) => (dispatch, getState) => { if(getState().app.offline) { - alert("Failed to create forum post. Must have internet connection.") + alert("Failed to create hour request. Must have internet connection.") } else { dispatch(updateNotification(false)); var docRef = firestore.collection('requests'); @@ -200,5 +211,24 @@ export const createForumPost = (_subject, _content) => (dispatch, getState) => { alert(error); }); } +} +export const createComment = (postId, subject, content) => (dispatch, getState) => { + if(getState().app.offline) { + alert("Failed to create comment post. Please establish internet connection.") + } else { + var docRef = firestore.collection('posts').doc(postId).collection('comments'); + var user = getState().firebaseAuth.userEmail.replace('@communityschoolnaples.org', ''); + docRef.add({ + subject, + content, + user, + date: new Date() + }).then(()=> { + alert("Successfuly posted comment."); + }).catch((error) => { + alert(error); + }); + } } + |