Skip to content

Commit

Permalink
Merge pull request #977 from Doraemon012/code_i1
Browse files Browse the repository at this point in the history
fix: Removed the step data from firestore after deleting
  • Loading branch information
shivareddy6 authored Jan 6, 2024
2 parents 1650919 + 52e733e commit 3b0952c
Showing 1 changed file with 147 additions and 150 deletions.
297 changes: 147 additions & 150 deletions src/store/actions/tutorialsActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <b>${title}</b> 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 <b>${title}</b> 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 });
Expand Down Expand Up @@ -305,81 +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)
.update({
deleted: true,
updatedAt: firestore.FieldValue.serverTimestamp()
});

// 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 });
Expand Down Expand Up @@ -468,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 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);
}
};
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);
}
};

0 comments on commit 3b0952c

Please sign in to comment.