diff --git a/client/html/pages/home/index.html b/client/html/pages/home/index.html index a6e8360..9f32920 100644 --- a/client/html/pages/home/index.html +++ b/client/html/pages/home/index.html @@ -120,11 +120,7 @@
No avatar configured yet.
+ Create Avatar +Unable to load avatar. Please try again later.
+ Go to Avatar Page +${blurb ? escapeHtml(blurb) : 'No blurb set.'}
@@ -148,35 +213,22 @@ $(document).ready(function () {Error: Invalid user data received.
'); + return; + } console.log('User profile data received:', user); // Add this line currentUser = user; - fetchUserStatus(username).then((isOnline) => { - user.isOnline = isOnline; - fetchForumPostCount(user._id).then((postCount) => { - user.forumPostCount = postCount; - displayUserProfile(user); - }); - }); - document.getElementById('profile-title').textContent = `${user.username}'s Profile - Valkyrie`; - }, + updateFriendshipUI({ + isFriend: user.isFriend, + friendRequestSent: user.friendRequestSent, + friendRequestReceived: user.friendRequestReceived + }); + fetchUserStatus(username).then((isOnline) => { + user.isOnline = isOnline; + fetchForumPostCount(user._id).then((postCount) => { + user.forumPostCount = postCount; + displayUserProfile(user); + }); + }); + document.getElementById('profile-title').textContent = `${user.username}'s Profile - Valkyrie`; + }, error: function (xhr, status, error) { console.error('Error fetching user profile:', xhr.responseText); $('#user-profile').html('Error fetching user profile. Please try again.
'); @@ -77,6 +87,12 @@ $(document).ready(function () { } function displayUserProfile(user) { + if (!user || !user.username) { + console.error('Invalid user data:', user); + $('#user-info').html('0/500
@@ -645,6 +657,7 @@ $(document).ready(function () { } function escapeHtml(unsafe) { + if (!unsafe) return ''; return unsafe .replace(/&/g, '&') .replace(/ Unfriend'; + actionButton = ` + + + `; } else if (status.friendRequestReceived) { - actionButton = ` - - - `; + actionButton = ` + + + `; } else if (status.friendRequestSent) { - actionButton = ''; + actionButton = ` + + + `; } else { - actionButton = ` - - - `; + actionButton = ` + + + `; } $('#action-button-container').html(actionButton); initFriendActions(); - } */ +} }); function formatDate(dateString) { diff --git a/server/functions/api/routes/friends.js b/server/functions/api/routes/friends.js index ef821a9..c3f4999 100644 --- a/server/functions/api/routes/friends.js +++ b/server/functions/api/routes/friends.js @@ -80,20 +80,20 @@ router.post( // Add this new route after the existing friend-related routes router.get( - '/friendship-status/:userId', + '/friendship-status/:username', authenticateToken, async (req, res) => { try { - const currentUser = await User.findById({ userId: req.user.userId }); + const currentUser = await User.findOne({ userId: req.user.userId }); const targetUser = await User.findOne({ username: req.params.username }); if (!targetUser) { return res.status(404).json({ error: 'User not found' }); } - const isFriend = currentUser.friends.includes(targetUser.userId); - const friendRequestSent = targetUser.friendRequests.includes(currentUser.userId); - const friendRequestReceived = currentUser.friendRequests.includes(targetUser.userId); + const isFriend = currentUser.friends.some(id => id.equals(targetUser._id)); + const friendRequestSent = targetUser.friendRequests.some(id => id.equals(currentUser._id)); + const friendRequestReceived = currentUser.friendRequests.some(id => id.equals(targetUser._id)); res.json({ isFriend, diff --git a/server/functions/api/routes/user.js b/server/functions/api/routes/user.js index 07f9efd..a10eee4 100644 --- a/server/functions/api/routes/user.js +++ b/server/functions/api/routes/user.js @@ -30,9 +30,9 @@ router.get('/user/:username', authenticateToken, async (req, res) => { avatarRenderDetails: user.avatarRender }); - const isFriend = currentUser.friends.includes(user.userId); - const friendRequestSent = user.friendRequests.includes(currentUser.userId); - const friendRequestReceived = currentUser.friendRequests.includes(user.userId); + const isFriend = currentUser.friends.some(id => id.equals(user._id)); + const friendRequestSent = user.friendRequests.some(id => id.equals(currentUser._id)); + const friendRequestReceived = currentUser.friendRequests.some(id => id.equals(user._id)); delete user.friendRequests; delete user.friends;