format project

This commit is contained in:
counterweight 2025-02-14 11:13:18 +01:00
parent 90d8e39eb3
commit c02cf8c12e
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
39 changed files with 2062 additions and 909 deletions

View file

@ -1,6 +1,6 @@
.badge {
border: 2px solid black;
border-radius: 10px;
margin: 5px;
padding: 5px;
}
border: 2px solid black;
border-radius: 10px;
margin: 5px;
padding: 5px;
}

View file

@ -1,104 +1,106 @@
class ContactDetails {
constructor(rootUiElement) {
this.rootUiElement = rootUiElement;
this.details = [];
}
constructor(rootUiElement) {
this.rootUiElement = rootUiElement;
this.details = [];
}
addDetails(type, value) {
this.details.push({ type, value });
}
addDetails(type, value) {
this.details.push({ type, value });
}
removeDetails(type, value) {
this.details = this.details.filter(detail => detail.type !== type || detail.value !== 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);
});
})
}
syncUi() {
requestAnimationFrame(() => {
this.rootUiElement.innerHTML = '';
this.details.forEach((detail) => {
const addedDetailFragment = this.buildContactDetailBadge(detail);
this.rootUiElement.appendChild(addedDetailFragment);
});
});
}
buildContactDetailBadge(detail) {
const fragment = document.createDocumentFragment();
buildContactDetailBadge(detail) {
const fragment = document.createDocumentFragment();
const div = document.createElement("div");
div.className = "added-contact-detail badge";
const div = document.createElement('div');
div.className = 'added-contact-detail badge';
const p = document.createElement("p");
p.textContent = `${detail.type}: ${detail.value}`;
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;
};
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);
div.appendChild(p);
div.appendChild(button);
fragment.appendChild(div);
return fragment;
}
return fragment;
}
async getEncryptedContactDetails() {
const jsonString = JSON.stringify(this.details);
const encryptedContactDetails = await window.nostr.nip04.encrypt(await window.nostr.getPublicKey(), jsonString);
return encryptedContactDetails;
}
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'));
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();
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;
if (value === '') return;
contactDetails.addDetails(type, value);
contactDetails.syncUi();
contactDetails.addDetails(type, value);
contactDetails.syncUi();
input.value = '';
});
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 })
});
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 })
});
}
);
};
const nym = document.querySelector('#nym-input').value;
await fetch('/api/set-nym', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ nym }),
});
});
};

View file

@ -1,69 +1,68 @@
window.onload = function () {
if (!window.nostr) {
console.log("Nostr extension not present");
document.querySelector('#nostr-signup').disabled = true;
document.querySelector('#no-extension-nudges').style.display = 'block';
} else {
console.log("Nostr extension present");
}
}
if (!window.nostr) {
console.log('Nostr extension not present');
document.querySelector('#nostr-signup').disabled = true;
document.querySelector('#no-extension-nudges').style.display = 'block';
} else {
console.log('Nostr extension present');
}
};
async function acceptInvite() {
let challengeResponse;
try {
challengeResponse = await fetch('/api/signup/nostr-challenge', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
} catch (error) {
console.log(`Something went wrong: ${error}`);
return;
}
let challengeResponse;
try {
challengeResponse = await fetch('/api/signup/nostr-challenge', {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
} catch (error) {
console.log(`Something went wrong: ${error}`);
return;
}
const { challenge } = await challengeResponse.json();
const { challenge } = await challengeResponse.json();
let pubkey;
try {
pubkey = await window.nostr.getPublicKey();
} catch (error) {
document.querySelector('#rejected-nostr-nudges').style.display = 'block';
return;
}
const event = {
kind: 22242,
created_at: Math.floor(Date.now() / 1000),
tags: [['challenge', challenge]],
content: 'Sign this challenge to authenticate',
pubkey: pubkey,
};
let pubkey;
try {
pubkey = await window.nostr.getPublicKey();
} catch (error) {
document.querySelector('#rejected-nostr-nudges').style.display = 'block';
return;
}
const event = {
kind: 22242,
created_at: Math.floor(Date.now() / 1000),
tags: [["challenge", challenge]],
content: "Sign this challenge to authenticate",
pubkey: pubkey
};
let signedEvent;
try {
signedEvent = await window.nostr.signEvent(event);
} catch (error) {
document.querySelector('#rejected-nostr-nudges').style.display = 'block';
return;
}
let signedEvent;
try {
signedEvent = await window.nostr.signEvent(event);
} catch (error) {
document.querySelector('#rejected-nostr-nudges').style.display = 'block';
return;
}
let verifyResponse;
try {
verifyResponse = await fetch('/api/signup/nostr-verify', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(signedEvent),
});
} catch (error) {
console.log(`Something went wrong: ${error}`);
return;
}
let verifyResponse;
try {
verifyResponse = await fetch("/api/signup/nostr-verify", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(signedEvent),
});
} catch (error) {
console.log(`Something went wrong: ${error}`);
return;
}
if (verifyResponse.ok) {
document.querySelector('#sign-up-success').style.display = 'block';
setTimeout(() => {
window.location.href = "/createProfile";
}, 1000);
}
}
if (verifyResponse.ok) {
document.querySelector('#sign-up-success').style.display = 'block';
setTimeout(() => {
window.location.href = '/createProfile';
}, 1000);
}
}