chore: code refactor
This commit is contained in:
@@ -88,6 +88,8 @@ export type Post = {
|
||||
/** The post's pinned comment, if any — hydrated so the card footer can show
|
||||
* it without a separate fetch. Null/absent when nothing is pinned. */
|
||||
pinned_comment?: Comment | null;
|
||||
/** Total comments + replies on the post (drives the footer comment count). */
|
||||
comments_count?: number;
|
||||
};
|
||||
|
||||
/** A comment or reply on a post. Threading is one level deep: `parent_id` is
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Compact relative time ("just now", "5m ago", "3h ago", "2d ago"), falling
|
||||
* back to a locale date for anything older than a week. Shared across the
|
||||
* notification feed, the comments drawer, and anywhere else that shows a
|
||||
* timestamp tail.
|
||||
*/
|
||||
export function timeAgo(iso: string): string {
|
||||
const then = new Date(iso).getTime();
|
||||
if (Number.isNaN(then)) return "";
|
||||
const secs = Math.max(0, Math.floor((Date.now() - then) / 1000));
|
||||
if (secs < 45) return "just now";
|
||||
const mins = Math.floor(secs / 60);
|
||||
if (mins < 60) return `${mins}m ago`;
|
||||
const hours = Math.floor(mins / 60);
|
||||
if (hours < 24) return `${hours}h ago`;
|
||||
const days = Math.floor(hours / 24);
|
||||
if (days < 7) return `${days}d ago`;
|
||||
return new Date(iso).toLocaleDateString();
|
||||
}
|
||||
Reference in New Issue
Block a user