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) {
const newPost = e.detail.post;
console.log(newPost)
if (anyFilterMatches(newPost)) {
newPost.classList.add('hidden');
}

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

@ -132,7 +132,6 @@ window.addEventListener('addPost', function(e) {
});
window.addEventListener('showModal', function(e) {
console.log(e.detail, 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]
if post.omittedposts || post.omittedfiles
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 omfi = post.omittedfiles;
| #{ompo} repl#{ompo > 1 ? 'ies' : 'y'}
| #{omfi > 0 ? ` and ${omfi} file${omfi > 1 ? 's' : ''}` : ''} omitted.
span
| #{ompo} repl#{ompo > 1 ? 'ies' : 'y'}
| #{omfi > 0 ? ` and ${omfi} file${omfi > 1 ? 's' : ''}` : ''} omitted.
| #[a(href=postURL) View the full thread]
if post.previewbacklinks != null
if post.previewbacklinks.length > 0

Loading…
Cancel
Save