next page
This commit is contained in:
parent
ae64424f54
commit
eb1cfbb64c
5 changed files with 129 additions and 124 deletions
|
|
@ -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);
|
|
||||||
125
src/front/pages/createProfile.js
Normal file
125
src/front/pages/createProfile.js
Normal 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();
|
||||||
|
|
@ -130,5 +130,5 @@
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
<script src="/javascript/createProfile.js"></script>
|
<script src="/javascript/createProfile.bundle.js"></script>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
<script src="/invite.bundle.js"></script>
|
<script src="/javascript/invite.bundle.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,11 @@ const path = require('path');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
entry: {
|
entry: {
|
||||||
invite: './src/front/pages/invite.js',
|
invite: './src/front/pages/invite.js',
|
||||||
|
createProfile: './src/front/pages/createProfile.js',
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
filename: '[name].bundle.js',
|
filename: '[name].bundle.js',
|
||||||
path: path.resolve(__dirname, 'public'),
|
path: path.resolve(__dirname, 'public', 'javascript'),
|
||||||
},
|
},
|
||||||
mode: 'development',
|
mode: 'development',
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue