Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sd 368 like post and comment post backend #203

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions client/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});


1 change: 1 addition & 0 deletions client/src/Components/CreationPostPoll/CreationPostPoll.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion client/src/Components/FeedLaunchpad/FeedLaunchpad.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ function PostsFeed({
id={id}
postType={postType}
postDate={postDate}
loggedInUser={loggedInUser}
// postDateType={postDateType}
// setPostStates={setPostStates}
// postName={postName}
Expand Down
2 changes: 2 additions & 0 deletions client/src/Pages/FullPagePost/FullPagePost.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function FullPagePost({
isFullPagePostModalDisplay,
// handleDropdownPostFeedClick,
fullPagePostModalStyle,
loggedInUser,
}) {
const [
isMediaQueriesFullPagePostDisabled,
Expand Down Expand Up @@ -342,6 +343,7 @@ function FullPagePost({
isMediaQueriesFullPagePostDisabled
}
postId={id}
loggedInUser={loggedInUser}
/>
</div>
</div>
Expand Down
Loading