From 933036a4d83bbe2b73897fdac2c31473f2f3d8d5 Mon Sep 17 00:00:00 2001 From: Abhishek Pandey Date: Tue, 22 Aug 2023 03:58:18 +0530 Subject: [PATCH 1/3] Feed tutorials set for following users --- src/components/HomePage/index.jsx | 20 ++++-- .../TutorialPage/components/UserDetails.jsx | 21 ++++++- src/store/actions/profileActions.js | 2 +- src/store/actions/tutorialPageActions.js | 61 ++++++++++++++++++- src/store/actions/tutorialsActions.js | 1 + 5 files changed, 95 insertions(+), 10 deletions(-) diff --git a/src/components/HomePage/index.jsx b/src/components/HomePage/index.jsx index 8ab6c8db..e8190e6b 100644 --- a/src/components/HomePage/index.jsx +++ b/src/components/HomePage/index.jsx @@ -33,7 +33,10 @@ import useWindowSize from "../../helpers/customHooks/useWindowSize"; import NewTutorial from "../Tutorials/NewTutorial"; import { useDispatch, useSelector } from "react-redux"; import { useFirebase, useFirestore } from "react-redux-firebase"; -import { getTutorialFeedData } from "../../store/actions/tutorialPageActions"; +import { + getTutorialFeedData, + getTutorialFeedIdArray +} from "../../store/actions/tutorialPageActions"; function HomePage({ background = "white", textColor = "black" }) { const classes = useStyles(); @@ -161,10 +164,17 @@ function HomePage({ background = "white", textColor = "black" }) { } ]); - const tutorialIdArray = ["9VF7JGNPYmTQe7tdhZfQ"]; - + const profileData = useSelector(({ firebase: { profile } }) => profile); useEffect(() => { - getTutorialFeedData(tutorialIdArray)(firebase, firestore, dispatch); + const getFeed = async () => { + const tutorialIdArray = await getTutorialFeedIdArray(profileData.uid)( + firebase, + firestore, + dispatch + ); + getTutorialFeedData(tutorialIdArray)(firebase, firestore, dispatch); + }; + getFeed(); }, []); const tutorials = useSelector( ({ @@ -174,8 +184,6 @@ function HomePage({ background = "white", textColor = "black" }) { }) => homepageFeedArray ); - console.log("tutorials array", tutorials); - const notification = () => {}; const handleChange = (event, newValue) => { setValue(newValue); diff --git a/src/components/TutorialPage/components/UserDetails.jsx b/src/components/TutorialPage/components/UserDetails.jsx index 88be6a3a..d028eea8 100644 --- a/src/components/TutorialPage/components/UserDetails.jsx +++ b/src/components/TutorialPage/components/UserDetails.jsx @@ -5,6 +5,8 @@ import Avatar from "@mui/material/Avatar"; import { useDispatch, useSelector } from "react-redux"; import { useFirebase, useFirestore } from "react-redux-firebase"; import { getUserProfileData } from "../../../store/actions"; +import { isUserFollower } from "../../../store/actions/profileActions"; +import { addUserFollower } from "../../../store/actions"; const useStyles = makeStyles(() => ({ container: { padding: "20px", @@ -22,10 +24,13 @@ const User = ({ id, timestamp, showFollowButton, size }) => { const dispatch = useDispatch(); const firebase = useFirebase(); const firestore = useFirestore(); + const [isFollowed, setIsFollowed] = useState(true); useEffect(() => { getUserProfileData(id)(firebase, firestore, dispatch); }, [id]); + const profileData = useSelector(({ firebase: { profile } }) => profile); + const user = useSelector( ({ profile: { @@ -34,6 +39,19 @@ const User = ({ id, timestamp, showFollowButton, size }) => { }) => data ); + useEffect(() => { + const checkIsFollowed = async () => { + const status = await isUserFollower(profileData.uid, user.uid, firestore); + setIsFollowed(status); + console.log(status); + }; + checkIsFollowed(); + }, [profileData, user]); + + const followUser = () => { + addUserFollower(profileData, user, firestore); + }; + const getTime = timestamp => { return timestamp.toDate().toDateString(); }; @@ -81,7 +99,8 @@ const User = ({ id, timestamp, showFollowButton, size }) => { {showFollowButton && (