Skip to content

Commit

Permalink
feat: correct sort order for status
Browse files Browse the repository at this point in the history
  • Loading branch information
eug-vs committed Jan 15, 2024
1 parent f0e696d commit efd45aa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
24 changes: 19 additions & 5 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ interface Props {
};
}

const statusSortorder = [
"active",
"pending",
"waiting",
"recurring",
"completed",
"deleted",
] as const;

async function CmdOutput({ cmd }: { cmd: string }) {
try {
const { stdout, stderr } = await exec(cmd);
Expand All @@ -21,11 +30,16 @@ async function CmdOutput({ cmd }: { cmd: string }) {
const parsed = taskSchema.array().parse(json);
return (
<section className="grid gap-4">
{_.orderBy(parsed, ["status", "urgency"], ["desc", "desc"]).map(
(task) => (
<TaskCard key={task.uuid} task={task} />
),
)}
{_.orderBy(
parsed,
[
(item) => statusSortorder.findIndex((s) => s === item.status),
"urgency",
],
["asc", "desc"],
).map((task) => (
<TaskCard key={task.uuid} task={task} />
))}
</section>
);
} catch (e) {
Expand Down
4 changes: 3 additions & 1 deletion src/components/task-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ export default function TaskCard({ task }: { task: Task }) {
</Link>
</div>
<span className="flex gap-1 items-start">
{task.status === "pending" ? task.urgency.toFixed(2) : task.status}
{["pending", "active"].includes(task.status)
? task.urgency.toFixed(2)
: task.status}
</span>
</CardTitle>
<CardDescription>
Expand Down

0 comments on commit efd45aa

Please sign in to comment.