From 3ab815c30e556c26c818300b2de9475c41110593 Mon Sep 17 00:00:00 2001 From: OFF0 Date: Sun, 4 Dec 2022 16:57:31 +0100 Subject: [PATCH] post: remove whitespace of textnote content (trim right only) Send button should be disabled if there are only white spaces or newlines, trimming only right as white spaces at the beginning could mean somethig i.e in markdown. --- src/main.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main.js b/src/main.js index 964b39c..44e838b 100644 --- a/src/main.js +++ b/src/main.js @@ -427,7 +427,8 @@ writeForm.addEventListener('submit', async (e) => { if (!pubkey || !privatekey) { return onSendError(new Error('no pubkey/privatekey')); } - if (!writeInput.value) { + const content = writeInput.value.trimRight(); + if (!content) { return onSendError(new Error('message is empty')); } const replyTo = localStorage.getItem('reply_to'); @@ -435,7 +436,7 @@ writeForm.addEventListener('submit', async (e) => { const newEvent = { kind: 1, pubkey, - content: writeInput.value, + content, tags, created_at: Math.floor(Date.now() * 0.001), }; @@ -462,7 +463,7 @@ writeForm.addEventListener('submit', async (e) => { }); writeInput.addEventListener('input', () => { - publish.disabled = !writeInput.value; + publish.disabled = !writeInput.value.trimRight(); updateElemHeight(writeInput); }); writeInput.addEventListener('blur', () => sendStatus.textContent = '');