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

[ Feat : The "Add" and "Remove" following options implemented ] #1181

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
37 changes: 28 additions & 9 deletions src/components/CardTabs/Users/UserElement.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import Box from "@mui/material/Box";
import AddUser from "../../../assets/images/add-user.svg";
import CheckUser from "../../../assets/images/square-check-regular.svg";

const UserElement = ({ user, index, useStyles }) => {
const classes = useStyles();
const [icon, setIcon] = useState(true);
useEffect(() => {
const fetchData = async () => {
try {
const isFollowing = await user.onClick.isUserFollower();
setIcon(!isFollowing);
} catch (error) {
console.error("Error fetching follower status:", error);
}
};
fetchData();
}, [icon]);
const handleUserClick = async event => {
event.preventDefault();
try {
let isFollowing = await user.onClick.isUserFollower();
if (isFollowing) {
await user.onClick.removeUserFollower();
} else {
await user.onClick.addUserFollower();
}
setIcon(isFollowing);
} catch (error) {
console.error("Error toggling follower status:", error);
}
};
return (
<Box
sx={{
Expand Down Expand Up @@ -46,15 +71,9 @@ const UserElement = ({ user, index, useStyles }) => {
</Box>
</Box>
<Box
onClick={() => {
setIcon(false);
}}
onClick={handleUserClick}
data-testId={index == 0 ? "UserAdd" : ""}
sx={
icon && {
cursor: "pointer"
}
}
sx={icon && { cursor: "pointer" }}
>
<img src={icon ? AddUser : CheckUser} />
</Box>
Expand Down
108 changes: 86 additions & 22 deletions src/components/HomePage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ import {
getTutorialFeedData,
getTutorialFeedIdArray
} from "../../store/actions/tutorialPageActions";
import { addUserFollower } from "../../store/actions";
import {
isUserFollower,
removeUserFollower
} from "../../store/actions/profileActions";

function HomePage({ background = "white", textColor = "black" }) {
const classes = useStyles();
Expand Down Expand Up @@ -109,31 +114,75 @@ function HomePage({ background = "white", textColor = "black" }) {
"Python",
"React"
]);

const profileToFollowData = {
// displayName: "SouGatariju"
// email: "sougatariju13@gmail.com"
uid: "850pPlsLaCg6JjmrKjOu6JqRPwhb"
};
const profileData = useSelector(({ firebase: { profile } }) => profile);
useEffect(() => {
const getFeed = async () => {
const tutorialIdArray = await getTutorialFeedIdArray(profileData.uid)(
firebase,
firestore,
dispatch
);
getTutorialFeedData(tutorialIdArray)(firebase, firestore, dispatch);
};
getFeed();
}, []);
const [usersToFollow, setUsersToFollow] = useState([
{
name: "Janvi Thakkar",
img: [OrgUser],
desg: "Software Engineer",
onClick: {}
onClick: {
addUserFollower: () =>
addUserFollower(profileData, profileToFollowData, firestore),
isUserFollower: () =>
isUserFollower(profileData.uid, profileToFollowData.uid, firestore),
removeUserFollower: () =>
removeUserFollower(profileData, profileToFollowData, firestore)
}
},
{
name: "Janvi Thakkar",
img: [OrgUser],
desg: "Software Engineer",
onClick: {}
onClick: {
addUserFollower: () =>
addUserFollower(profileData, profileToFollowData, firestore),
isUserFollower: () =>
isUserFollower(profileData.uid, profileToFollowData.uid, firestore),
removeUserFollower: () =>
removeUserFollower(profileData, profileToFollowData, firestore)
}
},
{
name: "Janvi Thakkar",
img: [OrgUser],
desg: "Software Engineer",
onClick: {}
onClick: {
addUserFollower: () =>
addUserFollower(profileData, profileToFollowData, firestore),
isUserFollower: () =>
isUserFollower(profileData.uid, profileToFollowData.uid, firestore),
removeUserFollower: () =>
removeUserFollower(profileData, profileToFollowData, firestore)
}
},
{
name: "Janvi Thakkar",
img: [OrgUser],
desg: "Software Engineer",
onClick: {}
onClick: {
addUserFollower: () =>
addUserFollower(profileData, profileToFollowData, firestore),
isUserFollower: () =>
isUserFollower(profileData.uid, profileToFollowData.uid, firestore),
removeUserFollower: () =>
removeUserFollower(profileData, profileToFollowData, firestore)
}
}
]);

Expand All @@ -142,40 +191,55 @@ function HomePage({ background = "white", textColor = "black" }) {
name: "Janvi Thakkar",
img: [OrgUser],
desg: "Software Engineer",
onClick: {}
onClick: {
addUserFollower: () =>
addUserFollower(profileData, profileToFollowData, firestore),
isUserFollower: () =>
isUserFollower(profileData.uid, profileToFollowData.uid, firestore),
removeUserFollower: () =>
removeUserFollower(profileData, profileToFollowData, firestore)
}
},
{
name: "Janvi Thakkar",
img: [OrgUser],
desg: "Software Engineer",
onClick: {}
onClick: {
addUserFollower: () =>
addUserFollower(profileData, profileToFollowData, firestore),
isUserFollower: () =>
isUserFollower(profileData.uid, profileToFollowData.uid, firestore),
removeUserFollower: () =>
removeUserFollower(profileData, profileToFollowData, firestore)
}
},
{
name: "Janvi Thakkar",
img: [OrgUser],
desg: "Software Engineer",
onClick: {}
onClick: {
addUserFollower: () =>
addUserFollower(profileData, profileToFollowData, firestore),
isUserFollower: () =>
isUserFollower(profileData.uid, profileToFollowData.uid, firestore),
removeUserFollower: () =>
removeUserFollower(profileData, profileToFollowData, firestore)
}
},
{
name: "Janvi Thakkar",
img: [OrgUser],
desg: "Software Engineer",
onClick: {}
onClick: {
addUserFollower: () =>
addUserFollower(profileData, profileToFollowData, firestore),
isUserFollower: () =>
isUserFollower(profileData.uid, profileToFollowData.uid, firestore),
removeUserFollower: () =>
removeUserFollower(profileData, profileToFollowData, firestore)
}
}
]);

const profileData = useSelector(({ firebase: { profile } }) => profile);
useEffect(() => {
const getFeed = async () => {
const tutorialIdArray = await getTutorialFeedIdArray(profileData.uid)(
firebase,
firestore,
dispatch
);
getTutorialFeedData(tutorialIdArray)(firebase, firestore, dispatch);
};
getFeed();
}, []);
const tutorials = useSelector(
({
tutorialPage: {
Expand Down
6 changes: 6 additions & 0 deletions src/store/actions/profileActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export const isUserFollower = async (followerId, followingId, firestore) => {
.collection("user_followers")
.doc(`${followingId}_${followerId}`)
.get();
console.log("Is User follower ran!!!",followerDoc.exists)
return followerDoc.exists;
};

Expand All @@ -209,7 +210,9 @@ export const addUserFollower = async (
profileData.uid,
firestore
);
console.log("Add User Follow ran!!!")
if (followStatus === false) {
console.log("New Follower")
await firestore
.collection("user_followers")
.doc(`${profileData.uid}_${currentProfileData.uid}`)
Expand Down Expand Up @@ -252,7 +255,9 @@ export const removeUserFollower = async (
profileData.uid,
firestore
);
console.log("Remove User Follow ran!!!")
if (followStatus === true) {
console.log("Removing the follower")
await firestore
.collection("user_followers")
.doc(`${profileData.uid}_${currentProfileData.uid}`)
Expand All @@ -276,6 +281,7 @@ export const removeUserFollower = async (
: 0
});
}
console.log("Remove User Follow ran!!!")
} catch (e) {
console.log(e);
}
Expand Down