mirror of
https://github.com/urosran/cally.git
synced 2025-11-26 16:34:54 +00:00
todo filtering, nanny shopping
This commit is contained in:
@ -17,7 +17,12 @@ const FILTER_OPTIONS = {
|
||||
};
|
||||
|
||||
const groupToDosByDate = (toDos: IToDo[]) => {
|
||||
let sortedTodos = toDos.sort((a, b) => a.date - b.date);
|
||||
let sortedTodos = toDos.sort((a, b) => {
|
||||
const dateA = a.date === null ? new Date() : a.date;
|
||||
const dateB = b.date === null ? new Date() : b.date;
|
||||
return dateA - dateB;
|
||||
});
|
||||
|
||||
return sortedTodos.reduce(
|
||||
(groups, toDo) => {
|
||||
let dateKey;
|
||||
@ -36,9 +41,15 @@ const groupToDosByDate = (toDos: IToDo[]) => {
|
||||
});
|
||||
};
|
||||
|
||||
if (toDo.date === null) {
|
||||
dateKey = "No Date";
|
||||
} else if (isToday(toDo.date)) {
|
||||
const isOverdue = (date: Date) => {
|
||||
const today = new Date();
|
||||
today.setHours(0, 0, 0, 0);
|
||||
return date < today;
|
||||
};
|
||||
|
||||
if (isOverdue(toDo.date) && !toDo.done) {
|
||||
dateKey = "Overdue";
|
||||
} else if (toDo.date === null || isToday(toDo.date)) {
|
||||
dateKey = "Today";
|
||||
} else if (isTomorrow(toDo.date)) {
|
||||
dateKey = "Tomorrow";
|
||||
@ -48,7 +59,8 @@ const groupToDosByDate = (toDos: IToDo[]) => {
|
||||
dateKey = "Next 30 Days";
|
||||
subDateKey = format(toDo.date, "MMM d");
|
||||
} else {
|
||||
return groups;
|
||||
dateKey = "Later";
|
||||
subDateKey = format(toDo.date, "MMM d, yyyy");
|
||||
}
|
||||
|
||||
if (!groups[dateKey]) {
|
||||
@ -58,7 +70,7 @@ const groupToDosByDate = (toDos: IToDo[]) => {
|
||||
};
|
||||
}
|
||||
|
||||
if (dateKey === "Next 30 Days" && subDateKey) {
|
||||
if ((dateKey === "Next 30 Days" || dateKey === "Later") && subDateKey) {
|
||||
if (!groups[dateKey].subgroups[subDateKey]) {
|
||||
groups[dateKey].subgroups[subDateKey] = [];
|
||||
}
|
||||
@ -138,14 +150,17 @@ const ToDosList = ({ isSettings }: { isSettings?: boolean }) => {
|
||||
};
|
||||
|
||||
const noDateToDos = groupedToDos["No Date"]?.items || [];
|
||||
const datedToDos = Object.keys(groupedToDos).filter(
|
||||
(key) => key !== "No Date"
|
||||
);
|
||||
const datedToDos = Object.keys(groupedToDos)
|
||||
.filter((key) => key !== "No Date")
|
||||
.sort((a, b) => {
|
||||
const order = ["Overdue", "Today", "Tomorrow", "Next 7 Days", "Next 30 Days", "Later"];
|
||||
return order.indexOf(a) - order.indexOf(b);
|
||||
});
|
||||
|
||||
const renderTodoGroup = (dateKey: string) => {
|
||||
const isExpanded = expandedGroups[dateKey] || false;
|
||||
|
||||
if (dateKey === "Next 30 Days") {
|
||||
if (dateKey === "Next 30 Days" || dateKey === "Later") {
|
||||
const subgroups = Object.entries(groupedToDos[dateKey].subgroups).sort(
|
||||
([dateA], [dateB]) => {
|
||||
const dateAObj = new Date(dateA);
|
||||
|
||||
Reference in New Issue
Block a user