// @ts-ignore globalThis.onReply = (id: string) => { location.href = `/admin/q+a/${id}?return=inbox`; }; // @ts-ignore globalThis.onDelete = async (id: string) => { const div = document.querySelector(`[data-q="${id}"]`) as HTMLDivElement; if (!div) return alert("Question not found"); // Pending State div.style.opacity = "0.5"; div.style.pointerEvents = "none"; div?.querySelectorAll("button").forEach((b) => { b.disabled = true; }); try { const resp = await fetch(`/admin/q+a/${id}`, { method: "DELETE", headers: { Accept: "application/json", }, }); if (resp.status !== 200) { throw new Error("Failed to delete question, status: " + resp.status); } } catch (e: any) { div.style.opacity = "1"; div.style.pointerEvents = "auto"; div?.querySelectorAll("button").forEach((b) => { b.disabled = false; }); return alert(e.message); } div.remove(); }; // @ts-ignore globalThis.onDeleteFull = async (id: string) => { const div = document.querySelector(`[data-q="${id}"]`) as HTMLDivElement; if (!div) return alert("Question not found"); // Confirmation if (!confirm("Are you sure you want to delete this question?")) return; // Pending State div.style.opacity = "0.5"; div.style.pointerEvents = "none"; div?.querySelectorAll("button").forEach((b) => { b.disabled = true; }); try { const resp = await fetch(`/admin/q+a/${id}`, { method: "DELETE", headers: { Accept: "application/json", "X-Delete-Full": "true", }, }); if (resp.status !== 200) { throw new Error("Failed to delete question, status: " + resp.status); } } catch (e: any) { div.style.opacity = "1"; div.style.pointerEvents = "auto"; div?.querySelectorAll("button").forEach((b) => { b.disabled = false; }); return alert(e.message); } div.remove(); };