- Improved the todo update

This commit is contained in:
Dejan
2024-12-22 16:35:31 +01:00
parent b7fd8daddf
commit 4866dd1b3f
2 changed files with 98 additions and 190 deletions

View File

@ -14,14 +14,19 @@ export const daysOfWeek = [
DAYS_OF_WEEK_ENUM.SATURDAY,
DAYS_OF_WEEK_ENUM.SUNDAY];
export const getNextDailyDates = (date) => {
export const getNextDailyDates = (date, includeToday) => {
const today = new Date();
const dates = [];
for (let weekOffset = 0; weekOffset < 52; weekOffset++) {
const targetDate = addWeeks(date, weekOffset);
if (targetDate > today) {
if (includeToday) {
dates.push(targetDate);
} else {
if (targetDate > today) {
dates.push(targetDate);
}
}
}
@ -46,28 +51,36 @@ export const getNextWeeklyDates = (selectedDays, date) => {
return dates;
};
export const getNextMonthlyDates = (date) => {
export const getNextMonthlyDates = (date, includeToday) => {
const today = new Date();
const dates = [];
for (let monthOffset = 0; monthOffset < 12; monthOffset++) {
const targetDate = addMonths(date, monthOffset);
if (targetDate > today) {
if (includeToday) {
dates.push(targetDate);
} else {
if (targetDate > today) {
dates.push(targetDate);
}
}
}
return dates;
};
export const getNextYearlyDates = (date) => {
export const getNextYearlyDates = (date, includeToday) => {
const today = new Date();
const dates = [];
for (let yearOffset = 0; yearOffset < 5; yearOffset++) {
const nextYear = addYears(date, yearOffset);
if (nextYear > today) {
if (includeToday) {
dates.push(nextYear);
} else {
if (nextYear > today) {
dates.push(nextYear);
}
}
}
@ -92,13 +105,13 @@ export const useCreateTodo = () => {
let nextDates;
if (todoData.repeatType === REPEAT_TYPE.DAILY) {
nextDates = getNextDailyDates(todoData.date);
nextDates = getNextDailyDates(todoData.date, false);
} else if (todoData.repeatType === REPEAT_TYPE.EVERY_WEEK) {
nextDates = getNextWeeklyDates(todoData.repeatDays, todoData.date);
} else if (todoData.repeatType === REPEAT_TYPE.ONCE_A_MONTH) {
nextDates = getNextMonthlyDates(todoData.date);
nextDates = getNextMonthlyDates(todoData.date, false);
} else if (todoData.repeatType === REPEAT_TYPE.ONCE_A_YEAR) {
nextDates = getNextYearlyDates(todoData.date);
nextDates = getNextYearlyDates(todoData.date, false);
}
const todosRef = firestore().collection("Todos");