From 2388a13bb5034a72f35533f14046fc71a98128e8 Mon Sep 17 00:00:00 2001 From: Ben Cole Date: Tue, 21 Jan 2025 16:09:20 -0600 Subject: [PATCH] Removed friend requests button/page --- src/App.jsx | 9 - .../Account/Friends/FriendRequests.jsx | 182 ------------------ src/components/Account/Friends/Friends.css | 8 +- src/components/Account/Friends/MyFriends.jsx | 2 +- src/components/AppBar/AppBar.jsx | 27 ++- .../NavigationBar/NavigationBar.jsx | 2 +- 6 files changed, 15 insertions(+), 215 deletions(-) delete mode 100644 src/components/Account/Friends/FriendRequests.jsx diff --git a/src/App.jsx b/src/App.jsx index 742fbfd..fb1c9a0 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -14,7 +14,6 @@ import SignIn from './components/SignIn/SignIn'; import Feed from './components/Feed/Feed'; import Submission from './components/Submission/Submission'; import Account from './components/Account/Account'; -import FriendRequests from './components/Account/Friends/FriendRequests'; import MyFriends from './components/Account/Friends/MyFriends'; import RatingHistory from './components/RatingHistory/RatingHistory'; import Comment from './components/Comment/Comment'; @@ -77,14 +76,6 @@ function App() { : } /> - - : - } - /> { - if (!user) return; - const unsubscribe = listenIncomingRequests(user.uid, async (raw) => { - const augmented = await Promise.all( - raw.map(async (req) => { - const ref = doc(db, 'users', req.from); - const snap = await getDoc(ref); - let fromDisplay = req.from; - if (snap.exists()) { - const data = snap.data(); - fromDisplay = data.displayName || data.email || req.from; - } - return { ...req, fromDisplay }; - }) - ); - setRequests(augmented); - }); - return () => unsubscribe(); - }, [user]); - - const handleAccept = async (req) => { - await acceptFriendRequest(req.id, req.from, req.to); - }; - - const handleReject = async (req) => { - await rejectFriendRequest(req.id); - }; - - const handleSearchChange = async (e) => { - const value = e.target.value; - setSearchTerm(value); - if (!value.trim()) { - setSearchResults([]); - return; - } - try { - const found = await searchUsersInFirestore(value); - - const filtered = found.filter((f) => f.id !== user.uid); - - const myFriends = await fetchUserFriends(user.uid); - - const resultsAugmented = []; - for (const usr of filtered) { - const pendingDoc = await findPendingRequestDoc(user.uid, usr.id); - const isRequested = !!pendingDoc; - const isFriend = myFriends.includes(usr.id); - resultsAugmented.push({ - ...usr, - requestDoc: pendingDoc ? pendingDoc.docId : null, - isRequested, - isFriend - }); - } - setSearchResults(resultsAugmented); - } catch (err) { - console.error('Error searching users:', err); - } - }; - - const handleActionClick = async (usr, index) => { - if (usr.isFriend) { - await removeFriend(user.uid, usr.id); - const newResults = [...searchResults]; - newResults[index] = { ...newResults[index], isFriend: false }; - setSearchResults(newResults); - return; - } - if (!usr.isRequested) { - const docId = await sendFriendRequest(user.uid, usr.id); - const updated = [...searchResults]; - updated[index] = { ...updated[index], isRequested: true, requestDoc: docId || null }; - setSearchResults(updated); - } else { - if (usr.requestDoc) { - await cancelFriendRequestIfPending(usr.requestDoc); - const updated = [...searchResults]; - updated[index] = { ...updated[index], isRequested: false, requestDoc: null }; - setSearchResults(updated); - } - } - }; - - const getButtonLabel = (usr) => { - if (usr.isFriend) return 'Unfriend'; - if (usr.isRequested) return 'Requested'; - return 'Add Friend'; - }; - - return ( -
- - - - - - ), - }} - style={{ marginBottom: '20px' }} - /> - - {searchResults.length > 0 && ( - <> -

Search Results

- - {searchResults.map((usr, i) => ( - - - - - ))} - -
- - )} - -

