No posts yet. Be the first.
'; return; }
host.innerHTML = j.items.map(p => {
const mine = p.reactions || {};
const btn = (kind, label) =>
`
${initials(p.authorName)}
${escapeHtml(p.authorName)}
${ago(p.createdAt)}
${escapeHtml(p.text)}
${btn("like","👍")} ${btn("fire","🔥")} ${btn("laugh","😂")} ${btn("wow","😮")}
`;
}).join("");
host.querySelectorAll("button.react").forEach(b => {
b.onclick = () => react(b.dataset.post, b.dataset.kind);
});
} catch { host.innerHTML = 'Could not load the timeline.
'; }
}
function escapeHtml(s) {
return String(s == null ? "" : s).replace(/[&<>"']/g, c =>
({ "&":"&", "<":"<", ">":">", '"':""", "'":"'" }[c]));
}
async function react(postId, kind) {
try {
const r = await fetch(`${API}/api/mob/react`, {
method:"POST", headers:{"content-type":"application/json"},
body: JSON.stringify({ id: ME, postId, kind })
});
if (r.status === 429) return toast("Slow down a moment.");
await loadFeed();
} catch { toast("Could not react."); }
}
document.getElementById("text").addEventListener("input", e => {
document.getElementById("charcount").textContent = e.target.value.length + " / 600";
});
document.getElementById("saveProfile").onclick = async () => {
const body = { id: ME,
displayName: document.getElementById("name").value.trim(),
bio: document.getElementById("bio").value.trim() };
try {
const r = await fetch(`${API}/api/mob/profile`, {
method:"POST", headers:{"content-type":"application/json"}, body: JSON.stringify(body) });
const j = await r.json();
if (j.ok) { document.getElementById("whoami").textContent = j.profile.displayName; toast("Profile saved"); }
else toast(j.error || "Could not save.");
} catch { toast("Could not save."); }
};
document.getElementById("post").onclick = async () => {
const el = document.getElementById("text");
const text = el.value.trim();
if (!text) return toast("Write something first.");
const btn = document.getElementById("post");
btn.disabled = true;
try {
const r = await fetch(`${API}/api/mob/post`, {
method:"POST", headers:{"content-type":"application/json"},
body: JSON.stringify({ id: ME, text })
});
if (r.status === 429) { toast("Give it a moment before posting again."); return; }
const j = await r.json();
if (j.ok) { el.value = ""; document.getElementById("charcount").textContent = "0 / 600"; toast("Posted"); await loadFeed(); }
else toast(j.error || "Could not post.");
} catch { toast("Could not post."); }
finally { btn.disabled = false; }
};
loadProfile();
loadFeed();
setInterval(loadFeed, 15000);