Skip to content

Commit 3b0952c

Browse files
authored
Merge pull request #977 from Doraemon012/code_i1
fix: Removed the step data from firestore after deleting
2 parents 1650919 + 52e733e commit 3b0952c

File tree

1 file changed

+147
-150
lines changed

1 file changed

+147
-150
lines changed

Diff for: src/store/actions/tutorialsActions.js

+147-150
Original file line numberDiff line numberDiff line change
@@ -230,36 +230,36 @@ export const getCurrentTutorialData =
230230

231231
export const addNewTutorialStep =
232232
({ owner, tutorial_id, title, time, id }) =>
233-
async (firebase, firestore, dispatch) => {
234-
try {
235-
dispatch({ type: actions.CREATE_TUTORIAL_STEP_START });
233+
async (firebase, firestore, dispatch) => {
234+
try {
235+
dispatch({ type: actions.CREATE_TUTORIAL_STEP_START });
236236

237-
await firestore
238-
.collection("tutorials")
239-
.doc(tutorial_id)
240-
.collection("steps")
241-
.doc(id)
242-
.set({
243-
content: `Switch to editor mode to begin <b>${title}</b> step`,
244-
id,
245-
time,
246-
title,
247-
visibility: true,
248-
deleted: false
249-
});
237+
await firestore
238+
.collection("tutorials")
239+
.doc(tutorial_id)
240+
.collection("steps")
241+
.doc(id)
242+
.set({
243+
content: `Switch to editor mode to begin <b>${title}</b> step`,
244+
id,
245+
time,
246+
title,
247+
visibility: true,
248+
deleted: false
249+
});
250250

251-
await getCurrentTutorialData(owner, tutorial_id)(
252-
firebase,
253-
firestore,
254-
dispatch
255-
);
251+
await getCurrentTutorialData(owner, tutorial_id)(
252+
firebase,
253+
firestore,
254+
dispatch
255+
);
256256

257-
dispatch({ type: actions.CREATE_TUTORIAL_STEP_SUCCESS });
258-
} catch (e) {
259-
console.log("CREATE_TUTORIAL_STEP_FAIL", e.message);
260-
dispatch({ type: actions.CREATE_TUTORIAL_STEP_FAIL, payload: e.message });
261-
}
262-
};
257+
dispatch({ type: actions.CREATE_TUTORIAL_STEP_SUCCESS });
258+
} catch (e) {
259+
console.log("CREATE_TUTORIAL_STEP_FAIL", e.message);
260+
dispatch({ type: actions.CREATE_TUTORIAL_STEP_FAIL, payload: e.message });
261+
}
262+
};
263263

264264
export const clearCreateTutorials = () => dispatch =>
265265
dispatch({ type: actions.CLEAR_CREATE_TUTORIALS_STATE });
@@ -305,81 +305,78 @@ export const setCurrentStepContent =
305305

306306
export const hideUnHideStep =
307307
(owner, tutorial_id, step_id, visibility) =>
308-
async (firebase, firestore, dispatch) => {
309-
try {
310-
/* not being used */
311-
// const type = await checkUserOrOrgHandle(owner)(firebase);
312-
await firestore
313-
.collection("tutorials")
314-
.doc(tutorial_id)
315-
.collection("steps")
316-
.doc(step_id)
317-
.update({
318-
[`visibility`]: !visibility,
319-
updatedAt: firestore.FieldValue.serverTimestamp()
320-
});
308+
async (firebase, firestore, dispatch) => {
309+
try {
310+
/* not being used */
311+
// const type = await checkUserOrOrgHandle(owner)(firebase);
312+
await firestore
313+
.collection("tutorials")
314+
.doc(tutorial_id)
315+
.collection("steps")
316+
.doc(step_id)
317+
.update({
318+
[`visibility`]: !visibility,
319+
updatedAt: firestore.FieldValue.serverTimestamp()
320+
});
321321

322-
await getCurrentTutorialData(owner, tutorial_id)(
323-
firebase,
324-
firestore,
325-
dispatch
326-
);
327-
} catch (e) {
328-
console.log(e.message);
329-
}
330-
};
322+
await getCurrentTutorialData(owner, tutorial_id)(
323+
firebase,
324+
firestore,
325+
dispatch
326+
);
327+
} catch (e) {
328+
console.log(e.message);
329+
}
330+
};
331331

332332
export const publishUnpublishTutorial =
333333
(owner, tutorial_id, isPublished) =>
334-
async (firebase, firestore, dispatch) => {
335-
try {
336-
await firestore
337-
.collection("tutorials")
338-
.doc(tutorial_id)
339-
.update({
340-
["isPublished"]: !isPublished
341-
});
334+
async (firebase, firestore, dispatch) => {
335+
try {
336+
await firestore
337+
.collection("tutorials")
338+
.doc(tutorial_id)
339+
.update({
340+
["isPublished"]: !isPublished
341+
});
342342

343-
getCurrentTutorialData(owner, tutorial_id)(firebase, firestore, dispatch);
344-
} catch (e) {
345-
console.log(e.message);
346-
}
347-
};
343+
getCurrentTutorialData(owner, tutorial_id)(firebase, firestore, dispatch);
344+
} catch (e) {
345+
console.log(e.message);
346+
}
347+
};
348348

