mirasim's picture
Add the tasks, judges, harness, app under test, docs and report; merge the repository README into the card (part 5)
3eb5a0c verified
Raw History Blame Contribute Delete
1.38 kB
import type { Priority, SortKey, StatusFilter, Task, TaskStatus } from "../types";
const PRIORITY_RANK: Record<Priority, number> = { high: 0, medium: 1, low: 2 };
export function matchesFilter(task: Task, filter: StatusFilter): boolean {
if (filter === "active") return task.status !== "done";
if (filter === "done") return task.status === "done";
return true;
}
export function countByFilter(tasks: Task[]): Record<StatusFilter, number> {
return {
all: tasks.length,
active: tasks.filter((t) => t.status !== "done").length,
done: tasks.filter((t) => t.status === "done").length,
};
}
export function sortTasks(tasks: Task[], key: SortKey): Task[] {
const out = [...tasks];
switch (key) {
case "newest":
return out.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
case "oldest":
return out.sort((a, b) => a.createdAt.localeCompare(b.createdAt));
case "priority":
return out.sort((a, b) => PRIORITY_RANK[a.priority] - PRIORITY_RANK[b.priority]);
case "title":
return out.sort((a, b) => a.title.localeCompare(b.title));
}
}
export const SORT_LABELS: Record<SortKey, string> = {
newest: "Newest first",
oldest: "Oldest first",
priority: "Priority",
title: "Title",
};
export const STATUS_LABELS: Record<TaskStatus, string> = {
todo: "To do",
in_progress: "In progress",
done: "Done",
};