mirror of
https://github.com/urosran/cally.git
synced 2025-07-10 15:17:17 +00:00
- Take turns implementation for the todos
This commit is contained in:
@ -31,6 +31,9 @@ export const useCreateTodo = () => {
|
||||
// Create the one original to do
|
||||
const newDoc = firestore().collection('Todos').doc();
|
||||
let originalTodo = {...todoData, id: newDoc.id, familyId: profileData?.familyId, creatorId: currentUser?.uid, connectedTodoId: newDoc.id};
|
||||
|
||||
originalTodo = resolveTodoAlternatingAssignees(todoData, originalTodo, 0);
|
||||
|
||||
await firestore()
|
||||
.collection("Todos")
|
||||
.add(originalTodo);
|
||||
@ -59,13 +62,17 @@ export const useCreateTodo = () => {
|
||||
});
|
||||
|
||||
// TODO: for the next 52 weeks
|
||||
let index = 1;
|
||||
for (let i = 0; i < 4; i++) {
|
||||
dates?.forEach((dateToAdd) => {
|
||||
index ++;
|
||||
let newTodoDate = addWeeks(dateToAdd, i);
|
||||
if (compareAsc(newTodoDate, originalTodo.date) !== 0) {
|
||||
|
||||
let docRef = firestore().collection("Todos").doc();
|
||||
const newTodo = { ...originalTodo, id: docRef.id, date: newTodoDate, connectedTodoId: newDoc.id };
|
||||
let newTodo = { ...originalTodo, id: docRef.id, date: newTodoDate, connectedTodoId: newDoc.id };
|
||||
newTodo = resolveTodoAlternatingAssignees(todoData, newTodo, index);
|
||||
|
||||
batch.set(docRef, newTodo);
|
||||
}
|
||||
})
|
||||
@ -78,7 +85,9 @@ export const useCreateTodo = () => {
|
||||
const nextMonth = addMonths(date, i);
|
||||
|
||||
let docRef = firestore().collection("Todos").doc();
|
||||
const newTodo = { ...originalTodo, id: docRef.id, date: nextMonth, connectedTodoId: newDoc.id };
|
||||
let newTodo = { ...originalTodo, id: docRef.id, date: nextMonth, connectedTodoId: newDoc.id };
|
||||
newTodo = resolveTodoAlternatingAssignees(todoData, newTodo, i);
|
||||
|
||||
batch.set(docRef, newTodo);
|
||||
}
|
||||
} else if (todoData.repeatType === REPEAT_TYPE.ONCE_A_YEAR) {
|
||||
@ -89,7 +98,9 @@ export const useCreateTodo = () => {
|
||||
const nextMonth = addYears(date, i);
|
||||
|
||||
let docRef = firestore().collection("Todos").doc();
|
||||
const newTodo = { ...originalTodo, id: docRef.id, date: nextMonth, connectedTodoId: newDoc.id };
|
||||
let newTodo = { ...originalTodo, id: docRef.id, date: nextMonth, connectedTodoId: newDoc.id };
|
||||
newTodo = resolveTodoAlternatingAssignees(todoData, newTodo, i);
|
||||
|
||||
batch.set(docRef, newTodo);
|
||||
}
|
||||
}
|
||||
@ -104,4 +115,15 @@ export const useCreateTodo = () => {
|
||||
queryClients.invalidateQueries("todos")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const resolveTodoAlternatingAssignees = (todoData, newTodo, i) => {
|
||||
if (todoData.assignees && todoData.rotate && todoData?.assignees?.length !== 0) {
|
||||
const assignees = todoData.assignees;
|
||||
const assignee = assignees[i % assignees.length];
|
||||
|
||||
newTodo = {...newTodo, assignees: [assignee]};
|
||||
}
|
||||
|
||||
return newTodo;
|
||||
}
|
Reference in New Issue
Block a user