fix: sort completed main tasks to bottom of list (#15) #18
2 changed files with 9 additions and 8 deletions
|
|
@ -85,18 +85,19 @@ export async function getTasksByList(listId: string, filters?: TaskFilters) {
|
|||
|
||||
function getOrderClauses(sortBy: SortBy, sortOrder: SortOrder) {
|
||||
const dir = sortOrder === 'asc' ? asc : desc;
|
||||
// Always sort completed tasks to the bottom, then apply the requested sort
|
||||
switch (sortBy) {
|
||||
case 'priority':
|
||||
return [dir(tasks.priority), asc(tasks.position)];
|
||||
return [asc(tasks.completed), dir(tasks.priority), asc(tasks.position)];
|
||||
case 'dueDate':
|
||||
return [dir(tasks.dueDate), asc(tasks.position)];
|
||||
return [asc(tasks.completed), dir(tasks.dueDate), asc(tasks.position)];
|
||||
case 'title':
|
||||
return [dir(tasks.title)];
|
||||
return [asc(tasks.completed), dir(tasks.title)];
|
||||
case 'createdAt':
|
||||
return [dir(tasks.createdAt)];
|
||||
return [asc(tasks.completed), dir(tasks.createdAt)];
|
||||
case 'position':
|
||||
default:
|
||||
return [asc(tasks.position), desc(tasks.createdAt)];
|
||||
return [asc(tasks.completed), asc(tasks.position), desc(tasks.createdAt)];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -105,7 +106,7 @@ export async function getSubtasks(parentId: string) {
|
|||
.select()
|
||||
.from(tasks)
|
||||
.where(eq(tasks.parentId, parentId))
|
||||
.orderBy(asc(tasks.position));
|
||||
.orderBy(asc(tasks.completed), asc(tasks.position));
|
||||
}
|
||||
|
||||
export async function getTaskById(id: string) {
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ export async function syncWidgetData(): Promise<void> {
|
|||
isNull(tasks.dueDate)
|
||||
)
|
||||
)
|
||||
.orderBy(asc(tasks.position));
|
||||
.orderBy(asc(tasks.completed), asc(tasks.position));
|
||||
|
||||
const toWidgetTask = (t: typeof upcomingTasks[number]): WidgetTask => ({
|
||||
id: t.id,
|
||||
|
|
@ -117,7 +117,7 @@ export async function syncWidgetData(): Promise<void> {
|
|||
.select({ id: tasks.id, title: tasks.title, completed: tasks.completed })
|
||||
.from(tasks)
|
||||
.where(eq(tasks.parentId, task.id))
|
||||
.orderBy(asc(tasks.position));
|
||||
.orderBy(asc(tasks.completed), asc(tasks.position));
|
||||
task.subtasks = subs;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue