feed: playing with ui

- shorten text notes after 280 chars
- add expand button to shortened text
- play around with profile image and username layout
pull/2/head
OFF0 2 years ago
parent c896789ccd
commit a71de21302
Signed by: offbyn
GPG Key ID: 94A2F643C51F37FA

@ -7,13 +7,19 @@
margin-bottom: 1rem; margin-bottom: 1rem;
} }
.mbox .mbox-img { .mbox-img {
--size: 4ch;
align-self: start; align-self: start;
flex-basis: 4ch; flex-basis: var(--size);
height: 4ch; height: var(--size);
margin-right: 1rem; margin-right: 1rem;
margin-top: .5ch; margin-top: .5ch;
max-width: 4ch; max-width: var(--size);
}
.mbox-recommend-server .mbox-img {
--size: 2.5ch;
margin-left: 1ch;
margin-right: 1.5ch;
} }
.mbox-body { .mbox-body {

@ -50,7 +50,7 @@ const subscription = pool.sub({
// '32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245', // jb55 // '32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245', // jb55
// ], // ],
// since: new Date(Date.now() - (24 * 60 * 60 * 1000)), // since: new Date(Date.now() - (24 * 60 * 60 * 1000)),
limit: 2000, limit: 100,
} }
}); });
@ -117,22 +117,20 @@ function createTextNote(evt, relay) {
const {host, img, isReply, replies, time, userName} = getMetadata(evt, relay); const {host, img, isReply, replies, time, userName} = getMetadata(evt, relay);
const name = elem('strong', {className: 'mbox-username', title: evt.pubkey}, userName); const name = elem('strong', {className: 'mbox-username', title: evt.pubkey}, userName);
const timeElem = elem('time', { dateTime: time.toISOString()}, formatTime(time)); const timeElem = elem('time', { dateTime: time.toISOString()}, formatTime(time));
const headerInfo = isReply ? [ const hasLongContent = evt.content.length > 280;
name, ' ', timeElem const headerInfo = isReply
] : [ ? [name, ' ', timeElem]
name, : [name, ` on ${host} `, timeElem];
elem('span', { const content = hasLongContent ? `${evt.content.slice(0, 280)}` : evt.content;
title: `Event ${evt.id}
${isReply ? `\nReply ${evt.tags[0][1]}\n` : ''}`
}, ` on ${host} `),
timeElem,
];
const body = elem('div', {className: 'mbox-body'}, [ const body = elem('div', {className: 'mbox-body'}, [
elem('header', {className: 'mbox-header'}, [ elem('header', {
className: 'mbox-header',
title: `Event ${evt.id}\non ${host} ${time}
${isReply ? `\nReply ${evt.tags[0][1]}\n` : ''}`
}, [
elem('small', {}, headerInfo), elem('small', {}, headerInfo),
]), ]),
evt.content, // text elem('div', {data: hasLongContent ? {append: evt.content.slice(280)} : null}, content),
elem('br'),
elem('button', { elem('button', {
className: 'button-inline', className: 'button-inline',
name: 'reply', type: 'button', name: 'reply', type: 'button',
@ -153,7 +151,7 @@ function handleReply(evt, relay) {
replyContainer = elem('div', {className: 'mobx-replies'}); replyContainer = elem('div', {className: 'mobx-replies'});
article.querySelector('.mbox-body').append(replyContainer); article.querySelector('.mbox-body').append(replyContainer);
} }
replyContainer.append(createTextNote(evt, relay)) replyContainer.append(createTextNote(evt, relay));
} }
} }
@ -247,13 +245,14 @@ function getMetadata(evt, relay) {
const userImg = /*user?.metadata[relay]?.picture || */'bubble.svg'; // TODO: enable pic once we have proxy const userImg = /*user?.metadata[relay]?.picture || */'bubble.svg'; // TODO: enable pic once we have proxy
const userName = user?.metadata[relay]?.name || evt.pubkey.slice(0, 8); const userName = user?.metadata[relay]?.name || evt.pubkey.slice(0, 8);
const userAbout = user?.metadata[relay]?.about || ''; const userAbout = user?.metadata[relay]?.about || '';
const isReply = evt.tags.some(hasEventTag); const title = `${userName} on ${host} ${userAbout}`;
const img = elem('img', { const img = elem('img', {
className: 'mbox-img', className: 'mbox-img',
src: userImg, src: userImg,
alt: `${userName}@${host}`, alt: title,
title: userAbout, title,
}, ''); }, '');
const isReply = evt.tags.some(hasEventTag);
const replies = replyList.filter((reply) => reply.tags[0][1] === evt.id); const replies = replyList.filter((reply) => reply.tags[0][1] === evt.id);
const time = new Date(evt.created_at * 1000); const time = new Date(evt.created_at * 1000);
return {host, img, isReply, replies, time, userName}; return {host, img, isReply, replies, time, userName};
@ -289,6 +288,7 @@ feedContainer.addEventListener('click', (e) => {
writeForm.hidden = false; writeForm.hidden = false;
replyTo = ['e', button.dataset.eventId, button.dataset.relay]; replyTo = ['e', button.dataset.eventId, button.dataset.relay];
input.focus(); input.focus();
return;
} }
}); });
@ -399,3 +399,12 @@ privateTgl.addEventListener('click', () => {
privateKeyInput.value = localStorage.getItem('private_key'); privateKeyInput.value = localStorage.getItem('private_key');
pubKeyInput.value = localStorage.getItem('pub_key'); pubKeyInput.value = localStorage.getItem('pub_key');
document.body.addEventListener('click', (e) => {
const append = e.target.closest('[data-append]');
if (append) {
append.textContent += append.dataset.append;
delete append.dataset.append;
return;
}
});
Loading…
Cancel
Save