delete old stuff
This commit is contained in:
parent
0d737aa5fb
commit
e31225594b
1 changed files with 0 additions and 123 deletions
|
|
@ -1,126 +1,3 @@
|
|||
/* class ContactDetails {
|
||||
constructor(rootUiElement) {
|
||||
this.rootUiElement = rootUiElement;
|
||||
this.details = [];
|
||||
}
|
||||
|
||||
addDetails(type, value) {
|
||||
this.details.push({ type, value });
|
||||
}
|
||||
|
||||
removeDetails(type, value) {
|
||||
this.details = this.details.filter(
|
||||
(detail) => detail.type !== type || detail.value !== value
|
||||
);
|
||||
}
|
||||
|
||||
syncUi() {
|
||||
requestAnimationFrame(() => {
|
||||
this.rootUiElement.innerHTML = '';
|
||||
this.details.forEach((detail) => {
|
||||
const addedDetailFragment = this.buildContactDetailBadge(detail);
|
||||
this.rootUiElement.appendChild(addedDetailFragment);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
buildContactDetailBadge(detail) {
|
||||
const fragment = document.createDocumentFragment();
|
||||
|
||||
const div = document.createElement('div');
|
||||
div.className = 'added-contact-detail badge';
|
||||
|
||||
const p = document.createElement('p');
|
||||
p.textContent = `${detail.type}: ${detail.value}`;
|
||||
|
||||
const button = document.createElement('button');
|
||||
button.textContent = 'Eliminar';
|
||||
button.onclick = () => {
|
||||
this.removeDetails(detail.type, detail.value);
|
||||
this.syncUi();
|
||||
return false;
|
||||
};
|
||||
|
||||
div.appendChild(p);
|
||||
div.appendChild(button);
|
||||
fragment.appendChild(div);
|
||||
|
||||
return fragment;
|
||||
}
|
||||
|
||||
async getEncryptedContactDetails() {
|
||||
const jsonString = JSON.stringify(this.details);
|
||||
const encryptedContactDetails = await window.nostr.nip04.encrypt(
|
||||
await window.nostr.getPublicKey(),
|
||||
jsonString
|
||||
);
|
||||
return encryptedContactDetails;
|
||||
}
|
||||
}
|
||||
|
||||
let contactDetails;
|
||||
|
||||
window.onload = () => {
|
||||
contactDetails = new ContactDetails(
|
||||
document.querySelector('#created-contact-details-list')
|
||||
);
|
||||
|
||||
document.querySelectorAll('.contact-detail-add-button').forEach((button) => {
|
||||
button.addEventListener('click', function () {
|
||||
const badge = this.parentElement;
|
||||
const type = badge.getAttribute('data-type');
|
||||
const input = badge.querySelector('input');
|
||||
const value = input.value.trim();
|
||||
|
||||
if (value === '') return;
|
||||
|
||||
contactDetails.addDetails(type, value);
|
||||
contactDetails.syncUi();
|
||||
|
||||
input.value = '';
|
||||
});
|
||||
});
|
||||
|
||||
document
|
||||
.querySelector('#submit-details-button')
|
||||
.addEventListener('click', async () => {
|
||||
const encryptedContactDetails =
|
||||
await contactDetails.getEncryptedContactDetails();
|
||||
await fetch('/api/set-contact-details', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ encryptedContactDetails }),
|
||||
});
|
||||
|
||||
const nym = document.querySelector('#nym-input').value;
|
||||
await fetch('/api/set-nym', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ nym }),
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.href = '/home';
|
||||
}, 1000);
|
||||
});
|
||||
};
|
||||
*/
|
||||
/*
|
||||
|
||||
Behaviours:
|
||||
|
||||
- Validate inputs
|
||||
- Only activate submit profile when nym and one contact method are alive
|
||||
- Send the data and redirect on button click
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
function debounce(func, wait) {
|
||||
let timeout;
|
||||
return function (...args) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue