From cebd301b58350180fa4e70f9db566bdcc3c00b11 Mon Sep 17 00:00:00 2001 From: Mohammed Huzaif Ahmed Date: Mon, 1 Apr 2024 12:17:18 +0530 Subject: [PATCH 1/2] rendering comments on time --- .../TutorialPage/components/Commnets/CommentBox.jsx | 9 ++++++--- src/store/actions/tutorialPageActions.js | 5 +++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/TutorialPage/components/Commnets/CommentBox.jsx b/src/components/TutorialPage/components/Commnets/CommentBox.jsx index 02f462f9..db1ca42a 100644 --- a/src/components/TutorialPage/components/Commnets/CommentBox.jsx +++ b/src/components/TutorialPage/components/Commnets/CommentBox.jsx @@ -35,7 +35,7 @@ const CommentBox = ({ commentsArray, tutorialId }) => { const dispatch = useDispatch(); const [comments, setComments] = useState([]); const [currCommentCount, setCurrCommentCount] = useState(3); - const handleSubmit = comment => { + const handleSubmit = async(comment) => { const commentData = { content: comment, replyTo: tutorialId, @@ -43,14 +43,17 @@ const CommentBox = ({ commentsArray, tutorialId }) => { createdAt: firestore.FieldValue.serverTimestamp(), userId: "codelabzuser" }; - addComment(commentData)(firebase, firestore, dispatch); + let x=await addComment(commentData)(firebase, firestore, dispatch); + console.log("new id ",x); + setComments(prevComments => [...prevComments, x]) }; useEffect(() => { setComments(commentsArray?.slice(0, currCommentCount)); + }, [currCommentCount, commentsArray]); - console.log(commentsArray, comments, currCommentCount); + console.log(commentsArray,comments, currCommentCount); const increaseCommentCount = () => { setCurrCommentCount(state => state + 3); diff --git a/src/store/actions/tutorialPageActions.js b/src/store/actions/tutorialPageActions.js index c716765a..7050622f 100644 --- a/src/store/actions/tutorialPageActions.js +++ b/src/store/actions/tutorialPageActions.js @@ -195,10 +195,13 @@ export const getCommentReply = export const addComment = comment => async (firebase, firestore, dispatch) => { try { dispatch({ type: actions.ADD_COMMENT_START }); + let x="" await firestore .collection("cl_comments") .add(comment) .then(docref => { + x=docref.id; + console.log("docref", docref.id); firestore.collection("cl_comments").doc(docref.id).update({ comment_id: docref.id }); @@ -213,7 +216,9 @@ export const addComment = comment => async (firebase, firestore, dispatch) => { }) .then(() => { dispatch({ type: actions.ADD_COMMENT_SUCCESS }); + return x ; }); + return x; } catch (e) { dispatch({ type: actions.ADD_COMMENT_FAILED, payload: e.message }); } From a8b59f8547e1880d84a1a77639bd5cb1ed21a481 Mon Sep 17 00:00:00 2001 From: Mohammed Huzaif Ahmed Date: Mon, 1 Apr 2024 12:17:54 +0530 Subject: [PATCH 2/2] rendering comments on time --- .../components/Commnets/CommentBox.jsx | 11 +- src/store/actions/tutorialPageActions.js | 8 +- src/store/actions/tutorialsActions.js | 294 +++++++++--------- 3 files changed, 156 insertions(+), 157 deletions(-) diff --git a/src/components/TutorialPage/components/Commnets/CommentBox.jsx b/src/components/TutorialPage/components/Commnets/CommentBox.jsx index db1ca42a..95646c58 100644 --- a/src/components/TutorialPage/components/Commnets/CommentBox.jsx +++ b/src/components/TutorialPage/components/Commnets/CommentBox.jsx @@ -35,7 +35,7 @@ const CommentBox = ({ commentsArray, tutorialId }) => { const dispatch = useDispatch(); const [comments, setComments] = useState([]); const [currCommentCount, setCurrCommentCount] = useState(3); - const handleSubmit = async(comment) => { + const handleSubmit = async comment => { const commentData = { content: comment, replyTo: tutorialId, @@ -43,17 +43,16 @@ const CommentBox = ({ commentsArray, tutorialId }) => { createdAt: firestore.FieldValue.serverTimestamp(), userId: "codelabzuser" }; - let x=await addComment(commentData)(firebase, firestore, dispatch); - console.log("new id ",x); - setComments(prevComments => [...prevComments, x]) + let x = await addComment(commentData)(firebase, firestore, dispatch); + console.log("new id ", x); + setComments(prevComments => [...prevComments, x]); }; useEffect(() => { setComments(commentsArray?.slice(0, currCommentCount)); - }, [currCommentCount, commentsArray]); - console.log(commentsArray,comments, currCommentCount); + console.log(commentsArray, comments, currCommentCount); const increaseCommentCount = () => { setCurrCommentCount(state => state + 3); diff --git a/src/store/actions/tutorialPageActions.js b/src/store/actions/tutorialPageActions.js index 7050622f..389992b5 100644 --- a/src/store/actions/tutorialPageActions.js +++ b/src/store/actions/tutorialPageActions.js @@ -195,12 +195,12 @@ export const getCommentReply = export const addComment = comment => async (firebase, firestore, dispatch) => { try { dispatch({ type: actions.ADD_COMMENT_START }); - let x="" + let x = ""; await firestore .collection("cl_comments") .add(comment) .then(docref => { - x=docref.id; + x = docref.id; console.log("docref", docref.id); firestore.collection("cl_comments").doc(docref.id).update({ comment_id: docref.id @@ -216,9 +216,9 @@ export const addComment = comment => async (firebase, firestore, dispatch) => { }) .then(() => { dispatch({ type: actions.ADD_COMMENT_SUCCESS }); - return x ; + return x; }); - return x; + return x; } catch (e) { dispatch({ type: actions.ADD_COMMENT_FAILED, payload: e.message }); } diff --git a/src/store/actions/tutorialsActions.js b/src/store/actions/tutorialsActions.js index 7d273c1d..f6adedc4 100644 --- a/src/store/actions/tutorialsActions.js +++ b/src/store/actions/tutorialsActions.js @@ -230,36 +230,36 @@ export const getCurrentTutorialData = export const addNewTutorialStep = ({ owner, tutorial_id, title, time, id }) => - async (firebase, firestore, dispatch) => { - try { - dispatch({ type: actions.CREATE_TUTORIAL_STEP_START }); + async (firebase, firestore, dispatch) => { + try { + dispatch({ type: actions.CREATE_TUTORIAL_STEP_START }); - await firestore - .collection("tutorials") - .doc(tutorial_id) - .collection("steps") - .doc(id) - .set({ - content: `Switch to editor mode to begin ${title} step`, - id, - time, - title, - visibility: true, - deleted: false - }); + await firestore + .collection("tutorials") + .doc(tutorial_id) + .collection("steps") + .doc(id) + .set({ + content: `Switch to editor mode to begin ${title} step`, + id, + time, + title, + visibility: true, + deleted: false + }); - await getCurrentTutorialData(owner, tutorial_id)( - firebase, - firestore, - dispatch - ); + await getCurrentTutorialData(owner, tutorial_id)( + firebase, + firestore, + dispatch + ); - dispatch({ type: actions.CREATE_TUTORIAL_STEP_SUCCESS }); - } catch (e) { - console.log("CREATE_TUTORIAL_STEP_FAIL", e.message); - dispatch({ type: actions.CREATE_TUTORIAL_STEP_FAIL, payload: e.message }); - } - }; + dispatch({ type: actions.CREATE_TUTORIAL_STEP_SUCCESS }); + } catch (e) { + console.log("CREATE_TUTORIAL_STEP_FAIL", e.message); + dispatch({ type: actions.CREATE_TUTORIAL_STEP_FAIL, payload: e.message }); + } + }; export const clearCreateTutorials = () => dispatch => dispatch({ type: actions.CLEAR_CREATE_TUTORIALS_STATE }); @@ -305,78 +305,78 @@ export const setCurrentStepContent = export const hideUnHideStep = (owner, tutorial_id, step_id, visibility) => - async (firebase, firestore, dispatch) => { - try { - /* not being used */ - // const type = await checkUserOrOrgHandle(owner)(firebase); - await firestore - .collection("tutorials") - .doc(tutorial_id) - .collection("steps") - .doc(step_id) - .update({ - [`visibility`]: !visibility, - updatedAt: firestore.FieldValue.serverTimestamp() - }); + async (firebase, firestore, dispatch) => { + try { + /* not being used */ + // const type = await checkUserOrOrgHandle(owner)(firebase); + await firestore + .collection("tutorials") + .doc(tutorial_id) + .collection("steps") + .doc(step_id) + .update({ + [`visibility`]: !visibility, + updatedAt: firestore.FieldValue.serverTimestamp() + }); - await getCurrentTutorialData(owner, tutorial_id)( - firebase, - firestore, - dispatch - ); - } catch (e) { - console.log(e.message); - } - }; + await getCurrentTutorialData(owner, tutorial_id)( + firebase, + firestore, + dispatch + ); + } catch (e) { + console.log(e.message); + } + }; export const publishUnpublishTutorial = (owner, tutorial_id, isPublished) => - async (firebase, firestore, dispatch) => { - try { - await firestore - .collection("tutorials") - .doc(tutorial_id) - .update({ - ["isPublished"]: !isPublished - }); + async (firebase, firestore, dispatch) => { + try { + await firestore + .collection("tutorials") + .doc(tutorial_id) + .update({ + ["isPublished"]: !isPublished + }); - getCurrentTutorialData(owner, tutorial_id)(firebase, firestore, dispatch); - } catch (e) { - console.log(e.message); - } - }; + getCurrentTutorialData(owner, tutorial_id)(firebase, firestore, dispatch); + } catch (e) { + console.log(e.message); + } + }; export const removeStep = (owner, tutorial_id, step_id, current_step_no) => - async (firebase, firestore, dispatch) => { - try { - await firestore - .collection("tutorials") - .doc(tutorial_id) - .collection("steps") - .doc(step_id) - .delete() - - // const data = await firestore - // .collection("tutorials") - // .doc(tutorial_id) - // .collection("steps") - // .doc(step_id) - // .get(); - - await setCurrentStepNo( - current_step_no > 0 ? current_step_no - 1 : current_step_no - )(dispatch); - - await getCurrentTutorialData(owner, tutorial_id)( - firebase, - firestore, - dispatch - ); - } catch (e) { - console.log(e.message); - } - }; + async (firebase, firestore, dispatch) => { + try { + await firestore + .collection("tutorials") + .doc(tutorial_id) + .collection("steps") + .doc(step_id) + .delete(); + + // const data = await firestore + // .collection("tutorials") + // .doc(tutorial_id) + // .collection("steps") + // .doc(step_id) + // .get(); + + await setCurrentStepNo( + current_step_no > 0 ? current_step_no - 1 : current_step_no + )(dispatch); + + await getCurrentTutorialData(owner, tutorial_id)( + firebase, + firestore, + dispatch + ); + } catch (e) { + console.log(e.message); + } + }; export const setCurrentStep = data => async dispatch => dispatch({ type: actions.SET_EDITOR_DATA, payload: data }); @@ -465,69 +465,69 @@ export const remoteTutorialImages = export const updateStepTitle = (owner, tutorial_id, step_id, step_title) => - async (firebase, firestore, dispatch) => { - try { - const dbPath = `tutorials/${tutorial_id}/steps`; - await firestore - .collection(dbPath) - .doc(step_id) - .update({ - [`title`]: step_title, - updatedAt: firestore.FieldValue.serverTimestamp() - }); + async (firebase, firestore, dispatch) => { + try { + const dbPath = `tutorials/${tutorial_id}/steps`; + await firestore + .collection(dbPath) + .doc(step_id) + .update({ + [`title`]: step_title, + updatedAt: firestore.FieldValue.serverTimestamp() + }); - await getCurrentTutorialData(owner, tutorial_id)( - firebase, - firestore, - dispatch - ); - } catch (e) { - console.log(e); - } - }; + await getCurrentTutorialData(owner, tutorial_id)( + firebase, + firestore, + dispatch + ); + } catch (e) { + console.log(e); + } + }; export const updateStepTime = (owner, tutorial_id, step_id, step_time) => - async (firebase, firestore, dispatch) => { - try { - const dbPath = `tutorials/${tutorial_id}/steps`; - - await firestore - .collection(dbPath) - .doc(step_id) - .update({ - [`time`]: step_time, - updatedAt: firestore.FieldValue.serverTimestamp() - }); + async (firebase, firestore, dispatch) => { + try { + const dbPath = `tutorials/${tutorial_id}/steps`; - await getCurrentTutorialData(owner, tutorial_id)( - firebase, - firestore, - dispatch - ); - } catch (e) { - console.log(e.message); - } - }; + await firestore + .collection(dbPath) + .doc(step_id) + .update({ + [`time`]: step_time, + updatedAt: firestore.FieldValue.serverTimestamp() + }); + + await getCurrentTutorialData(owner, tutorial_id)( + firebase, + firestore, + dispatch + ); + } catch (e) { + console.log(e.message); + } + }; export const setTutorialTheme = ({ tutorial_id, owner, bgColor, textColor }) => - async (firebase, firestore, dispatch) => { - try { - const dbPath = `tutorials`; + async (firebase, firestore, dispatch) => { + try { + const dbPath = `tutorials`; - await firestore.collection(dbPath).doc(tutorial_id).update({ - text_color: textColor, - background_color: bgColor, - updatedAt: firestore.FieldValue.serverTimestamp() - }); + await firestore.collection(dbPath).doc(tutorial_id).update({ + text_color: textColor, + background_color: bgColor, + updatedAt: firestore.FieldValue.serverTimestamp() + }); - await getCurrentTutorialData(owner, tutorial_id)( - firebase, - firestore, - dispatch - ); - } catch (e) { - console.log(e.message); - } - }; + await getCurrentTutorialData(owner, tutorial_id)( + firebase, + firestore, + dispatch + ); + } catch (e) { + console.log(e.message); + } + };