remotes/1693045480750635534/spooky-22
Aevann1 2021-12-06 00:52:39 +02:00
parent 99d6ec18f8
commit 3d971c1368
3 changed files with 36 additions and 38 deletions

View File

@ -190,7 +190,7 @@ def post_id(pid, anything=None, v=None):
offset = 0
if post.comment_count > 60:
if len(comments) > 60:
comments2 = []
count = 0
if post.created_utc > 1638672040:
@ -229,6 +229,7 @@ def post_id(pid, anything=None, v=None):
@limiter.limit("1/second")
@auth_desired
def viewmore(v, pid, sort, offset):
offset = int(offset)
if v:
votes = g.db.query(CommentVote).filter_by(user_id=v.id).subquery()
@ -283,7 +284,7 @@ def viewmore(v, pid, sort, offset):
elif sort == "bottom":
comments = comments.order_by(Comment.upvotes - Comment.downvotes)
if offset: comments = comments.offset(int(offset))
comments = comments.offset(offset)
comments = [c[0] for c in comments.all()]
else:
@ -300,11 +301,32 @@ def viewmore(v, pid, sort, offset):
elif sort == "bottom":
comments = comments.order_by(Comment.upvotes - Comment.downvotes)
if offset: comments = comments.offset(int(offset))
comments = comments.offset(offset)
comments = comments.all()
return render_template("comments.html", v=v, comments=comments, render_replies=True)
if len(comments) > 60:
comments2 = []
count = 0
post = get_post(pid, v=v)
if post.created_utc > 1638672040:
for comment in comments:
comments2.append(comment)
count += g.db.query(Comment.id).filter_by(parent_submission=post.id, top_comment_id=comment.id).count() + 1
offset += 1
if count > 50: break
else:
for comment in comments:
comments2.append(comment)
count += g.db.query(Comment.id).filter_by(parent_submission=post.id, parent_comment_id=comment.id).count() + 1
offset += 1
if count > 10: break
if len(comments) == len(comments2): offset = None
comments = comments2
else: offset = None
return render_template("comments.html", v=v, comments=comments, render_replies=True, pid=pid, sort=sort, offset=offset)
@app.post("/edit_post/<pid>")

View File

@ -800,4 +800,12 @@
{% endif %}
</script>
{% if offset %}
{% if p %}
{% set pid = p.id %}
{% endif %}
<br>
<div id="viewmore-{{offset}}"><button id="viewbtn" class="btn btn-primary" onclick="viewmore({{pid}},'{{sort}}',{{offset}})">VIEW MORE COMMENTS</a></div>
{% endif %}
</body>

View File

@ -825,39 +825,7 @@
</div>
{% if offset %}
<script>
function viewmore() {
btn = document.getElementById("viewbtn");
btn.disabled = true;
btn.innerHTML = "Requesting...";
var form = new FormData();
var xhr = new XMLHttpRequest();
xhr.open("post", "/viewmore/{{p.id}}/{{sort}}/{{offset}}");
xhr.withCredentials=true;
xhr.onload=function(){
if (xhr.status==200) {
document.getElementById("viewmore").innerHTML = xhr.response.replace(/data-src/g, 'src').replace(/data-cfsrc/g, 'src').replace(/style="display:none;visibility:hidden;"/g, '');
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
tooltipTriggerList.map(function(element){
return new bootstrap.Tooltip(element);
});
const popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'));
const popoverList = popoverTriggerList.map(function(popoverTriggerEl) {
const popoverId = popoverTriggerEl.getAttribute('data-content-id');
const contentEl = document.getElementById(popoverId).innerHTML;
return new bootstrap.Popover(popoverTriggerEl, {
content: contentEl,
html: true,
});
})
}
}
xhr.send(form)
}
</script>
<br>
<div id="viewmore"><button id="viewbtn" class="btn btn-primary" onclick="viewmore()">VIEW MORE COMMENTS</a></div>
<script src="/assets/js/viewmore.js?v=1"></script>
{% endif %}