feed: ability to close reply form
ci/woodpecker/pr/woodpecker Pipeline was successful Details
ci/woodpecker/push/woodpecker Pipeline was successful Details

This is an approach to close the reply-to-form automatically when
focus is lost and only if the input is empty. A second way to close
the reply-to-form is provided by toggling the reply icon.
pull/23/head
OFF0 1 year ago
parent cfb7a2dc35
commit 11fbc7aa7d
Signed by: offbyn
GPG Key ID: 94A2F643C51F37FA

@ -202,7 +202,7 @@ button[name="back"] {
.shrink-out { .shrink-out {
animation-duration: var(--transition-duration); animation-duration: var(--transition-duration);
animation-name: lineInserted; animation-name: lineInserted;
transition: max-height var(--transition-duration) var(--transition-timing-function); transition: max-height calc(.5 * var(--transition-duration)) var(--transition-timing-function);
} }
@keyframes lineInserted { @keyframes lineInserted {
from { from {

@ -52,7 +52,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: 750, limit: 75,
} }
}); });
@ -405,10 +405,13 @@ function getMetadata(evt, relay) {
return {host, img, isReply, name, replies, time, userName}; return {host, img, isReply, name, replies, time, userName};
} }
// reply
feedContainer.addEventListener('click', (e) => { feedContainer.addEventListener('click', (e) => {
const button = e.target.closest('button'); const button = e.target.closest('button');
if (button && button.name === 'reply') { if (button && button.name === 'reply') {
if (localStorage.getItem('reply_to') === button.dataset.eventId) {
writeInput.blur();
return;
}
appendReplyForm(button); appendReplyForm(button);
localStorage.setItem('reply_to', button.dataset.eventId); localStorage.setItem('reply_to', button.dataset.eventId);
return; return;
@ -422,11 +425,29 @@ feedContainer.addEventListener('click', (e) => {
const writeForm = document.querySelector('#writeForm'); const writeForm = document.querySelector('#writeForm');
const writeInput = document.querySelector('textarea[name="message"]'); const writeInput = document.querySelector('textarea[name="message"]');
function appendReplyForm(el) { const elemShrink = () => {
const height = writeInput.style.height || writeInput.getBoundingClientRect().height;
const shrink = elem('div', {className: 'shrink-out'}); const shrink = elem('div', {className: 'shrink-out'});
shrink.style.height = `${writeInput.style.height || writeInput.getBoundingClientRect().height}px`; shrink.style.height = `${height}px`;
shrink.addEventListener('animationend', () => shrink.remove()); shrink.addEventListener('animationend', () => shrink.remove(), {once: true});
writeForm.before(shrink); return shrink;
}
writeInput.addEventListener('focusout', () => {
const reply_to = localStorage.getItem('reply_to');
if (reply_to && writeInput.value === '') {
writeInput.addEventListener('transitionend', (event) => {
if (!reply_to || reply_to === localStorage.getItem('reply_to') && !writeInput.style.height) { // should prob use some class or data-attr instead of relying on height
writeForm.after(elemShrink());
writeForm.remove();
localStorage.removeItem('reply_to');
}
}, {once: true});
}
});
function appendReplyForm(el) {
writeForm.before(elemShrink());
writeInput.blur(); writeInput.blur();
writeInput.style.removeProperty('height'); writeInput.style.removeProperty('height');
el.after(writeForm); el.after(writeForm);

Loading…
Cancel
Save