- Added Daily repeat type for the todos and implemented creating and updating this kinds of todos

This commit is contained in:
Dejan
2024-11-10 18:00:17 +01:00
parent 7da8005fb1
commit 5b80a3ba80
4 changed files with 32 additions and 6 deletions
+1
View File
@@ -26,6 +26,7 @@ export const DAYS_OF_WEEK_ENUM = {
export const REPEAT_TYPE = {
NONE: "None",
DAILY: "Daily",
EVERY_WEEK: "Every week",
ONCE_A_MONTH: "Once a month",
ONCE_A_YEAR: "Once a year"
+13 -1
View File
@@ -40,7 +40,19 @@ export const useCreateTodo = () => {
const batch = firestore().batch();
if (todoData.repeatType === REPEAT_TYPE.EVERY_WEEK) {
if (todoData.repeatType === REPEAT_TYPE.DAILY) {
// for the next 52 weeks
for (let i = 1; i < 52; i++) {
let date = originalTodo.date;
const nextWeek = addWeeks(date, i);
let docRef = firestore().collection("Todos").doc();
let newTodo = { ...originalTodo, id: docRef.id, date: nextWeek, connectedTodoId: newDoc.id };
newTodo = resolveTodoAlternatingAssignees(todoData, newTodo, i);
batch.set(docRef, newTodo);
}
} else if (todoData.repeatType === REPEAT_TYPE.EVERY_WEEK) {
let date = originalTodo.date;
let repeatDays = originalTodo.repeatDays;
+12
View File
@@ -51,6 +51,18 @@ export const useUpdateTodo = () => {
const newDoc = firestore().collection('Todos').doc();
let originalTodo = {...todoData, id: newDoc.id, familyId: profileData?.familyId, creatorId: currentUser?.uid}
batch.set(newDoc, originalTodo);
} else if (todoData.repeatType === REPEAT_TYPE.DAILY) {
console.log("DAILY");
// for the next 52 weeks
for (let i = 0; i < 52; i++) {
let date = todoData?.date;
const nextWeek = addWeeks(date, i);
let docRef = firestore().collection("Todos").doc();
let newTodo = { ...todoData, id: docRef.id, date: nextWeek, connectedTodoId: firstTodo?.connectedTodoId };
newTodo = resolveTodoAlternatingAssignees(todoData, newTodo, i);
batch.set(docRef, newTodo);
}
} else if (todoData.repeatType === REPEAT_TYPE.EVERY_WEEK) {
console.log("EVERY WEEK");