From b71eaa949eeebed7bea09469b9c256288ef6c03c Mon Sep 17 00:00:00 2001 From: tavo Date: Sun, 22 Sep 2024 11:00:40 -0600 Subject: [PATCH] check one time --- public/client.js | 64 +++++++++++++++++++++++++++++------------------- server/main.go | 2 +- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/public/client.js b/public/client.js index 33338b1..02c5dd8 100644 --- a/public/client.js +++ b/public/client.js @@ -1,4 +1,5 @@ -const PayPalSDK = "https://sandbox.paypal.com/sdk/js?client-id=AUm4S44vdasfvVjG6oaQBc9ivbI92ofrfvL8-ItRjwSgtxuJyzkRRhKLabXMbehC7t-nxGdqhD58qasD&components=buttons&enable-funding=card&disable-funding=paylater,venmo" +const PayPalSDK = "https://sandbox.paypal.com/sdk/js?client-id=AcCW43LI1S6lLQgtLkF4V8UOPfmXcqXQ8xfEl41hRuMxSskR2jkWNwQN6Ab1WK7E2E52GNaoYBHqgIKd&components=buttons&enable-funding=card&disable-funding=paylater,venmo" +// const PayPalSDK = "https://paypal.com/sdk/js?client-id=AUm4S44vdasfvVjG6oaQBc9ivbI92ofrfvL8-ItRjwSgtxuJyzkRRhKLabXMbehC7t-nxGdqhD58qasD&components=buttons&enable-funding=card&disable-funding=paylater,venmo" const EditorJSComponents = [ "https://cdn.jsdelivr.net/npm/@editorjs/header@latest", @@ -117,15 +118,44 @@ function initializeEventListeners() { // // Mode switching document.getElementById('buyModeButton').addEventListener('click', openBuyModeDialog); document.getElementById('editModeButton').addEventListener('click', openEditModeDialog); + document.getElementById("continueToBuyModeButton").addEventListener('click', async () => { - const directory = sanitizeDirectoryTitle(document.getElementById("buyModeDirectoryInput").value); - const exists = await checkDirectoryExists(directory); - if (exists) { - document.getElementById("checkdir-error-message").style.display = "block"; - document.getElementById("checkdir-error-message").innerHTML = `El sitio https://conex.one/${directory} ya existe.`; - } else { - document.getElementById("checkdir-error-message").style.display = "none"; - buyMode(directory); + const button = document.getElementById("continueToBuyModeButton"); + const directoryInput = document.getElementById("buyModeDirectoryInput"); + const errorMessage = document.getElementById("checkdir-error-message"); + const directory = sanitizeDirectoryTitle(directoryInput.value); + + + const originalBuyButtonHTML = button.innerHTML; + button.innerHTML = ''; + button.disabled = true; + + let timeout = setTimeout(() => { + button.innerHTML = originalBuyButtonHTML; + button.disabled = false; + errorMessage.style.display = "block"; + errorMessage.innerHTML = `Revisar la disponibilidad del sitio tardó mucho tiempo, intentalo más tarde.`; + }, 10000); + + try { + const exists = await checkDirectoryExists(directory); + + clearTimeout(timeout); + + if (exists) { + errorMessage.style.display = "block"; + errorMessage.innerHTML = `El sitio https://conex.one/${directory} ya existe.`; + } else { + errorMessage.style.display = "none"; + buyMode(directory); + } + } catch (error) { + clearTimeout(timeout); + errorMessage.style.display = "block"; + errorMessage.innerHTML = `Error: Could not check the site. Please try again.`; + } finally { + button.innerHTML = originalBuyButtonHTML; + button.disabled = false; } }); @@ -166,14 +196,6 @@ function initializeEventListeners() { console.error('Invalid code. Please enter a 6-digit number.'); } }); - - const titleElement = document.getElementById('buyModeDirectoryInput'); - titleElement.addEventListener('input', debounce(function() { - const directory = titleElement.value.trim(); - if (directory.length > 0) { - validateDirectory(directory); - } - }, 500)); // 500ms debounce } function openDialog(content) { @@ -183,14 +205,6 @@ function openDialog(content) { floatingButtons.style.display = "none"; } -function debounce(func, delay) { - let timeout; - return function(...args) { - clearTimeout(timeout); - timeout = setTimeout(() => func.apply(this, args), delay); - }; -} - function closeDialog() { checkoutDialog.style.display = "none"; editDialog.style.display = "none"; diff --git a/server/main.go b/server/main.go index eb64285..ecb839f 100644 --- a/server/main.go +++ b/server/main.go @@ -131,7 +131,7 @@ func main() { http.HandleFunc("/api/directory/", VerifyDirectoryHandler(db)) http.HandleFunc("/api/fetch/", FetchSiteHandler(db)) http.HandleFunc("/api/upload", UploadFileHandler(s3Client, endpoint, apiEndpoint, apiToken, bucketName, publicEndpoint)) - http.Handle("/", http.FileServer(http.Dir("./public"))) + // http.Handle("/", http.FileServer(http.Dir("./public"))) stop := make(chan os.Signal, 1) signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)