From 66ff80163e4117a0c14f0a95723d9e0fe48b9660 Mon Sep 17 00:00:00 2001 From: Meysam Date: Sat, 11 Jan 2025 15:56:11 +0700 Subject: [PATCH] chore: hide subscribe button if the server is down (#70) --- docs/static/subscribe.css | 4 ++++ docs/static/subscribe.js | 14 +++++++++++++- overrides/partials/subscription-form.html | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/docs/static/subscribe.css b/docs/static/subscribe.css index 4683f2e..dc2c94e 100644 --- a/docs/static/subscribe.css +++ b/docs/static/subscribe.css @@ -54,6 +54,10 @@ flex-direction: column; } +#subscribe-container-82087868.hidden { + display: none; +} + #subscribe-form-9b27c56e.hidden { display: none; } diff --git a/docs/static/subscribe.js b/docs/static/subscribe.js index fd8b013..510884b 100644 --- a/docs/static/subscribe.js +++ b/docs/static/subscribe.js @@ -1,4 +1,4 @@ -document$.subscribe(function prepareSubForm() { +document$.subscribe(async function prepareSubForm() { var formParentDiv = document.getElementById("subscribe-form-9b27c56e"); var subscriptionForm = document.getElementById("subscription-form-b8eb1947"); var subscribeButton = document.getElementById("subscribe-button-ea4577c9"); @@ -81,6 +81,18 @@ document$.subscribe(function prepareSubForm() { submitInfo.classList.remove("hidden"); } + async function renderSubscriptionForm() { + console.log("Fetching newsletter subscription form..."); + + var response = await fetch("https://newsletter.developer-friendly.blog"); + if (response.status == 200) { + document + .getElementById("subscribe-container-82087868") + .classList.remove("hidden"); + } + } + subscribeButton.addEventListener("click", subscribeButtonClick); subscriptionForm.addEventListener("submit", subscribeButtonSubmit); + await renderSubscriptionForm(); }); diff --git a/overrides/partials/subscription-form.html b/overrides/partials/subscription-form.html index 5383a6f..f0c374f 100644 --- a/overrides/partials/subscription-form.html +++ b/overrides/partials/subscription-form.html @@ -1,4 +1,4 @@ -
+