utils: move multiline function to domutils

pull/13/head
OFF0 1 year ago
parent 409ff80d64
commit e9cc165738
Signed by: offbyn
GPG Key ID: 94A2F643C51F37FA

@ -23,3 +23,15 @@ export function elem(name = 'div', {data, ...props} = {}, children = []) {
}
return el;
}
/**
* Renders line breaks
*
* @param {string} text with newlines
* @return Array<TextNode | HTMLBRElement>
*/
export function multilineText(string) {
return string
.split('\n')
.reduce((acc, next, i) => acc.concat(i === 0 ? next : [elem('br'), next]), []);
}

@ -1,5 +1,5 @@
import {relayPool, generatePrivateKey, getPublicKey, signEvent} from 'nostr-tools';
import {elem} from './domutil.js';
import {elem, multilineText} from './domutil.js';
import {dateTime, formatTime} from './timeutil.js';
// curl -H 'accept: application/nostr+json' https://nostr.x1ddos.ch
const pool = relayPool();
@ -152,12 +152,6 @@ setInterval(() => {
});
}, 10000);
function renderMultilineText(string) {
return string
.split('\n')
.reduce((acc, next, i) => acc.concat(i === 0 ? next : [elem('br'), next]), []);
}
function createTextNote(evt, relay) {
const {host, img, isReply, replies, time, userName} = getMetadata(evt, relay);
const isLongContent = evt.content.length > 280;
@ -178,7 +172,7 @@ function createTextNote(evt, relay) {
elem('time', {dateTime: time.toISOString()}, formatTime(time)),
]),
]),
elem('div', {data: isLongContent ? {append: evt.content.slice(280)} : null}, renderMultilineText(content)),
elem('div', {data: isLongContent ? {append: evt.content.slice(280)} : null}, multilineText(content)),
elem('button', {
className: 'btn-inline', name: 'star', type: 'button',
data: {'eventId': evt.id, relay},

Loading…
Cancel
Save