diff --git a/assets/js/index.tsx b/assets/js/index.tsx index 44ade17..088485e 100644 --- a/assets/js/index.tsx +++ b/assets/js/index.tsx @@ -55,8 +55,20 @@ const AuthCtx = createContext({ email: "", userId: "" }); // ── Helpers ──────────────────────────────────────────────────────────────────── -function timeAgo(): string { - return "just now"; +function timeAgo(insertedAt?: string | null): string { + if (!insertedAt) return "just now"; + const now = Date.now(); + const then = new Date(insertedAt).getTime(); + const diffSec = Math.floor((now - then) / 1000); + if (diffSec < 5) return "just now"; + if (diffSec < 60) return `${diffSec}s`; + const diffMin = Math.floor(diffSec / 60); + if (diffMin < 60) return `${diffMin}m`; + const diffHr = Math.floor(diffMin / 60); + if (diffHr < 24) return `${diffHr}h`; + const diffDay = Math.floor(diffHr / 24); + if (diffDay < 7) return `${diffDay}d`; + return new Date(insertedAt).toLocaleDateString(undefined, { month: "short", day: "numeric" }); } function getAssetHost(): string { @@ -501,7 +513,7 @@ function TweetCard({ tweet }: { tweet: Tweet }) {
{tweet.userEmail ?? "@mixer"} · - {timeAgo()} + {timeAgo(tweet.insertedAt)} {canModify && (