next page

This commit is contained in:
counterweight 2025-03-13 11:05:12 +01:00
parent ae64424f54
commit eb1cfbb64c
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
5 changed files with 129 additions and 124 deletions

View file

@ -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);

View file

@ -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();

View file

@ -130,5 +130,5 @@
</div>
</main>
</body>
<script src="/javascript/createProfile.js"></script>
<script src="/javascript/createProfile.bundle.js"></script>
</html>

View file

@ -110,6 +110,6 @@
</div>
</div>
</main>
<script src="/invite.bundle.js"></script>
<script src="/javascript/invite.bundle.js"></script>
</body>
</html>

View file

@ -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',
};