diff --git a/src/components/HomePage.jsx b/src/components/HomePage.jsx index 6c00c45..4b33138 100644 --- a/src/components/HomePage.jsx +++ b/src/components/HomePage.jsx @@ -10,7 +10,7 @@ import { useNavigate } from 'react-router-dom'; export default function HomePage() { const [user] = useAuthState(); const { userProfile, requestedUsers, setRequestedUsers, matchedUserUids, loading } = - useUserProfile(user); + useUserProfile(user, true); const [selectedMajors, setSelectedMajors] = useState([]); const [selectedCourses, setSelectedCourses] = useState([]); const [selectedYears, setSelectedYears] = useState([]); diff --git a/src/hooks/data/useUserProfile.js b/src/hooks/data/useUserProfile.js index 5eaae8d..d6f2032 100644 --- a/src/hooks/data/useUserProfile.js +++ b/src/hooks/data/useUserProfile.js @@ -3,7 +3,7 @@ import { useEffect, useState } from 'react'; import { getMatchedUserUids } from '@firestore/matches'; import { fetchUserProfile } from '@firestore/userProfile'; -export default function useUserProfile(user) { +export default function useUserProfile(user, getMatchData = false) { const [userProfile, setUserProfile] = useState(null); const [requestedUsers, setRequestedUsers] = useState(new Set()); const [matchedUserUids, setMatchedUserUids] = useState(new Set()); @@ -19,10 +19,17 @@ export default function useUserProfile(user) { if (profile) { setUserProfile(profile); + // If getMatchData is false, skip fetching match data + if (!getMatchData) { + setLoading(false); + return; + } + if (profile.major === '' || profile.year === '') { setLoading(false); return; } + setRequestedUsers(new Set(profile.outgoingMatches.map((match) => match.requestedUser))); const matchedUids = await getMatchedUserUids(user.uid); @@ -43,7 +50,7 @@ export default function useUserProfile(user) { setUserProfile(null); setLoading(false); } - }, [user?.uid]); + }, [user?.uid, getMatchData]); return { userProfile, requestedUsers, setRequestedUsers, matchedUserUids, loading }; }