Compare commits

..

No commits in common. "9fc386a973b1d94b17e4959176f3261294648fc8" and "411c9e0597f1c959220d8fe68c4eb135eb336328" have entirely different histories.

4 changed files with 49 additions and 58 deletions

View File

@ -1,4 +1,22 @@
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()}`;
}
const emptyTableHtml = `
<div class="max-w-md w-full min-h-[400px] flex flex-col justify-center mx-auto px-6 py-4">
<div class="flex justify-center items-center size-[46px] bg-gray-100 rounded-lg dark:bg-neutral-800">

View File

@ -1,4 +1,22 @@
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 = `
@ -88,12 +106,12 @@ const defineTable = () => {
data: "name",
orderable: true,
searchable: true,
render: (data, _type, row) => {
render: data => {
return `
<td class="size-px whitespace-nowrap align-top">
<span class="openSubModal-js block px-6 py-4 text-blue-500 hover:text-blue-600 focus:text-blue-600 dark:text-blue-400 dark:hover:text-blue-500 dark:focus:text-blue-500 text-nowrap cursor-pointer" data-id="${row.id}">
<a href="#" class="block px-6 py-4 text-blue-500 hover:text-blue-600 focus:text-blue-600 dark:text-blue-400 dark:hover:text-blue-500 dark:focus:text-blue-500 text-nowrap">
${data}
</span>
</a>
</td>
`;
}
@ -289,43 +307,21 @@ $("input[name='filterActive']").on("change", () => {
table.dataTable.draw();
});
const openSubForm = async id => {
const openSubForm = () => {
$("#subForm").removeClass("submitted");
// Always clear the selects to avoid bugs
// Clear the form values
$("#formName").val("");
$("#formUrl").val("");
$("#formPublishedThreshold").val(new Date().toISOString().slice(0, 16));
HSSelect.getInstance("#formStyle", true).element.setValue([]);
HSSelect.getInstance("#formChannels", true).element.setValue([]);
HSSelect.getInstance("#formFilters", true).element.setValue([]);
$("#formChannelsInput").css("width", "");
$("#formFiltersInput").css("width", "");
// New Subscription: Clear the form values
if (id === -1) {
$("#formName").val("");
$("#formUrl").val("");
$("#formPublishedThreshold").val(new Date().toISOString().slice(0, 16));
$("#formActive").prop("checked", true);
}
// Existing subscription: Load the values
else {
const data = await $.ajax({
url: `/guild/${guildId}/subscriptions/api?id=${id}`,
method: "get",
});
$("#formName").val(data.name);
$("#formUrl").val(data.url);
$("#formPublishedThreshold").val(new Date(data.created_at));
HSSelect.getInstance("#formStyle", true).element.setValue([]);
HSSelect.getInstance("#formChannels", true).element.setValue(data.channels);
HSSelect.getInstance("#formFilters", true).element.setValue([]);
// $("#formChannelsInput").css("width", "");
// $("#formFiltersInput").css("width", "");
$("#formActive").prop("checked", data.active);
}
$("#formActive").prop("checked", true);
HSOverlay.open($("#subModal").get(0));
}
@ -335,9 +331,7 @@ const closeSubForm = () => {
HSOverlay.close($("#subModal").get(0));
}
$(document).on("click", ".openSubModal-js", event => {
openSubForm($(event.target).data("id") || -1);
});
$(document).on("click", ".openSubModal-js", openSubForm);
const submitForm = async event => {
event.preventDefault();

View File

@ -6,22 +6,4 @@ window.addEventListener('load', () => {
if ((evt.metaKey || evt.ctrlKey) && evt.key === 'a') this.select();
});
});
});
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()}`;
}
});

View File

@ -69,10 +69,7 @@ export const get = async (request: Request, response: Response) => {
return;
}
// Parse empty channel arrays
data.channels = data.channels === "[null]"
? []
: JSON.parse(data.channels);
data.channels = JSON.parse(data.channels);
response.json(data);
}