import * as api from "@/utils/api"; /** * Adds a quick accept all friend requests button & a decline all friend requests button to the top of the /my/friends/ page grid. */ export function actions() { const container = document.getElementById("friends-container")!; const actionBtns = document.createElement("div"); actionBtns.classList.add("row", "mb-3"); actionBtns.innerHTML = `
`; const acceptAll: HTMLButtonElement = actionBtns.querySelector( ".btn-success", )!; const declineAll: HTMLButtonElement = actionBtns.querySelector( ".btn-danger", )!; const firstPage = Array.from(container.getElementsByTagName("a")) .map((link) => link.getAttribute("href")?.split("/")[2]); const setDisabled = function (value: boolean) { acceptAll.disabled = value; declineAll.disabled = value; }; if (firstPage.length == 0) { setDisabled(true); } else { acceptAll.addEventListener("click", async () => { setDisabled(true); const ids = await api.iterate( "internal", "friends/requests?page=", null, 1, ); const payloads = ids.map((request: any) => ({ method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ userID: request.senderID, }), })); api.batchAction("friends/send", payloads); }); declineAll.addEventListener("click", async () => { setDisabled(true); const ids = await api.iterate( "internal", "friends/requests?page=", null, 1, ); const payloads = ids.map((request: any) => ({ method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ userID: request.senderID, }), })); api.batchAction("friends/remove", payloads); }); } container.parentElement!.insertBefore(actionBtns, container); } export function checkboxes() {}