chore: format htmx and shell
This commit is contained in:
@@ -4,7 +4,7 @@ type ToastFn = (opts: { message: string; duration?: number }) => void;
|
||||
|
||||
const getToast = (): ToastFn | null => {
|
||||
const anyWindow = window as unknown as { showToast?: ToastFn };
|
||||
return typeof anyWindow.showToast === 'function' ? anyWindow.showToast : null;
|
||||
return typeof anyWindow.showToast === "function" ? anyWindow.showToast : null;
|
||||
};
|
||||
|
||||
const toast = (message: string): void => {
|
||||
@@ -13,15 +13,15 @@ const toast = (message: string): void => {
|
||||
|
||||
const setBusy = (el: Element | null, busy: boolean): void => {
|
||||
if (!(el instanceof HTMLElement)) return;
|
||||
el.toggleAttribute('aria-busy', busy);
|
||||
el.dataset.htmxLoading = busy ? 'true' : 'false';
|
||||
el.toggleAttribute("aria-busy", busy);
|
||||
el.dataset.htmxLoading = busy ? "true" : "false";
|
||||
|
||||
if (el instanceof HTMLButtonElement) {
|
||||
el.disabled = busy;
|
||||
}
|
||||
|
||||
if (busy) {
|
||||
el.dataset.htmxBusy = 'true';
|
||||
el.dataset.htmxBusy = "true";
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ const getTriggerFromHtmxEvent = (event: Event): Element | null => {
|
||||
};
|
||||
|
||||
const onReady = (fn: () => void): void => {
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', fn, { once: true });
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", fn, { once: true });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -43,29 +43,29 @@ const onReady = (fn: () => void): void => {
|
||||
};
|
||||
|
||||
onReady(() => {
|
||||
document.addEventListener('htmx:beforeRequest', event => {
|
||||
document.addEventListener("htmx:beforeRequest", (event) => {
|
||||
setBusy(getTriggerFromHtmxEvent(event), true);
|
||||
});
|
||||
|
||||
document.addEventListener('htmx:afterRequest', event => {
|
||||
document.addEventListener("htmx:afterRequest", (event) => {
|
||||
setBusy(getTriggerFromHtmxEvent(event), false);
|
||||
|
||||
const remaining = document.querySelectorAll('.continue-watching-item').length;
|
||||
const remaining = document.querySelectorAll(".continue-watching-item").length;
|
||||
if (remaining !== 0) return;
|
||||
|
||||
const section = document.getElementById('continue-watching-section');
|
||||
const section = document.getElementById("continue-watching-section");
|
||||
section?.remove();
|
||||
});
|
||||
|
||||
document.addEventListener('htmx:responseError', () => {
|
||||
toast('Something went wrong');
|
||||
document.addEventListener("htmx:responseError", () => {
|
||||
toast("Something went wrong");
|
||||
});
|
||||
|
||||
document.addEventListener('htmx:sendError', () => {
|
||||
toast('Network error');
|
||||
document.addEventListener("htmx:sendError", () => {
|
||||
toast("Network error");
|
||||
});
|
||||
|
||||
document.addEventListener('htmx:timeout', () => {
|
||||
toast('Request timed out');
|
||||
document.addEventListener("htmx:timeout", () => {
|
||||
toast("Request timed out");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user