Compare commits

..

2 commits

Author SHA1 Message Date
0462b5a50b Merge pull request 'fix: sort completed main tasks to bottom of list (#15)' (#18) from fix/simpl-liste-15-sort-completed-tasks into master 2026-03-08 15:26:01 +00:00
2d9440b05c 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>
2026-03-08 11:04:32 -04:00
2 changed files with 9 additions and 8 deletions

View file

@ -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) {

View file

@ -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;
}
}