diff --git a/src/components/Card/CardWithPicture.jsx b/src/components/Card/CardWithPicture.jsx index e8cd65c2..e2b7d379 100644 --- a/src/components/Card/CardWithPicture.jsx +++ b/src/components/Card/CardWithPicture.jsx @@ -75,6 +75,7 @@ export default function CardWithPicture({ tutorial }) { const classes = useStyles(); const [alignment, setAlignment] = React.useState("left"); const [count, setCount] = useState(1); + const [user,setUser]=useState(null) const dispatch = useDispatch(); const firebase = useFirebase(); const firestore = useFirestore(); @@ -91,16 +92,25 @@ export default function CardWithPicture({ tutorial }) { }; useEffect(() => { - getUserProfileData(tutorial?.created_by)(firebase, firestore, dispatch); + const fetchData = async () => { + const data = await getUserProfileData(tutorial?.user_uid)( + firebase, + firestore, + dispatch + ); + console.log("Data From CardWithPic ",data) + setUser(data); + }; + fetchData(); }, [tutorial]); - const user = useSelector( - ({ - profile: { - user: { data } - } - }) => data - ); + // const user = useSelector( + // ({ + // profile: { + // user: { data } + // } + // }) => data + // ); const getTime = timestamp => { return timestamp.toDate().toDateString(); diff --git a/src/components/Card/CardWithoutPicture.jsx b/src/components/Card/CardWithoutPicture.jsx index abc4ecb0..09c2a48f 100644 --- a/src/components/Card/CardWithoutPicture.jsx +++ b/src/components/Card/CardWithoutPicture.jsx @@ -69,6 +69,7 @@ export default function CardWithoutPicture({ tutorial }) { const classes = useStyles(); const [alignment, setAlignment] = React.useState("left"); const [count, setCount] = useState(1); + const [user, setUser] = useState(null); const dispatch = useDispatch(); const firebase = useFirebase(); const firestore = useFirestore(); @@ -85,16 +86,25 @@ export default function CardWithoutPicture({ tutorial }) { }; useEffect(() => { - getUserProfileData(tutorial?.created_by)(firebase, firestore, dispatch); + const fetchData = async () => { + const data = await getUserProfileData(tutorial?.user_uid)( + firebase, + firestore, + dispatch + ); + console.log("Data from Card W/o Pic",data) + setUser(data); + }; + fetchData(); }, [tutorial]); - const user = useSelector( - ({ - profile: { - user: { data } - } - }) => data - ); + // const user = useSelector( + // ({ + // profile: { + // user: { data } + // } + // }) => data + // ); const getTime = timestamp => { return timestamp.toDate().toDateString(); diff --git a/src/components/TutorialPage/components/PostDetails.jsx b/src/components/TutorialPage/components/PostDetails.jsx index 1c46ac63..899e01aa 100644 --- a/src/components/TutorialPage/components/PostDetails.jsx +++ b/src/components/TutorialPage/components/PostDetails.jsx @@ -42,24 +42,24 @@ const useStyles = makeStyles(() => ({ })); const PostDetails = ({ details }) => { - const dispatch = useDispatch(); - const firebase = useFirebase(); - const firestore = useFirestore(); + // const dispatch = useDispatch(); + // const firebase = useFirebase(); + // const firestore = useFirestore(); const [alignment, setAlignment] = React.useState("left"); const [count, setCount] = useState(details.upVote - details.downVote || 0); const { id } = useParams(); - useEffect(() => { - getUserProfileData(details.user)(firebase, firestore, dispatch); - }, [details]); + // useEffect(() => { + // getUserProfileData(details.user)(firebase, firestore, dispatch); + // }, [details]); - const user = useSelector( - ({ - profile: { - user: { data } - } - }) => data - ); + // const user = useSelector( + // ({ + // profile: { + // user: { data } + // } + // }) => data + // ); const getTime = timestamp => { return timestamp.toDate().toDateString(); @@ -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..12820dc1 100644 --- a/src/components/TutorialPage/components/UserDetails.jsx +++ b/src/components/TutorialPage/components/UserDetails.jsx @@ -25,20 +25,28 @@ const User = ({ id, timestamp, showFollowButton, size }) => { const firebase = useFirebase(); const firestore = useFirestore(); const [isFollowed, setIsFollowed] = useState(true); + const [user, setUser]=useState(null); useEffect(() => { - getUserProfileData(id)(firebase, firestore, dispatch); - return () => {}; + const fetchData = async () => { + const data = await getUserProfileData(id)( + firebase, + firestore, + dispatch + ); + setUser(data); + }; + fetchData(); }, [id]); 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 dd7895c2..3a6c5cc1 100644 --- a/src/components/TutorialPage/index.jsx +++ b/src/components/TutorialPage/index.jsx @@ -57,7 +57,8 @@ function TutorialPage({ background = "white", textColor = "black" }) { upVote: tutorial?.upVotes, downVote: tutorial?.downVotes, published_on: tutorial?.createdAt, - tag: tutorial?.tut_tags + tag: tutorial?.tut_tags, + id: tutorial?.user_uid }; const steps = useSelector( diff --git a/src/store/actions/authActions.js b/src/store/actions/authActions.js index 5b748dee..9d3a9a99 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..c08ebdd1 100644 --- a/src/store/actions/profileActions.js +++ b/src/store/actions/profileActions.js @@ -160,26 +160,28 @@ 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)(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); + 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 } + }); + } + 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 }); diff --git a/src/store/actions/tutorialPageActions.js b/src/store/actions/tutorialPageActions.js index c716765a..7d2770b6 100644 --- a/src/store/actions/tutorialPageActions.js +++ b/src/store/actions/tutorialPageActions.js @@ -94,6 +94,7 @@ export const getTutorialFeedData = const feed = tutorials.docs.map(doc => { const tutorial = doc.data(); const tutorialData = { + user_uid:tutorial?.user_uid, tutorial_id: tutorial?.tutorial_id, title: tutorial?.title, summary: tutorial?.summary, 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,