const formatTimestamp = timestamp => { let d; if (typeof timestamp === "string") { d = new Date(timestamp.replace(" ", "T")); } else { d = new Date(timestamp); } const now = new Date(); // If younger than a year, show time // otherwise show the year return now - d < 31536000000 ? `${d.getDate()} ${d.toLocaleString("en-GB", { month: "short" })}, ${d.getHours().toString().padStart(2, "0")}:${d.getMinutes().toString().padStart(2, "0")}` : `${d.getDate()} ${d.toLocaleString("en-GB", { month: "short" })} ${d.getFullYear()}`; } //#region Table const emptyTableHtml = `

No results found

Create a subscription and it will appear here.

`; var table; const defineTable = () => { table = new HSDataTable("#table", { ajax: { url: `/guild/${guildId}/subscriptions/api/datatable`, dataSrc: "data", data: (d) => { if (d === undefined) { return ;} d.filters = {}; const active = $("input[name='filterActive']:checked").val(); d.filters.active = active; } }, serverSide: true, processing: true, selecting: true, pagingOptions: { pageBtnClasses: "hidden" }, rowSelectingOptions: { selectAllSelector: "#selectAllBox" }, language: { zeroRecords: emptyTableHtml, emptyTable: emptyTableHtml, loading: "Placeholder Loading Message...", }, rowCallback: (row, data, index) => { $(row).addClass("bg-white dark:bg-neutral-900"); }, drawCallback: () => { HSDropdown.autoInit(); }, select: { style: "multi", selector: "td:first-child input[type='checkbox']" }, columnDefs: [ { // Row select checkbox targets: 0, orderable: false, searchable: false, render: (data, type, row) => { return `
`; } }, { // Name targets: 1, data: "name", orderable: true, searchable: true, render: data => { return ` ${data} `; } }, { // Url targets: 2, data: "url", orderable: true, searchable: true, render: data => { return ` ${data} `; } }, { // Channels target: 3, data: "channels", orderable: false, searchable: false, render: (data, type, row) => { if (type !== "display") { return data; } if (!data.length) { return ""; } const wrapper = $("
").addClass("flex flex-nowrap gap-1 px-6 py-4"); const tag = $("").addClass("inline-flex items-center whitespace-nowrap gap-1 py-1 px-2.5 border text-xs rounded-md bg-white dark:bg-neutral-800 border-gray-200 dark:border-neutral-700 text-gray-800 dark:text-neutral-200"); const firstChannelName = "# " + channels.find(c => c.id === data[0]).name; wrapper.append(tag.clone().text(firstChannelName)); // No need to run the dropdown code if there's no more to show if (data.length === 1) { return wrapper.get(0); } else if (data.length <= 2) { const secondChannelName = "# " + channels.find(c => c.id === data[1]).name; wrapper.append(tag.clone().text(secondChannelName)); data.shift(); return wrapper.get(0); } // drop the first element to exclude it from the dropdown data.shift(); const dropdown = $("
").addClass("hs-dropdown inline-block"); const dropdownBtn = $("