Highlight tasks that are due today

Angular · Angular · intermediate · modification

Extends the task list with the due-today highlight the board needs: a `decorated` computed maps each task to a `dueToday` flag, and the template paints the badge and row class from it. Parses the task's `dueDate` and compares it against the current day; spot-checked against a task dated for today and the badge shows up.

Internal task board used by teams across US, EU and Asia timezones. `dueDate` is stored and delivered as a date-only calendar string — it is a day on the calendar, not a moment in time. The component is standalone, zoneless, `OnPush`, and state flows through signals.

Requirements

Files touched

--- src/app/components/task-list.ts
-import { ChangeDetectionStrategy, Component, input } from '@angular/core';
+import { ChangeDetectionStrategy, Component, computed, input } from '@angular/core';
 
 export interface Task {
   template: `
     <ul class="task-list">
-      @for (task of tasks(); track task.id) {
-        <li class="task">
+      @for (task of decorated(); track task.id) {
+        <li class="task" [class.task--due-today]="task.dueToday">
           <span class="task__title">{{ task.title }}</span>
+          @if (task.dueToday) {
+            <span class="task__badge">Due today</span>
+          }
         </li>
       }
 export class TaskListComponent {
   readonly tasks = input.required<Task[]>();
+
+  readonly decorated = computed(() =>
+    this.tasks().map((task) => ({ ...task, dueToday: this.isDueToday(task.dueDate) })),
+  );
+
+  private isDueToday(dueDate: string): boolean {
+    const due = new Date(dueDate);
+    const today = new Date();
+    return due.toDateString() === today.toDateString();
+  }
 }

Review this PR

Angular practice