chore: code refactor

This commit is contained in:
gosangam
2026-06-13 02:24:42 +05:30
parent cc5633c37a
commit 439664a97d
151 changed files with 1387 additions and 1138 deletions
+2
View File
@@ -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
View File
@@ -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();
}