Friend Requests

- - {requests.length === 0 &&

No pending requests

} - {requests.map((req) => ( - - - - - - ))} -
-
- -
- ); -} - -export default FriendRequests; diff --git a/src/components/Account/Friends/Friends.css b/src/components/Account/Friends/Friends.css index 521117c..f1a8604 100644 --- a/src/components/Account/Friends/Friends.css +++ b/src/components/Account/Friends/Friends.css @@ -1,10 +1,4 @@ -.friend-requests-page { - margin-top: 3rem; - padding-top: 3rem; - height: calc(100vh - 56px - 64px); - overflow-y: auto; - } - + .my-friends-page { margin-top: 3rem; padding-top: 3rem; diff --git a/src/components/Account/Friends/MyFriends.jsx b/src/components/Account/Friends/MyFriends.jsx index 2c747e4..ddb2989 100644 --- a/src/components/Account/Friends/MyFriends.jsx +++ b/src/components/Account/Friends/MyFriends.jsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect } from 'react'; import { List, ListItem, ListItemText, Button, Container } from '@mui/material'; import { fetchUserFriends, removeFriend } from '../../../services/friendService'; import { doc, getDoc } from 'firebase/firestore'; diff --git a/src/components/AppBar/AppBar.jsx b/src/components/AppBar/AppBar.jsx index cedc9eb..c7bd849 100644 --- a/src/components/AppBar/AppBar.jsx +++ b/src/components/AppBar/AppBar.jsx @@ -1,7 +1,7 @@ import React from 'react'; import { useLocation, useNavigate } from 'react-router-dom'; import ArrowBackIcon from '@mui/icons-material/ArrowBack'; -import PersonSearchIcon from '@mui/icons-material/PersonSearch'; +import PeopleAltIcon from '@mui/icons-material/PeopleAlt'; import "./AppBar.css"; function AppBar() { @@ -10,7 +10,7 @@ function AppBar() { let title = "CourseBuddy"; let showBackButton = false; - let showFriendRequestsIcon = false; + let showMyFriendsIcon = false; if (location.pathname.startsWith('/feed')) { title = "CourseBuddy"; @@ -18,25 +18,23 @@ function AppBar() { title = "New Review"; } else if (location.pathname.startsWith('/account')) { title = "My Account"; - showFriendRequestsIcon = true; + } else if (location.pathname.startsWith('/search')) { + title = "Friends"; + showMyFriendsIcon = true; } - if (location.pathname === '/friend-requests') { - title = "Friend Requests"; - showBackButton = true; - showFriendRequestsIcon = false; - } else if (location.pathname === '/my-friends') { + if (location.pathname === '/my-friends') { title = "My Friends"; showBackButton = true; - showFriendRequestsIcon = false; + showMyFriendsIcon = false; } const handleBackClick = () => { navigate(-1); }; - const handleFriendRequestsClick = () => { - navigate('/friend-requests'); + const handleMyFriendsClick = () => { + navigate('/my-friends'); }; return ( @@ -46,12 +44,11 @@ function AppBar() { )} -

{title}

- {showFriendRequestsIcon && ( - )} diff --git a/src/components/NavigationBar/NavigationBar.jsx b/src/components/NavigationBar/NavigationBar.jsx index 0c24f88..347face 100644 --- a/src/components/NavigationBar/NavigationBar.jsx +++ b/src/components/NavigationBar/NavigationBar.jsx @@ -11,8 +11,8 @@ function NavigationBar() { return ( } component={Link} to="/feed" /> - } component={Link} to="/search" /> } component={Link} to="/submission" /> + } component={Link} to="/search" /> } component={Link} to="/account" /> );