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 : "Follow +" button in Tutorial View Implemented ] #1204

Open
wants to merge 2 commits 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
15 changes: 8 additions & 7 deletions src/components/Card/CardWithPicture.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 8 additions & 7 deletions src/components/Card/CardWithoutPicture.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/components/TutorialPage/components/PostDetails.jsx
Original file line number Diff line number Diff line change
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?.uid}
timestamp={details?.published_on}
showFollowButton={true}
/>
Expand Down
24 changes: 14 additions & 10 deletions src/components/TutorialPage/components/UserDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
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,
uid: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
37 changes: 20 additions & 17 deletions src/store/actions/profileActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,29 +157,32 @@ export const uploadProfileImage =
}
};

export const getUserProfileData =
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 }
});
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 });
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