Open source CapCut alternative.
TypeScript
refactor(site): one date reading for every shelf
David Le955631f45951
diff --git a/site/src/cut/components/ProjectsHome.tsx b/site/src/cut/components/ProjectsHome.tsxindex 2351ed1a..c80230aa 100644--- a/site/src/cut/components/ProjectsHome.tsx+++ b/site/src/cut/components/ProjectsHome.tsx@@ -80,7 +80,7 @@ import { createProjectFromFile, isMediaFile } from "@/cut/lib/media";import { dropLocalProjectCopy, localMediaUrl } from "@/cut/lib/mediaSync";import { copyProjectAcross } from "@/cut/lib/projectCopy";import { homeHref, projectHref, useCutBase } from "@/cut/lib/nav";-import { daysUntil, formatTime } from "@/cut/lib/time";+import { daysUntil, formatDate, formatTime } from "@/cut/lib/time";import {parseRatio,shapeBand,@@ -115,20 +115,6 @@ type SectionData = {// move a whole marquee-selected collection into a folder.const PROJECT_MIME = "application/x-cut-project";-function formatDate(ts: number) {- const d = new Date(ts);- const now = Date.now();- const mins = Math.floor((now - ts) / 60000);- if (mins < 1) return "just now";- if (mins < 60) return `${mins}m ago`;- if (mins < 60 * 24) return `${Math.floor(mins / 60)}h ago`;- return d.toLocaleDateString(undefined, {- month: "short",- day: "numeric",- ...(d.getFullYear() !== new Date().getFullYear() ? { year: "numeric" } : {}),- });-}-// The badge marks where one project lives, so it says that outright rather// than repeating the shelf heading it sits under. A local project the Donkey// app isn't answering for says that instead: it is the reason its card can'tdiff --git a/site/src/cut/lib/time.ts b/site/src/cut/lib/time.tsindex f304819d..698181ed 100644--- a/site/src/cut/lib/time.ts+++ b/site/src/cut/lib/time.ts@@ -4,6 +4,21 @@ export function daysUntil(iso: string): number {return Math.max(0, Math.floor((new Date(iso).getTime() - Date.now()) / 86_400_000));}+/** A moment as a shelf reads it: minutes and hours while it is recent, then+ * the calendar date, with the year only once it is not this one. */+export function formatDate(ts: number) {+ const d = new Date(ts);+ const mins = Math.floor((Date.now() - ts) / 60000);+ if (mins < 1) return "just now";+ if (mins < 60) return `${mins}m ago`;+ if (mins < 60 * 24) return `${Math.floor(mins / 60)}h ago`;+ return d.toLocaleDateString(undefined, {+ month: "short",+ day: "numeric",+ ...(d.getFullYear() !== new Date().getFullYear() ? { year: "numeric" } : {}),+ });+}+/** Elapsed wall-clock as "m:ss" — 63400ms -> "1:03". */export function formatElapsed(ms: number) {const t = Math.max(0, Math.floor(ms / 1000));