From e2431c7e609bbc7a1c2679391bdb203853e56692 Mon Sep 17 00:00:00 2001 From: OFF0 Date: Sat, 10 Dec 2022 11:57:46 +0100 Subject: [PATCH] profile: support kind 0 metadata events Added simple profile form to the setting view to send kind 0 metdata such as: name, about and picture. --- src/form.css | 11 ++++++----- src/index.html | 13 ++++++++++++- src/main.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/src/form.css b/src/form.css index 1c9d56e..4863d74 100644 --- a/src/form.css +++ b/src/form.css @@ -45,6 +45,7 @@ label { input[type="password"], input[type="text"], +input[type="url"], textarea { background: var(--bgcolor-textinput); border: .2rem solid #b7b7b7; @@ -55,11 +56,16 @@ textarea { } input[type="password"]:focus, input[type="text"]:focus, +input[type="url"]:focus, textarea:focus { border-color: var(--focus-border-color); outline-offset: var(--focus-outline-offset); outline: var(--focus-outline); } +input:invalid { + outline: 2px solid var(--bgcolor-danger); + outline-offset: var(--focus-outline-offset); +} textarea { /* max-height: 64vh; */ min-height: 20px; @@ -145,11 +151,6 @@ button:disabled { cursor: default; } -.inline-text { - display: inline-block; - padding: 0 1ch; -} - .form-status { flex-basis: 100%; flex-grow: 1; diff --git a/src/index.html b/src/index.html index 2659c0f..2781169 100644 --- a/src/index.html +++ b/src/index.html @@ -59,6 +59,18 @@ --> +
+ + + + + + +
+ + +
+
@@ -72,7 +84,6 @@
-
diff --git a/src/main.js b/src/main.js index 743b415..e42245c 100644 --- a/src/main.js +++ b/src/main.js @@ -723,3 +723,49 @@ document.body.addEventListener('click', (e) => { hideNewMessage(true); } }); + +// profile +const profileForm = document.querySelector('form[name="profile"]'); +const profileSubmit = profileForm.querySelector('button[type="submit"]'); +const profileStatus = document.querySelector('#profilestatus'); +const onProfileError = err => { + profileStatus.hidden = false; + profileStatus.textContent = err.message +}; +profileForm.addEventListener('input', (e) => { + if (e.target.nodeName === 'TEXTAREA') { + updateElemHeight(e.target); + } + const form = new FormData(profileForm); + const name = form.get('name'); + const about = form.get('about'); + const picture = form.get('picture'); + profileSubmit.disabled = !(name || about || picture); +}); + +profileForm.addEventListener('submit', async (e) => { + e.preventDefault(); + const form = new FormData(profileForm); + const privatekey = localStorage.getItem('private_key'); + + const newProfile = { + kind: 0, + pubkey, + content: JSON.stringify(Object.fromEntries(form)), + created_at: Math.floor(Date.now() * 0.001), + tags: [], + }; + const sig = await signEvent(newProfile, privatekey).catch(console.error); + if (sig) { + const ev = await pool.publish({...newProfile, sig}, (status, url) => { + if (status === 0) { + console.info(`publish request sent to ${url}`); + } + if (status === 1) { + profileStatus.textContent = 'profile metadata successfully published'; + profileStatus.hidden = false; + profileSubmit.disabled = true; + } + }).catch(console.error); + } +}); -- 2.46.2