Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SD-293-FavAthlete-HomePage #209

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 && <img src={Star} alt="star" className="athleteTemplate-star" />}
Expand Down
2 changes: 2 additions & 0 deletions client/src/Components/FavAthlete/Carroussel/Carroussel.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
}
.carroussel-left-arrow-wrap > img {
transform: rotate(180deg);
background-repeat: no-repeat;

}
@media (max-width: 950px) {
.carroussel-section{
Expand Down
13 changes: 6 additions & 7 deletions client/src/Components/FavAthlete/Carroussel/Carroussel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -92,15 +92,14 @@ const Carroussel = () => {
counter !== (filteredArray.length - 2) * 120 * -1 ? style2 : style
}
>
{filteredArray.map((athlete) => {
{athletesFollowing.map((athlete) => {
return (
<div key={uuidv4()} className="athlete-template-container">
<AthleteTemplate

href={`/profile/${athlete.id}`}
src={athlete.img}
athleteName={athlete.surName + " " + athlete.firstName}
isFan={athlete.isFan}
href={`/athleteprofile/${athlete.athleteId}`}
src={athlete.profile_avatar}
athleteName={athlete.username}
// isFan={athlete.isFan}
/>
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions client/src/Components/FavAthlete/FavAthlete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -77,7 +77,7 @@ const FavAthlete = () => {
<span>Vos sportifs préférés</span>
{/* <a href="/favathlete-details"> Voir plus</a> */}
</div>
<Carroussel />
<Carroussel athletesFollowing={athletesFollowing}/>
<div className="favAthlete-responsive-container">
{filteredArray.map((athlete) => (
<FeedSuggestionTemplate
Expand Down
4 changes: 2 additions & 2 deletions client/src/Components/LoginSignupPopUp/Signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -1015,11 +1015,11 @@ function Signup({
isPasswordMatch;

if (allFieldsValid) {
console.log("Tout est bon!");
// console.log("Tout est bon!");
setIsAllFieldsComplete(true);
} else {
setIsAllFieldsComplete(false);
console.log("tout n'est pas bon");
// console.log("tout n'est pas bon");
}
// }, [email, username, password, showError, isPasswordMatch]);
}, [
Expand Down
2 changes: 1 addition & 1 deletion client/src/Components/Navbar/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const Navbar = ({
setIsPageHomeDisplay(true);
setIsPageLaunchpadDisplay(false);

console.log("ceci est home");
// console.log("ceci est home");
} else {
setIsPageHomeDisplay(false);
}
Expand Down
58 changes: 53 additions & 5 deletions client/src/Pages/Home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ function Home({
const [commentCounts, setCommentCounts] = useState({});
const [commentCounterIncrementLocal, setCommentCounterIncrementLocal] =
useState(0);
const [athletesFollowing, setAthletesFollowing] = useState([]);

function handleDisplayPremiumContent(i) {
if (isUserFan === false && dataPost[i]?.visibility === false) {
return true;
Expand Down Expand Up @@ -101,6 +103,53 @@ function Home({
return () => 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 (
Expand Down Expand Up @@ -162,10 +211,7 @@ function Home({
}, 5700);
// clearTimeout(timeOutHideCopyClicked);
}
useEffect(() => {
console.log(dataPost);
}, [dataPost]);
// console.log(loggedInUser?.account_type)

return (
<>
<section className="home-component">
Expand Down Expand Up @@ -219,7 +265,9 @@ function Home({
)
}
</div>
<FavAthlete />
<FavAthlete
athletesFollowing={athletesFollowing}
/>
<FeedSuggestions
handleAthleteSuggestionClick={handleAthleteSuggestionClick}
suggestionsAthletes={suggestionsAthletes}
Expand Down
Loading