Sort completed main tasks to the bottom of the list
Add asc(tasks.completed) as the primary sort key in getOrderClauses() so completed tasks always appear after active ones regardless of the chosen sort mode (position, priority, dueDate, title, createdAt). Also apply the same completed-first ordering to: - getSubtasks() in tasks.ts - noDateTasks query in widgetSync.ts - subtasks query in widgetSync.ts Ref: simpl-liste#15 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
fa037e9eef
commit
2d9440b05c
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