aboutsummaryrefslogtreecommitdiffstats
path: root/src/scripts/common/login/form-caching.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/scripts/common/login/form-caching.ts')
-rw-r--r--src/scripts/common/login/form-caching.ts22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/scripts/common/login/form-caching.ts b/src/scripts/common/login/form-caching.ts
index bde6442..656de6e 100644
--- a/src/scripts/common/login/form-caching.ts
+++ b/src/scripts/common/login/form-caching.ts
@@ -1,22 +1,28 @@
import { addPostListener, addPostResponder, JQueryAjaxResponse } from "@/shared/intercept-jquery-ajax";
-let loginAreaHTML: string | null = null;
+/** Caches the login area HTML to avoid re-fetching it on subsequent requests. */
+let loginAreaHTML: JQueryAjaxResponse | null = null;
+/**
+ * Intercepts `viewLoginAreaAction` AJAX requests and serves the cached HTML
+ * if available, avoiding an unnecessary network round-trip.
+ */
addPostResponder(
"viewLoginAreaAction",
- function(_args): JQueryAjaxResponse | undefined | null {
- return loginAreaHTML
- ? {
- data: loginAreaHTML
- }
- : null;
+ function(_args): JQueryAjaxResponse | null {
+ return loginAreaHTML;
}
);
+/**
+ * Listens for successful `viewLoginAreaAction` responses and stores the
+ * returned HTML so the responder above can serve it from cache later.
+ */
addPostListener(
"viewLoginAreaAction",
function(_args, result): void {
- loginAreaHTML = result.data?.toString() ?? "";
+ if (result.textStatus === "success")
+ loginAreaHTML = result;
},
false
);