From 51b58b9b64da26463e389b32e6bdbf73c69b62e9 Mon Sep 17 00:00:00 2001 From: rohitPandey469 Date: Fri, 16 Feb 2024 19:09:44 +0530 Subject: [PATCH 1/2] First Commit --- src/components/Card/CardWithoutPicture.jsx | 2 +- src/components/TutorialPage/index.jsx | 1 + src/store/actions/authActions.js | 10 ++++--- src/store/actions/profileActions.js | 33 +++++++++++----------- src/store/actions/tutorialsActions.js | 3 ++ 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/components/Card/CardWithoutPicture.jsx b/src/components/Card/CardWithoutPicture.jsx index abc4ecb0..9ce539be 100644 --- a/src/components/Card/CardWithoutPicture.jsx +++ b/src/components/Card/CardWithoutPicture.jsx @@ -108,7 +108,7 @@ export default function CardWithoutPicture({ tutorial }) { {user?.photoURL && user?.photoURL.length > 0 ? ( ) : ( - user?.displayName[0] + "e" // user?.displayName[0] )} } diff --git a/src/components/TutorialPage/index.jsx b/src/components/TutorialPage/index.jsx index dd7895c2..8fbc440d 100644 --- a/src/components/TutorialPage/index.jsx +++ b/src/components/TutorialPage/index.jsx @@ -59,6 +59,7 @@ function TutorialPage({ background = "white", textColor = "black" }) { published_on: tutorial?.createdAt, tag: tutorial?.tut_tags }; + console.log("postDetails",postDetails) const steps = useSelector( ({ diff --git a/src/store/actions/authActions.js b/src/store/actions/authActions.js index 5b748dee..ad04094f 100644 --- a/src/store/actions/authActions.js +++ b/src/store/actions/authActions.js @@ -178,10 +178,12 @@ export const resendVerifyEmail = email => async dispatch => { */ export const checkUserHandleExists = userHandle => async firebase => { try { - const handle = await firebase - .ref(`/cl_user_handle/${userHandle}`) - .once("value"); - return handle.exists(); + const userSnapshot = await firebase + .firestore() + .collection("cl_user") + .doc(userHandle) + .get(); + return userSnapshot.exists; } catch (e) { throw e.message; } diff --git a/src/store/actions/profileActions.js b/src/store/actions/profileActions.js index c3a96c31..0a95831f 100644 --- a/src/store/actions/profileActions.js +++ b/src/store/actions/profileActions.js @@ -157,27 +157,26 @@ export const uploadProfileImage = } }; -export const getUserProfileData = + export const getUserProfileData = handle => async (firebase, firestore, dispatch) => { try { dispatch({ type: actions.GET_USER_DATA_START }); - const isUserExists = await checkUserHandleExists(handle)(firestore); + const isUserExists = await checkUserHandleExists(handle)(firebase); if (isUserExists) { - const docs = await firestore - .collection("cl_user") - .where("handle", "==", handle) - .get(); - const doc = docs.docs[0].data(); - const currentUserId = firebase.auth().currentUser.uid; - const followingStatus = await isUserFollower( - currentUserId, - doc.uid, - firestore - ); - dispatch({ - type: actions.GET_USER_DATA_SUCCESS, - payload: { ...doc, isFollowing: followingStatus } - }); + const docRef = firestore.collection("cl_user").doc(handle); + const doc = (await docRef.get()).data(); + if (doc) { + const currentUserId = firebase.auth().currentUser.uid; + const followingStatus = await isUserFollower( + currentUserId, + doc.uid, + firestore + ); + dispatch({ + type: actions.GET_USER_DATA_SUCCESS, + payload: { ...doc, isFollowing: followingStatus } + }); + } } else { dispatch({ type: actions.GET_USER_DATA_SUCCESS, payload: false }); } diff --git a/src/store/actions/tutorialsActions.js b/src/store/actions/tutorialsActions.js index 7d273c1d..5fa929e8 100644 --- a/src/store/actions/tutorialsActions.js +++ b/src/store/actions/tutorialsActions.js @@ -124,6 +124,8 @@ export const createTutorial = dispatch({ type: actions.CREATE_TUTORIAL_START }); const { title, summary, owner, created_by, is_org } = tutorialData; + const currentUserId = firebase.auth().currentUser.uid; + const setData = async () => { const document = firestore.collection("tutorials").doc(); @@ -131,6 +133,7 @@ export const createTutorial = const step_id = `${documentID}_${new Date().getTime()}`; await document.set({ + user_uid:currentUserId, created_by, editors: [created_by], isPublished: false, From 775787565d0833d54448682cc95c32b9fdd250a6 Mon Sep 17 00:00:00 2001 From: rohitPandey469 Date: Fri, 16 Feb 2024 21:42:16 +0530 Subject: [PATCH 2/2] Made the Follow + button functionality work --- src/components/Card/CardWithPicture.jsx | 15 ++++++------ src/components/Card/CardWithoutPicture.jsx | 17 ++++++------- .../TutorialPage/components/PostDetails.jsx | 2 +- .../TutorialPage/components/UserDetails.jsx | 24 +++++++++++-------- src/components/TutorialPage/index.jsx | 4 ++-- src/store/actions/profileActions.js | 6 ++++- 6 files changed, 39 insertions(+), 29 deletions(-) diff --git a/src/components/Card/CardWithPicture.jsx b/src/components/Card/CardWithPicture.jsx index e8cd65c2..b567fa44 100644 --- a/src/components/Card/CardWithPicture.jsx +++ b/src/components/Card/CardWithPicture.jsx @@ -94,13 +94,14 @@ export default function CardWithPicture({ tutorial }) { getUserProfileData(tutorial?.created_by)(firebase, firestore, dispatch); }, [tutorial]); - const user = useSelector( - ({ - profile: { - user: { data } - } - }) => data - ); + // const user = useSelector( + // ({ + // profile: { + // user: { data } + // } + // }) => data + // ); + const user=null; const getTime = timestamp => { return timestamp.toDate().toDateString(); diff --git a/src/components/Card/CardWithoutPicture.jsx b/src/components/Card/CardWithoutPicture.jsx index 9ce539be..9891fe28 100644 --- a/src/components/Card/CardWithoutPicture.jsx +++ b/src/components/Card/CardWithoutPicture.jsx @@ -88,13 +88,14 @@ export default function CardWithoutPicture({ tutorial }) { getUserProfileData(tutorial?.created_by)(firebase, firestore, dispatch); }, [tutorial]); - const user = useSelector( - ({ - profile: { - user: { data } - } - }) => data - ); + // const user = useSelector( + // ({ + // profile: { + // user: { data } + // } + // }) => data + // ); + const user=null; const getTime = timestamp => { return timestamp.toDate().toDateString(); @@ -108,7 +109,7 @@ export default function CardWithoutPicture({ tutorial }) { {user?.photoURL && user?.photoURL.length > 0 ? ( ) : ( - "e" // user?.displayName[0] + user?.displayName[0] )} } diff --git a/src/components/TutorialPage/components/PostDetails.jsx b/src/components/TutorialPage/components/PostDetails.jsx index 1c46ac63..6cf2f125 100644 --- a/src/components/TutorialPage/components/PostDetails.jsx +++ b/src/components/TutorialPage/components/PostDetails.jsx @@ -101,7 +101,7 @@ const PostDetails = ({ details }) => { diff --git a/src/components/TutorialPage/components/UserDetails.jsx b/src/components/TutorialPage/components/UserDetails.jsx index 0438b2f9..830e9772 100644 --- a/src/components/TutorialPage/components/UserDetails.jsx +++ b/src/components/TutorialPage/components/UserDetails.jsx @@ -24,21 +24,25 @@ const User = ({ id, timestamp, showFollowButton, size }) => { const dispatch = useDispatch(); const firebase = useFirebase(); const firestore = useFirestore(); + const [user, setUser] = useState(null); const [isFollowed, setIsFollowed] = useState(true); useEffect(() => { - getUserProfileData(id)(firebase, firestore, dispatch); - return () => {}; - }, [id]); + const fetchData = async () => { + const data = await getUserProfileData(id)(firebase, firestore, dispatch); + setUser(data); + }; + fetchData(); + }, [id, firebase, firestore, dispatch]); const profileData = useSelector(({ firebase: { profile } }) => profile); - const user = useSelector( - ({ - profile: { - user: { data } - } - }) => data - ); + // const user = useSelector( + // ({ + // profile: { + // user: { data } + // } + // }) => data + // ); useEffect(() => { const checkIsFollowed = async () => { diff --git a/src/components/TutorialPage/index.jsx b/src/components/TutorialPage/index.jsx index 8fbc440d..e0468ebb 100644 --- a/src/components/TutorialPage/index.jsx +++ b/src/components/TutorialPage/index.jsx @@ -57,9 +57,9 @@ function TutorialPage({ background = "white", textColor = "black" }) { upVote: tutorial?.upVotes, downVote: tutorial?.downVotes, published_on: tutorial?.createdAt, - tag: tutorial?.tut_tags + tag: tutorial?.tut_tags, + uid:tutorial?.user_uid }; - console.log("postDetails",postDetails) const steps = useSelector( ({ diff --git a/src/store/actions/profileActions.js b/src/store/actions/profileActions.js index 0a95831f..65583cbb 100644 --- a/src/store/actions/profileActions.js +++ b/src/store/actions/profileActions.js @@ -160,11 +160,12 @@ export const uploadProfileImage = export const getUserProfileData = handle => async (firebase, firestore, dispatch) => { try { + let doc; dispatch({ type: actions.GET_USER_DATA_START }); const isUserExists = await checkUserHandleExists(handle)(firebase); if (isUserExists) { const docRef = firestore.collection("cl_user").doc(handle); - const doc = (await docRef.get()).data(); + doc = (await docRef.get()).data(); if (doc) { const currentUserId = firebase.auth().currentUser.uid; const followingStatus = await isUserFollower( @@ -176,9 +177,12 @@ export const uploadProfileImage = type: actions.GET_USER_DATA_SUCCESS, payload: { ...doc, isFollowing: followingStatus } }); + console.log("Doc from profileActions",doc) } + return doc; } else { dispatch({ type: actions.GET_USER_DATA_SUCCESS, payload: false }); + return null; } } catch (e) { dispatch({ type: actions.GET_USER_DATA_FAIL, payload: e.message });