From a79169517ecd9b946a7d478a08b9bec072d39db2 Mon Sep 17 00:00:00 2001 From: shajeed Date: Mon, 4 Sep 2023 19:54:46 -0400 Subject: [PATCH 1/2] Fix comment in full page post --- .../PostsComponents/AddCommentInput/AddCommentInput.js | 4 ++-- client/src/Components/PostsComponents/PostsFeed/PostsFeed.js | 1 + client/src/Pages/FullPagePost/FullPagePost.js | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/client/src/Components/PostsComponents/AddCommentInput/AddCommentInput.js b/client/src/Components/PostsComponents/AddCommentInput/AddCommentInput.js index ef35bce4..8d8e62ad 100644 --- a/client/src/Components/PostsComponents/AddCommentInput/AddCommentInput.js +++ b/client/src/Components/PostsComponents/AddCommentInput/AddCommentInput.js @@ -31,8 +31,8 @@ function AddCommentInput({ const commentData = { createdAt: serverTimestamp(), - userId: loggedInUser.id, // Replace with the actual user ID - display_name: loggedInUser.displayName, + userId: loggedInUser.id, + display_name: loggedInUser.display_name, profile_avatar: loggedInUser.profile_avatar, comment: commentText, likes: [], diff --git a/client/src/Components/PostsComponents/PostsFeed/PostsFeed.js b/client/src/Components/PostsComponents/PostsFeed/PostsFeed.js index af8786f4..8aedd211 100644 --- a/client/src/Components/PostsComponents/PostsFeed/PostsFeed.js +++ b/client/src/Components/PostsComponents/PostsFeed/PostsFeed.js @@ -186,6 +186,7 @@ function PostsFeed({ id={id} postType={postType} postDate={postDate} + loggedInUser={loggedInUser} // postDateType={postDateType} // setPostStates={setPostStates} // postName={postName} diff --git a/client/src/Pages/FullPagePost/FullPagePost.js b/client/src/Pages/FullPagePost/FullPagePost.js index c3fe1d0a..65603354 100644 --- a/client/src/Pages/FullPagePost/FullPagePost.js +++ b/client/src/Pages/FullPagePost/FullPagePost.js @@ -36,6 +36,7 @@ function FullPagePost({ isFullPagePostModalDisplay, // handleDropdownPostFeedClick, fullPagePostModalStyle, + loggedInUser, }) { const [ isMediaQueriesFullPagePostDisabled, @@ -342,6 +343,7 @@ function FullPagePost({ isMediaQueriesFullPagePostDisabled } postId={id} + loggedInUser={loggedInUser} /> From 8893a66aa8d57693cc0cff32b7bf677fc604c87a Mon Sep 17 00:00:00 2001 From: shajeed Date: Mon, 4 Sep 2023 22:39:38 -0400 Subject: [PATCH 2/2] scheduled post --- client/functions/index.js | 38 +++++++++++++++++++ .../CreationPostPoll/CreationPostPoll.js | 1 + .../Components/FeedLaunchpad/FeedLaunchpad.js | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/client/functions/index.js b/client/functions/index.js index e51b5a61..eeeb3757 100644 --- a/client/functions/index.js +++ b/client/functions/index.js @@ -77,3 +77,41 @@ exports.sendWelcomeEmail = functions.https.onRequest((req, res) => { }); }); + + +const admin = require('firebase-admin'); +//const functions = require('firebase-functions'); +admin.initializeApp(); + +exports.scheduledPublish = functions.pubsub.schedule('every 60 minutes').onRun(async (context) => { + const now = admin.firestore.Timestamp.now(); + const scheduledPostsRef = admin.firestore().collection('scheduled_posts'); + const feedPostsRef = admin.firestore().collection('feed_post'); + + console.log('Checking for scheduled posts to publish...'); + + const snapshot = await scheduledPostsRef.where('publish_timestamp', '<=', now).get(); + + if (snapshot.empty) { + console.log('No posts to publish.'); + return null; + } + + const batch = admin.firestore().batch(); + + snapshot.docs.forEach((doc) => { + const postData = doc.data(); + postData.createdAt = now; // Update the createdAt value to the current timestamp + const newPostRef = feedPostsRef.doc(); + + batch.set(newPostRef, postData); + batch.delete(doc.ref); + }); + + return batch.commit().then(() => { + console.log('Posts published successfully!'); + return null; + }); +}); + + diff --git a/client/src/Components/CreationPostPoll/CreationPostPoll.js b/client/src/Components/CreationPostPoll/CreationPostPoll.js index 8063ea76..cac01fef 100644 --- a/client/src/Components/CreationPostPoll/CreationPostPoll.js +++ b/client/src/Components/CreationPostPoll/CreationPostPoll.js @@ -121,6 +121,7 @@ const CreationPostPoll = ({ userId }) => { try { // Upload the post object to Firestore + // const postRef = collection(db, "scheduled_posts"); const postRef = collection(db, "feed_post"); let postUid; await addDoc(postRef, post).then((snapshot) => { diff --git a/client/src/Components/FeedLaunchpad/FeedLaunchpad.js b/client/src/Components/FeedLaunchpad/FeedLaunchpad.js index 971fe295..2389e2bf 100644 --- a/client/src/Components/FeedLaunchpad/FeedLaunchpad.js +++ b/client/src/Components/FeedLaunchpad/FeedLaunchpad.js @@ -45,7 +45,7 @@ const FeedLaunchpad = () => { result.sort((a, b) => a.launch_date.seconds - b.launch_date.seconds); const mostRecentUpcomingLaunch = result[0]; - console.log(mostRecentUpcomingLaunch); + //console.log(mostRecentUpcomingLaunch); setMostRecentLaunchpad(mostRecentUpcomingLaunch); } else { console.log("No upcoming launches found.");