diff --git a/src/public/javascript/createProfile.js b/src/public/javascript/createProfile.js index 0b0c334..80e9fb0 100644 --- a/src/public/javascript/createProfile.js +++ b/src/public/javascript/createProfile.js @@ -129,7 +129,7 @@ function debounce(func, wait) { }; } -validateNymInput = debounce(() => { +const validateNymInput = debounce(() => { const nymValue = nymInput.value.trim(); const isValid = nymValue.length >= 3 && nymValue.length <= 128; if (isValid) { @@ -139,7 +139,7 @@ validateNymInput = debounce(() => { } }, 500); -checkIfSubmittable = debounce((allInputs) => { +const checkIfSubmittable = debounce((allInputs) => { const nymIsFilled = allInputs.nymInput.value !== ''; let atLeastOneContactIsFilled = false; @@ -153,7 +153,37 @@ checkIfSubmittable = debounce((allInputs) => { submitProfileButton.disabled = buttonShouldBeDisabled; }, 1000); -function onLoadErrands(allInputs) { +async function createProfile(allInputs) { + const contactDetails = []; + for (const someInput of allInputs.contactInputs) { + contactDetails.push({ + type: someInput.getAttribute('data-type'), + value: someInput.value, + }); + } + const encryptedContactDetails = await window.nostr.nip04.encrypt( + await window.nostr.getPublicKey(), + JSON.stringify(contactDetails) + ); + await fetch('/api/set-contact-details', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ encryptedContactDetails }), + }); + + const nym = allInputs.nymInput.value; + await fetch('/api/set-nym', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ nym }), + }); +} + +function onLoadErrands(allInputs, submitProfileButton) { allInputs.nymInput.addEventListener('input', validateNymInput); for (const someInput of allInputs.allInputs) { @@ -163,6 +193,10 @@ function onLoadErrands(allInputs) { } checkIfSubmittable(allInputs); + + submitProfileButton.addEventListener('click', () => { + createProfile(allInputs); + }); } const nymInput = document.getElementById('nym-input'); @@ -198,4 +232,4 @@ const allInputs = { ], }; -onLoadErrands(allInputs); +onLoadErrands(allInputs, submitProfileButton); diff --git a/src/views/createProfile.ejs b/src/views/createProfile.ejs index 6ab04f1..606d9ec 100644 --- a/src/views/createProfile.ejs +++ b/src/views/createProfile.ejs @@ -67,36 +67,55 @@
-
+
-

Teléfono

- +
-
+

Whatsapp

- +
-
+

Telegram

- +
-
+

Email

- +
-
+

Nostr

- +
-
+

Signal

- +