claude refactor of index.tsx so its humanly editable
This commit is contained in:
32
assets/js/utils.ts
Normal file
32
assets/js/utils.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
export 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" });
|
||||
}
|
||||
|
||||
export function getAssetHost(): string {
|
||||
const appEl = document.getElementById("app");
|
||||
return appEl?.dataset.assetHost ?? "http://localhost:9000";
|
||||
}
|
||||
|
||||
export function userDisplayLabel(u: {
|
||||
displayName?: string | null;
|
||||
username?: string | null;
|
||||
email?: string | null;
|
||||
}): string {
|
||||
return u.displayName || u.username || u.email || "@mixer";
|
||||
}
|
||||
|
||||
export function userHandle(u: { username?: string | null; email?: string | null }): string {
|
||||
return u.username ? `@${u.username}` : u.email ?? "@mixer";
|
||||
}
|
||||
Reference in New Issue
Block a user