From eb1cfbb64c3f92d6e94ae3a802f28b0379fce0d4 Mon Sep 17 00:00:00 2001 From: counterweight Date: Thu, 13 Mar 2025 11:05:12 +0100 Subject: [PATCH] next page --- public/javascript/createProfile.js | 121 ---------------------------- src/front/pages/createProfile.js | 125 +++++++++++++++++++++++++++++ src/views/createProfile.ejs | 2 +- src/views/invite.ejs | 2 +- webpack.config.js | 3 +- 5 files changed, 129 insertions(+), 124 deletions(-) delete mode 100644 public/javascript/createProfile.js create mode 100644 src/front/pages/createProfile.js diff --git a/public/javascript/createProfile.js b/public/javascript/createProfile.js deleted file mode 100644 index 4be8920..0000000 --- a/public/javascript/createProfile.js +++ /dev/null @@ -1,121 +0,0 @@ -const createProfileConfirmation = document.querySelector( - '#create-profile-success' -); - -function debounce(func, wait) { - let timeout; - return function (...args) { - clearTimeout(timeout); - timeout = setTimeout(() => func.apply(this, args), wait); - }; -} - -const validateNymInput = debounce(() => { - const nymValue = nymInput.value.trim(); - const isValid = nymValue.length >= 3 && nymValue.length <= 128; - if (isValid) { - nymInputValidationWarning.style.display = 'none'; - } else { - nymInputValidationWarning.style.display = 'block'; - } -}, 500); - -const checkIfSubmittable = debounce((allInputs) => { - const nymIsFilled = allInputs.nymInput.value !== ''; - let atLeastOneContactIsFilled = false; - - for (const contactInput of allInputs.contactInputs) { - if (contactInput.value !== '') { - atLeastOneContactIsFilled = true; - } - } - - const buttonShouldBeDisabled = !(nymIsFilled && atLeastOneContactIsFilled); - submitProfileButton.disabled = buttonShouldBeDisabled; -}, 500); - -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 }), - }); - - createProfileConfirmation.classList.add('revealed'); - setTimeout(() => { - window.location.href = '/home'; - }, 5000); -} - -function onLoadErrands(allInputs, submitProfileButton) { - allInputs.nymInput.addEventListener('input', validateNymInput); - - for (const someInput of allInputs.allInputs) { - someInput.addEventListener('input', () => { - checkIfSubmittable(allInputs); - }); - } - - checkIfSubmittable(allInputs); - - submitProfileButton.addEventListener('click', () => { - createProfile(allInputs); - }); -} - -const nymInput = document.getElementById('nym-input'); -const nymInputValidationWarning = document.getElementById( - 'nym-input-validation-warning' -); -const phoneInput = document.getElementById('phone-input'); -const whatsappInput = document.getElementById('whatsapp-input'); -const telegramInput = document.getElementById('telegram-input'); -const emailInput = document.getElementById('email-input'); -const nostrInput = document.getElementById('nostr-input'); -const signalInput = document.getElementById('signal-input'); -const submitProfileButton = document.getElementById('submit-profile-button'); - -const allInputs = { - nymInput: nymInput, - contactInputs: [ - phoneInput, - whatsappInput, - telegramInput, - emailInput, - nostrInput, - signalInput, - ], - allInputs: [ - nymInput, - phoneInput, - whatsappInput, - telegramInput, - emailInput, - nostrInput, - signalInput, - ], -}; - -onLoadErrands(allInputs, submitProfileButton); diff --git a/src/front/pages/createProfile.js b/src/front/pages/createProfile.js new file mode 100644 index 0000000..51e61dd --- /dev/null +++ b/src/front/pages/createProfile.js @@ -0,0 +1,125 @@ +const createProfilesFunction = () => { + const createProfileConfirmation = document.querySelector( + '#create-profile-success' + ); + + function debounce(func, wait) { + let timeout; + return function (...args) { + clearTimeout(timeout); + timeout = setTimeout(() => func.apply(this, args), wait); + }; + } + + const validateNymInput = debounce(() => { + const nymValue = nymInput.value.trim(); + const isValid = nymValue.length >= 3 && nymValue.length <= 128; + if (isValid) { + nymInputValidationWarning.style.display = 'none'; + } else { + nymInputValidationWarning.style.display = 'block'; + } + }, 500); + + const checkIfSubmittable = debounce((allInputs) => { + const nymIsFilled = allInputs.nymInput.value !== ''; + let atLeastOneContactIsFilled = false; + + for (const contactInput of allInputs.contactInputs) { + if (contactInput.value !== '') { + atLeastOneContactIsFilled = true; + } + } + + const buttonShouldBeDisabled = !(nymIsFilled && atLeastOneContactIsFilled); + submitProfileButton.disabled = buttonShouldBeDisabled; + }, 500); + + 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 }), + }); + + createProfileConfirmation.classList.add('revealed'); + setTimeout(() => { + window.location.href = '/home'; + }, 5000); + } + + function onLoadErrands(allInputs, submitProfileButton) { + allInputs.nymInput.addEventListener('input', validateNymInput); + + for (const someInput of allInputs.allInputs) { + someInput.addEventListener('input', () => { + checkIfSubmittable(allInputs); + }); + } + + checkIfSubmittable(allInputs); + + submitProfileButton.addEventListener('click', () => { + createProfile(allInputs); + }); + } + + const nymInput = document.getElementById('nym-input'); + const nymInputValidationWarning = document.getElementById( + 'nym-input-validation-warning' + ); + const phoneInput = document.getElementById('phone-input'); + const whatsappInput = document.getElementById('whatsapp-input'); + const telegramInput = document.getElementById('telegram-input'); + const emailInput = document.getElementById('email-input'); + const nostrInput = document.getElementById('nostr-input'); + const signalInput = document.getElementById('signal-input'); + const submitProfileButton = document.getElementById('submit-profile-button'); + + const allInputs = { + nymInput: nymInput, + contactInputs: [ + phoneInput, + whatsappInput, + telegramInput, + emailInput, + nostrInput, + signalInput, + ], + allInputs: [ + nymInput, + phoneInput, + whatsappInput, + telegramInput, + emailInput, + nostrInput, + signalInput, + ], + }; + + onLoadErrands(allInputs, submitProfileButton); +}; + +createProfilesFunction(); diff --git a/src/views/createProfile.ejs b/src/views/createProfile.ejs index 3613440..d4be5ec 100644 --- a/src/views/createProfile.ejs +++ b/src/views/createProfile.ejs @@ -130,5 +130,5 @@ - + diff --git a/src/views/invite.ejs b/src/views/invite.ejs index d5e4dc9..d7d8f79 100644 --- a/src/views/invite.ejs +++ b/src/views/invite.ejs @@ -110,6 +110,6 @@ - + diff --git a/webpack.config.js b/webpack.config.js index 6cedde0..9e61a4e 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -3,10 +3,11 @@ const path = require('path'); module.exports = { entry: { invite: './src/front/pages/invite.js', + createProfile: './src/front/pages/createProfile.js', }, output: { filename: '[name].bundle.js', - path: path.resolve(__dirname, 'public'), + path: path.resolve(__dirname, 'public', 'javascript'), }, mode: 'development', };