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

[ Fix : Correctly Showing Avatars for Users in the Tutorials ] #1206

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
26 changes: 18 additions & 8 deletions src/components/Card/CardWithPicture.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
26 changes: 18 additions & 8 deletions src/components/Card/CardWithoutPicture.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
28 changes: 14 additions & 14 deletions src/components/TutorialPage/components/PostDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -101,7 +101,7 @@ const PostDetails = ({ details }) => {
<Box sx={{ width: "100%", marginTop: "10px" }}>
<Grid container justifyContent="space-between" alignItems="end">
<User
id={details?.user}
id={details?.id}
timestamp={details?.published_on}
showFollowButton={true}
/>
Expand Down
26 changes: 17 additions & 9 deletions src/components/TutorialPage/components/UserDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
3 changes: 2 additions & 1 deletion src/components/TutorialPage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 6 additions & 4 deletions src/store/actions/authActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
34 changes: 18 additions & 16 deletions src/store/actions/profileActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
1 change: 1 addition & 0 deletions src/store/actions/tutorialPageActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/store/actions/tutorialsActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,16 @@ 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();

const documentID = document.id;
const step_id = `${documentID}_${new Date().getTime()}`;

await document.set({
user_uid:currentUserId,
created_by,
editors: [created_by],
isPublished: false,
Expand Down