349349
export const removeStep =
350350
(owner, tutorial_id, step_id, current_step_no) =>
351-
async (firebase, firestore, dispatch) => {
352-
try {
353-
await firestore
354-
.collection("tutorials")
355-
.doc(tutorial_id)
356-
.collection("steps")
357-
.doc(step_id)
358-
.update({
359-
deleted: true,
360-
updatedAt: firestore.FieldValue.serverTimestamp()
361-
});
362-
363-
// const data = await firestore
364-
// .collection("tutorials")
365-
// .doc(tutorial_id)
366-
// .collection("steps")
367-
// .doc(step_id)
368-
// .get();
369-
370-
await setCurrentStepNo(
371-
current_step_no > 0 ? current_step_no - 1 : current_step_no
372-
)(dispatch);
373-
374-
await getCurrentTutorialData(owner, tutorial_id)(
375-
firebase,
376-
firestore,
377-
dispatch
378-
);
379-
} catch (e) {
380-
console.log(e.message);
381-
}
382-
};
351+
async (firebase, firestore, dispatch) => {
352+
try {
353+
await firestore
354+
.collection("tutorials")
355+
.doc(tutorial_id)
356+
.collection("steps")
357+
.doc(step_id)
358+
.delete()
359+
360+
// const data = await firestore
361+
// .collection("tutorials")
362+
// .doc(tutorial_id)
363+
// .collection("steps")
364+
// .doc(step_id)
365+
// .get();
366+
367+
await setCurrentStepNo(
368+
current_step_no > 0 ? current_step_no - 1 : current_step_no
369+
)(dispatch);
370+
371+
await getCurrentTutorialData(owner, tutorial_id)(
372+
firebase,
373+
firestore,
374+
dispatch
375+
);
376+
} catch (e) {
377+
console.log(e.message);
378+
}
379+
};
383380

384381
export const setCurrentStep = data => async dispatch =>
385382
dispatch({ type: actions.SET_EDITOR_DATA, payload: data });
@@ -468,69 +465,69 @@ export const remoteTutorialImages =
468465

469466
export const updateStepTitle =
470467
(owner, tutorial_id, step_id, step_title) =>
471-
async (firebase, firestore, dispatch) => {
472-
try {
473-
const dbPath = `tutorials/${tutorial_id}/steps`;
474-
await firestore
475-
.collection(dbPath)
476-
.doc(step_id)
477-
.update({
478-
[`title`]: step_title,
479-
updatedAt: firestore.FieldValue.serverTimestamp()
480-
});
468+
async (firebase, firestore, dispatch) => {
469+
try {
470+
const dbPath = `tutorials/${tutorial_id}/steps`;
471+
await firestore
472+
.collection(dbPath)
473+
.doc(step_id)
474+
.update({
475+
[`title`]: step_title,
476+
updatedAt: firestore.FieldValue.serverTimestamp()
477+
});
481478

482-
await getCurrentTutorialData(owner, tutorial_id)(
483-
firebase,
484-
firestore,
485-
dispatch
486-
);
487-
} catch (e) {
488-
console.log(e);
489-
}
490-
};
479+
await getCurrentTutorialData(owner, tutorial_id)(
480+
firebase,
481+
firestore,
482+
dispatch
483+
);
484+
} catch (e) {
485+
console.log(e);
486+
}
487+
};
491488

492489
export const updateStepTime =
493490
(owner, tutorial_id, step_id, step_time) =>
494-
async (firebase, firestore, dispatch) => {
495-
try {
496-
const dbPath = `tutorials/${tutorial_id}/steps`;
497-
498-
await firestore
499-
.collection(dbPath)
500-
.doc(step_id)
501-
.update({
502-
[`time`]: step_time,
503-
updatedAt: firestore.FieldValue.serverTimestamp()
504-
});
491+
async (firebase, firestore, dispatch) => {
492+
try {
493+
const dbPath = `tutorials/${tutorial_id}/steps`;
494+
495+
await firestore
496+
.collection(dbPath)
497+
.doc(step_id)
498+
.update({
499+
[`time`]: step_time,
500+
updatedAt: firestore.FieldValue.serverTimestamp()
501+
});
505502

506-
await getCurrentTutorialData(owner, tutorial_id)(
507-
firebase,
508-
firestore,
509-
dispatch
510-
);
511-
} catch (e) {
512-
console.log(e.message);
513-
}
514-
};
503+
await getCurrentTutorialData(owner, tutorial_id)(
504+
firebase,
505+
firestore,
506+
dispatch
507+
);
508+
} catch (e) {
509+
console.log(e.message);
510+
}
511+
};
515512

516513
export const setTutorialTheme =
517514
({ tutorial_id, owner, bgColor, textColor }) =>
518-
async (firebase, firestore, dispatch) => {
519-
try {
520-
const dbPath = `tutorials`;
515+
async (firebase, firestore, dispatch) => {
516+
try {
517+
const dbPath = `tutorials`;
521518

522-
await firestore.collection(dbPath).doc(tutorial_id).update({
523-
text_color: textColor,
524-
background_color: bgColor,
525-
updatedAt: firestore.FieldValue.serverTimestamp()
526-
});
519+
await firestore.collection(dbPath).doc(tutorial_id).update({
520+
text_color: textColor,
521+
background_color: bgColor,
522+
updatedAt: firestore.FieldValue.serverTimestamp()
523+
});
527524

528-
await getCurrentTutorialData(owner, tutorial_id)(
529-
firebase,
530-
firestore,
531-
dispatch
532-
);
533-
} catch (e) {
534-
console.log(e.message);
535-
}
536-
};
525+
await getCurrentTutorialData(owner, tutorial_id)(
526+
firebase,
527+
firestore,
528+
dispatch
529+
);
530+
} catch (e) {
531+
console.log(e.message);
532+
}
533+
};

0 commit comments

Comments
 (0)