diff --git a/epoch_backend/persistence/epoch/epoch_notification_persistence.py b/epoch_backend/persistence/epoch/epoch_notification_persistence.py index 9a64adb..d3a8915 100644 --- a/epoch_backend/persistence/epoch/epoch_notification_persistence.py +++ b/epoch_backend/persistence/epoch/epoch_notification_persistence.py @@ -11,7 +11,7 @@ def get_user_notifications(self, user_id: int, limit: int, offset: int): conn = get_db_connection() curr = conn.cursor() - curr.execute("SELECT * FROM notifications WHERE user_id = %s ORDER BY created_at DESC LIMIT %s OFFSET %s", (user_id, limit, offset)) + curr.execute("SELECT * FROM notifications WHERE user_id = %s AND created_at > now() ORDER BY created_at DESC LIMIT %s OFFSET %s", (user_id, limit, offset)) notifs = curr.fetchall() for i in range(len(notifs)): diff --git a/epoch_backend/persistence/epoch/epoch_post_persistence.py b/epoch_backend/persistence/epoch/epoch_post_persistence.py index 7081d58..a17c462 100644 --- a/epoch_backend/persistence/epoch/epoch_post_persistence.py +++ b/epoch_backend/persistence/epoch/epoch_post_persistence.py @@ -52,7 +52,7 @@ def add_post(self, new_post: post): mentioned_notification = cursor.fetchone() if not mentioned_notification and mentioned_user[0] != new_post.user_id: - cursor.execute("INSERT INTO notifications (user_id, type, target_id, target_username, target_name) VALUES (%s, %s, %s, %s, %s)", (mentioned_user[0], "mention", post_id, user_info[0], user_info[1])) + cursor.execute("INSERT INTO notifications (user_id, type, target_id, created_at, target_username, target_name) VALUES (%s, %s, %s, %s, %s, %s)", (mentioned_user[0], "mention", post_id, new_post.release, user_info[0], user_info[1])) connection.commit() @@ -205,7 +205,7 @@ def update_post(self, post_id: int, new_post: post): mentioned_notification = cursor.fetchone() if not mentioned_notification and mentioned_user[0] != new_post.user_id: - cursor.execute("INSERT INTO notifications (user_id, type, target_id, target_username, target_name) VALUES (%s, %s, %s, %s, %s)", (mentioned_user[0], "mention", post_id, user_info[0], user_info[1])) + cursor.execute("INSERT INTO notifications (user_id, type, target_id, created_at, target_username, target_name) VALUES (%s, %s, %s, %s, %s, %s)", (mentioned_user[0], "mention", post_id, new_post.release, user_info[0], user_info[1])) connection.commit() if old_post_caption: diff --git a/epoch_frontend/src/modules/EditProfilePopup.js b/epoch_frontend/src/modules/EditProfilePopup.js index a70955c..e6c1220 100644 --- a/epoch_frontend/src/modules/EditProfilePopup.js +++ b/epoch_frontend/src/modules/EditProfilePopup.js @@ -1,8 +1,9 @@ -import React, {useState, useRef, useEffect} from 'react'; +import React, {useState, useRef, useEffect, useContext} from 'react'; import {updateUser} from '../services/user'; import '../styles/EditProfilePopup.css'; import {useSpring, animated} from 'react-spring'; + function EditProfilePopup({onClose, user, showEditProfilePopup, setShowEditProfilePopup, refreshProfile, setRefreshProfile, profilePicId, profilePicUrl, profilePicName, profilePicType, backgroundPicId, backgroundPicUrl, backgroundPicName, backgroundPicType}) { const [formData, setFormData] = useState({ username: user.username, @@ -45,7 +46,6 @@ function EditProfilePopup({onClose, user, showEditProfilePopup, setShowEditProfi const maxImageBytes = 30000001; const allowedFileTypes = ["jpg", "jpeg", "png", "gif", "HEIC", "JPG", "JPEG", "PNG", "GIF", "heic"]; - const {transform: inTransform, opacity: inOpacity} = useSpring({ opacity: showEditProfilePopup ? 1 : 0, transform: `translateY(${showEditProfilePopup ? 0 : 100}vh)`, diff --git a/epoch_frontend/src/modules/NotificationItem.js b/epoch_frontend/src/modules/NotificationItem.js index 090de70..53c447b 100644 --- a/epoch_frontend/src/modules/NotificationItem.js +++ b/epoch_frontend/src/modules/NotificationItem.js @@ -69,32 +69,7 @@ function NotificationItem({notification, setShowNotifications, onRead}) { const isNotificationVisible = () => { - let toReturn = true; - - if(notification) { - if(notification.type === 'mention') { - getAllComments(notification.target_id) - .then(data => { - let thePost = data.post; - - const now = new Date(); - let postTime = new Date(thePost.release); - postTime = new Date(Date.UTC(postTime.getFullYear(), postTime.getMonth(), postTime.getDate(), postTime.getHours(), postTime.getMinutes(), postTime.getSeconds())); - let isInPast = now >= postTime; - - if (!isInPast) { - toReturn = false; - } - }) - .catch(error => { - toReturn = false; - }) - - - } - } - - return toReturn; + return true; } diff --git a/epoch_frontend/src/modules/ProtectedRoute.js b/epoch_frontend/src/modules/ProtectedRoute.js index d28304f..c0f0989 100644 --- a/epoch_frontend/src/modules/ProtectedRoute.js +++ b/epoch_frontend/src/modules/ProtectedRoute.js @@ -1,5 +1,7 @@ import { useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; +import { useContext } from 'react'; +import { UserContext } from '../services/UserContext'; // Utility function to get the "epoch_session_id" cookie export function getSessionCookie() { @@ -14,9 +16,13 @@ export function isSessionActive() { const ProtectedRoute = ({ children }) => { const navigate = useNavigate(); + + useEffect(() => { // Check if the session is active; if not, redirect to the login page if (!isSessionActive()) { + const { updateUser } = useContext(UserContext); + updateUser(null); navigate('/epoch/login'); } }, [navigate]); diff --git a/epoch_frontend/src/pages/Comments.js b/epoch_frontend/src/pages/Comments.js index 425e6e2..c7f751e 100644 --- a/epoch_frontend/src/pages/Comments.js +++ b/epoch_frontend/src/pages/Comments.js @@ -3,7 +3,6 @@ import {Spinner} from '../modules/Spinner'; import {getAllComments} from '../services/comments' import NavBar from "../modules/NavBar"; import PostPopup from "../modules/PostPopup"; -import Post from '../modules/Post' import {useLocation} from 'react-router-dom'; import Comment from '../modules/Comment'; import '../styles/PostComments.css' @@ -28,9 +27,6 @@ function Comments() { const [showNewPostPopup, setShowNewPostPopup] = useState(false); const [showNewCommentPopup, setShowNewCommentPopup] = useState(false); const [refreshComments, setRefreshComments] = useState(false); - const [mentionedUsers, setMentionedUsers] = useState([]); - const [failedToFetchUser, setFailedToFetchUser] = useState(false); - const [fetchedPost, setFetchedPost] = useState(false); const navigate = useNavigate(); useEffect(() => { @@ -39,14 +35,9 @@ function Comments() { getUserInfo() .then(data => { updateUser(data); - setFailedToFetchUser(false); }) .catch(error => { updateUser(null); - setFailedToFetchUser(true); - if(mentionedUsers.length > 0 && fetchedPost){ - navigate('/epoch/login') - } }); } @@ -59,26 +50,6 @@ function Comments() { setIsLoading(true); getAllComments(postId) .then(data => { - const usernames = []; - const regex = /@([a-zA-Z0-9_]+)/g; - - if (data.post.caption) { - const matches = data.post.caption.match(regex); - - if (matches) { - for (let i = 0; i < matches.length; i++) { - usernames.push(matches[i].substring(1)); - } - } - } - setMentionedUsers(usernames); - - if(usernames.length > 0 && user === null && failedToFetchUser){ - navigate('/epoch/login') - } - - setFetchedPost(true); - setCommentsPost(data.post); setComments(data.comments); setRefreshComments(false); @@ -88,7 +59,6 @@ function Comments() { console.log(error) setRefreshComments(false); setIsLoading(false); - setFetchedPost(false); navigate('/epoch/login') }) } @@ -103,27 +73,6 @@ function Comments() { if (postId !== -1) { getAllComments(postId) .then(data => { - - const usernames = []; - const regex = /@([a-zA-Z0-9_]+)/g; - - if (data.post.caption) { - const matches = data.post.caption.match(regex); - - if (matches) { - for (let i = 0; i < matches.length; i++) { - usernames.push(matches[i].substring(1)); - } - } - } - setMentionedUsers(usernames); - - if(usernames.length > 0 && user === null && failedToFetchUser){ - navigate('/epoch/login') - } - - setFetchedPost(true); - setCommentsPost(data.post); setComments(data.comments); setIsLoading(false); @@ -131,7 +80,6 @@ function Comments() { .catch(error => { console.log(error); setIsLoading(false); - setFetchedPost(false); navigate('/epoch/login') }) } @@ -145,7 +93,7 @@ function Comments() { return ( <> {user ? () : ( + showNewPostPopup={showNewCommentPopup} setShowNewPostPopup={setShowNewCommentPopup} userId={user.id}/>) : ( )} {isLoading ? ( @@ -167,7 +115,9 @@ function Comments() { {user && ()} + onClick={() => setShowNewCommentPopup(!showNewCommentPopup)}>{ + showNewCommentPopup ? '+' : + })} {comments && comments.length === 0 &&
No comments yet
} diff --git a/epoch_frontend/src/pages/profile.js b/epoch_frontend/src/pages/profile.js index 86e970c..b2b884c 100644 --- a/epoch_frontend/src/pages/profile.js +++ b/epoch_frontend/src/pages/profile.js @@ -266,7 +266,6 @@ function Profile() { .catch(error => { console.log("Error fetching user info:", error); setIsLoading(false); - }); } }, [refreshProfile, setRefreshProfile, updateUser]);