Show each clip's length as a m:ss badge

Angular · Angular · intermediate · modification

Adds a duration badge to ClipCard: a computed derives a compact m:ss label from the clip and renders it next to the title. Reads durationMs straight off the existing Clip model so the badge and the player can never disagree about a clip's length.

The m:ss badge is the only length shown in the library grid — it's how a viewer decides whether a clip is a 40-second teaser or a 40-minute talk before pressing play.

Requirements

Files touched

--- src/app/library/clip-card.component.ts
-import { Component, input } from '@angular/core';
+import { Component, computed, input } from '@angular/core';
 
 /** A clip in the media library. */
     <article class="clip-card">
       <h3 class="clip-card__title">{{ clip().title }}</h3>
+      <span class="clip-card__duration">{{ durationLabel() }}</span>
     </article>
   `,
 export class ClipCard {
   readonly clip = input.required<Clip>();
+
+  /** The clip's length as a compact m:ss badge, e.g. "3:45". */
+  readonly durationLabel = computed(() => {
+    const totalSeconds = Math.floor(this.clip().durationMs);
+    const minutes = Math.floor(totalSeconds / 60);
+    const seconds = totalSeconds % 60;
+    return `${minutes}:${seconds.toString().padStart(2, '0')}`;
+  });
 }
 

Review this PR

Angular practice