hide/toggle "x posts omiited" text when expanded

return to correct number of preview posts e.g. if post has less/no preview replies
indiachan-spamvector
Thomas Lynch 2 years ago
parent 9430649a72
commit ddd5b29dda
  1. 1
      gulp/res/js/filters.js
  2. 26
      gulp/res/js/omitted.js
  3. 1
      gulp/res/js/time.js
  4. 7
      views/mixins/post.pug

@ -316,7 +316,6 @@ togglePostsHidden(getHiddenElems(), true);
window.addEventListener('addPost', function(e) { window.addEventListener('addPost', function(e) {
const newPost = e.detail.post; const newPost = e.detail.post;
console.log(newPost)
if (anyFilterMatches(newPost)) { if (anyFilterMatches(newPost)) {
newPost.classList.add('hidden'); newPost.classList.add('hidden');
} }

@ -3,9 +3,12 @@ window.addEventListener('DOMContentLoaded', () => {
let loading = {}; let loading = {};
const hideOmitted = (e) => { const hideOmitted = (e) => {
e.target.nextSibling.style.display = 'unset';
const thread = e.target.closest('.thread'); const thread = e.target.closest('.thread');
let replies = Array.from(thread.querySelectorAll('.post-container')); let replies = Array.from(thread.querySelectorAll('.post-container:not(.op)'));
replies = replies.slice(1, replies.length-5); if (e.target.dataset.shown > 0) {
replies = replies.slice(0, -parseInt(e.target.dataset.shown));
}
replies.forEach(r => { replies.forEach(r => {
r.previousSibling.remove(); r.previousSibling.remove();
r.remove(); r.remove();
@ -18,16 +21,17 @@ window.addEventListener('DOMContentLoaded', () => {
const threadId = e.target.dataset.thread; const threadId = e.target.dataset.thread;
const board = e.target.dataset.board; const board = e.target.dataset.board;
const parentPost = e.target.closest('.post-container'); const parentPost = e.target.closest('.post-container');
const firstPreviewReply = parentPost.nextSibling.nextSibling; //the first preview reply const firstPreviewReply = parentPost.nextSibling && parentPost.nextSibling.nextSibling; //the first preview reply
const jsonPath = `/${board}/thread/${threadId}.json`; const jsonPath = `/${board}/thread/${threadId}.json`;
let hovercache = localStorage.getItem(`hovercache-${jsonPath}`); let hovercache = localStorage.getItem(`hovercache-${jsonPath}`);
let replies; let replies;
if (hovercache) { if (hovercache) {
hovercache = JSON.parse(hovercache); hovercache = JSON.parse(hovercache);
//if we have the first preview reply in cache, the cache is fresh enough to show the omitted posts //if we have the first preview reply in cache, the cache is fresh enough to show the omitted posts
if (hovercache.replies.find(r => r.postId == firstPreviewReply.dataset.postId)) { if (firstPreviewReply && hovercache.replies.find(r => r.postId == firstPreviewReply.dataset.postId)) {
replies = hovercache.replies; replies = hovercache.replies;
} }
//note: will always fetch (on new page load) for sticky preview replies = 0
} }
if (!replies) { if (!replies) {
e.target.style.cursor = 'wait'; e.target.style.cursor = 'wait';
@ -56,15 +60,17 @@ window.addEventListener('DOMContentLoaded', () => {
if (!replies) { if (!replies) {
return; return;
} }
e.target.nextSibling.style.display = 'none';
e.target.src = '/file/minus.png'; e.target.src = '/file/minus.png';
e.target.dataset.open = true; e.target.dataset.open = true;
replies replies = replies.reverse();
.reverse() if (firstPreviewReply) {
.filter(r => r.postId < firstPreviewReply.dataset.postId) replies = replies.filter(r => r.postId < firstPreviewReply.dataset.postId);
.forEach(r => { }
replies.forEach(r => {
newPost(r, { newPost(r, {
insertPoint: parentPost.nextSibling, //anchor before first previewreply insertPoint: firstPreviewReply ? parentPost.nextSibling : parentPost,
insertPosition: 'beforebegin', insertPosition: firstPreviewReply ? 'beforebegin' : 'afterend',
}); });
}); });
}; };

@ -132,7 +132,6 @@ window.addEventListener('addPost', function(e) {
}); });
window.addEventListener('showModal', function(e) { window.addEventListener('showModal', function(e) {
console.log(e.detail, e.detail.modal)
handleDateUpdates(e.detail.modal); handleDateUpdates(e.detail.modal);
}); });

@ -158,11 +158,12 @@ mixin post(post, truncate, manage=false, globalmanage=false, ban=false, overboar
| Message too long. #[a.viewfulltext(href=`${postURL}#${post.postId}`) View the full text] | Message too long. #[a.viewfulltext(href=`${postURL}#${post.postId}`) View the full text]
if post.omittedposts || post.omittedfiles if post.omittedposts || post.omittedfiles
div.cb.mt-5.ml-5 div.cb.mt-5.ml-5
img.dummy-link.expand-omitted(height='18' width='18' data-board=post.board data-thread=post.postId src='/file/plus.png') img.dummy-link.expand-omitted(height='18' width='18' data-shown=post.replies.length data-board=post.board data-thread=post.postId src='/file/plus.png')
- const ompo = post.omittedposts; - const ompo = post.omittedposts;
- const omfi = post.omittedfiles; - const omfi = post.omittedfiles;
| #{ompo} repl#{ompo > 1 ? 'ies' : 'y'} span
| #{omfi > 0 ? ` and ${omfi} file${omfi > 1 ? 's' : ''}` : ''} omitted. | #{ompo} repl#{ompo > 1 ? 'ies' : 'y'}
| #{omfi > 0 ? ` and ${omfi} file${omfi > 1 ? 's' : ''}` : ''} omitted.
| #[a(href=postURL) View the full thread] | #[a(href=postURL) View the full thread]
if post.previewbacklinks != null if post.previewbacklinks != null
if post.previewbacklinks.length > 0 if post.previewbacklinks.length > 0

Loading…
Cancel
Save