From 67031fcd4f48d6629fe61fc28b8bfd88d057f535 Mon Sep 17 00:00:00 2001 From: Ra Date: Thu, 14 Sep 2023 01:00:55 +0200 Subject: [PATCH] followers display in favathelte --- client/src/App.js | 2 +- .../AthleteTemplate/AthleteTemplate.js | 1 + .../FavAthlete/Carroussel/Carroussel.css | 2 + .../FavAthlete/Carroussel/Carroussel.js | 13 ++--- .../src/Components/FavAthlete/FavAthlete.js | 4 +- .../src/Components/LoginSignupPopUp/Signup.js | 4 +- client/src/Components/Navbar/Navbar.js | 2 +- client/src/Pages/Home/Home.js | 58 +++++++++++++++++-- 8 files changed, 68 insertions(+), 18 deletions(-) diff --git a/client/src/App.js b/client/src/App.js index 7477f6ac..fac4243b 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -178,7 +178,7 @@ function App() { setIsSignInButtonClicked(false); setIsSignUpButtonClicked(true); }; - console.log(loggedInUser); + // console.log(loggedInUser); const ref = useRef([]); const [items, set] = useState([]); const transitions = useTransition(items, { diff --git a/client/src/Components/FavAthlete/AthleteTemplate/AthleteTemplate.js b/client/src/Components/FavAthlete/AthleteTemplate/AthleteTemplate.js index 1faa40cd..88eb6252 100644 --- a/client/src/Components/FavAthlete/AthleteTemplate/AthleteTemplate.js +++ b/client/src/Components/FavAthlete/AthleteTemplate/AthleteTemplate.js @@ -13,6 +13,7 @@ const AthleteTemplate = ({ href, src, athleteName, isFan }) => { style={{ backgroundImage: `linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, #000000 100%), url(${src})`, backgroundPosition: "center", + backgroundRepeat: "no-repeat" }} > {isFan && star} diff --git a/client/src/Components/FavAthlete/Carroussel/Carroussel.css b/client/src/Components/FavAthlete/Carroussel/Carroussel.css index b3fd905c..a49ebd80 100644 --- a/client/src/Components/FavAthlete/Carroussel/Carroussel.css +++ b/client/src/Components/FavAthlete/Carroussel/Carroussel.css @@ -54,6 +54,8 @@ } .carroussel-left-arrow-wrap > img { transform: rotate(180deg); + background-repeat: no-repeat; + } @media (max-width: 950px) { .carroussel-section{ diff --git a/client/src/Components/FavAthlete/Carroussel/Carroussel.js b/client/src/Components/FavAthlete/Carroussel/Carroussel.js index 3344c43a..3cb5b333 100644 --- a/client/src/Components/FavAthlete/Carroussel/Carroussel.js +++ b/client/src/Components/FavAthlete/Carroussel/Carroussel.js @@ -5,7 +5,7 @@ import Mbappe from "../fakeData/mbappe.svg"; import RightArrow from "../../../Assets/Image/right_arrow.svg"; import "./Carroussel.css"; import { v4 as uuidv4 } from "uuid"; -const Carroussel = () => { +const Carroussel = ({ athletesFollowing }) => { const [rightArrowClicked, setRightArrowClicked] = useState(false); const [leftArrowClicked, setLeftArrowClicked] = useState(false); const [counter, setCounter] = useState(0); @@ -92,15 +92,14 @@ const Carroussel = () => { counter !== (filteredArray.length - 2) * 120 * -1 ? style2 : style } > - {filteredArray.map((athlete) => { + {athletesFollowing.map((athlete) => { return (
); diff --git a/client/src/Components/FavAthlete/FavAthlete.js b/client/src/Components/FavAthlete/FavAthlete.js index 653aeaf9..3a7d03ed 100644 --- a/client/src/Components/FavAthlete/FavAthlete.js +++ b/client/src/Components/FavAthlete/FavAthlete.js @@ -6,7 +6,7 @@ import LeBron from "./fakeData/lebron.svg"; import Mbappe from "./fakeData/mbappe.svg"; import FeedSuggestionTemplate from "../FeedSuggestions/FeedSuggestionTemplate/FeedSuggestionTemplate"; import { v4 as uuidv4 } from "uuid"; -const FavAthlete = () => { +const FavAthlete = ({athletesFollowing}) => { const fakeArray = [ { firstName: "James", @@ -77,7 +77,7 @@ const FavAthlete = () => { Vos sportifs préférés {/* Voir plus */} - +
{filteredArray.map((athlete) => ( unsubscribe(); }, []); + useEffect(() => { + const userIdToFind = loggedInUser?.id; + + const usersRef = collection(db, "users"); + const q = query(usersRef, where("account_type", "==", "athlete")); + + const unsubscribe = onSnapshot(q, async (querySnapshot) => { + const foundAthletes = []; + for (let doc of querySnapshot.docs) { + const athleteId = doc.id; + const userData = doc.data(); + + // Accéder à la collection athlete_data pour l'athlète spécifique + const athleteDataRef = collection( + db, + "users", + athleteId, + "athlete_data" + ); + + // Récupérer le document + const athleteDataSnapshot = await getDocs(athleteDataRef); + athleteDataSnapshot.forEach((doc) => { + if (doc.exists) { + const athleteData = doc.data(); + if ( + athleteData && + athleteData.followers && + athleteData.followers.includes(userIdToFind) + ) { + foundAthletes.push({ + athleteId, + profile_avatar: userData.profile_avatar, + username: userData.username, + }); + } + } + }); + } + setAthletesFollowing(foundAthletes); + }); + + return () => unsubscribe(); + }, [loggedInUser]); + + console.log(athletesFollowing); + const handleDropdownPostFeedClick = (e) => { for (let i = 0; i < dataPost.length; i++) { if ( @@ -162,10 +211,7 @@ function Home({ }, 5700); // clearTimeout(timeOutHideCopyClicked); } - useEffect(() => { - console.log(dataPost); - }, [dataPost]); - // console.log(loggedInUser?.account_type) + return ( <>
@@ -219,7 +265,9 @@ function Home({ ) }
- +