diff --git a/app/community/routes.py b/app/community/routes.py index 4b5ca040..e1cbb069 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -15,7 +15,7 @@ from app.models import User, Community, CommunityMember, CommunityJoinRequest, C PostReplyVote, PostVote from app.community import bp from app.utils import get_setting, render_template, allowlist_html, markdown_to_html, validation_required, \ - shorten_string, markdown_to_text + shorten_string, markdown_to_text, domain_from_url @bp.route('/add_local', methods=['GET', 'POST']) @@ -205,6 +205,9 @@ def add_post(actor): post.title = form.link_title.data post.url = form.link_url.data post.type = POST_TYPE_LINK + domain = domain_from_url(form.link_url.data, create=True) + domain.post_count += 1 + post.domain = domain elif form.type.data == 'image': post.title = form.image_title.data post.type = POST_TYPE_IMAGE diff --git a/app/models.py b/app/models.py index a5677c9b..a04401ff 100644 --- a/app/models.py +++ b/app/models.py @@ -345,6 +345,7 @@ class Post(db.Model): search_vector = db.Column(TSVectorType('title', 'body')) image = db.relationship(File, foreign_keys=[image_id], cascade="all, delete") + domain = db.relationship('Domain', foreign_keys=[domain_id]) @classmethod def get_by_ap_id(cls, ap_id): diff --git a/app/static/js/scripts.js b/app/static/js/scripts.js index 88bef557..a1116883 100644 --- a/app/static/js/scripts.js +++ b/app/static/js/scripts.js @@ -12,6 +12,32 @@ window.addEventListener("load", function () { setupHideButtons(); }); +function collapseReply(comment_id) { + const reply = document.getElementById('comment_' + comment_id); + let isHidden = false; + if(reply) { + const hidables = parentElement.querySelectorAll('.hidable'); + + hidables.forEach(hidable => { + hidable.style.display = isHidden ? 'block' : 'none'; + }); + + const moreHidables = parentElement.parentElement.querySelectorAll('.hidable'); + moreHidables.forEach(hidable => { + hidable.style.display = isHidden ? 'block' : 'none'; + }); + + // Toggle the content of hideEl + if (isHidden) { + hideEl.innerHTML = "[-] hide"; + } else { + hideEl.innerHTML = "[+] show"; + } + + isHidden = !isHidden; // Toggle the state + } +} + // every element with the 'confirm_first' class gets a popup confirmation dialog function setupConfirmFirst() { const show_first = document.querySelectorAll('.confirm_first'); @@ -123,6 +149,30 @@ function setupHideButtons() { isHidden = !isHidden; // Toggle the state }); }); + + if(toBeHidden) { + toBeHidden.forEach((arrayElement) => { + // Build the ID of the outer div + const divId = "comment_" + arrayElement; + + // Access the outer div by its ID + const commentDiv = document.getElementById(divId); + + if (commentDiv) { + // Access the inner div with class "hide_button" inside the outer div + const hideButton = commentDiv.getElementsByClassName("hide_button")[0]; + + if (hideButton) { + // Programmatically trigger a click event on the "hide_button" div + hideButton.click(); + } else { + console.log(`"hide_button" not found in ${divId}`); + } + } else { + console.log(`Div with ID ${divId} not found`); + } + }); + } } function titleToURL(title) { diff --git a/app/static/styles.css b/app/static/styles.css index 3f0b9775..5523abd4 100644 --- a/app/static/styles.css +++ b/app/static/styles.css @@ -358,4 +358,12 @@ nav.navbar { background: whitesmoke url(/static/images/collapsed.gif) no-repeat center left; } +.domain_link { + color: #bbb; + font-size: 73%; +} +.domain_link a { + color: #777; +} + /*# sourceMappingURL=styles.css.map */ diff --git a/app/static/styles.scss b/app/static/styles.scss index f05c772e..68b9fa95 100644 --- a/app/static/styles.scss +++ b/app/static/styles.scss @@ -120,4 +120,12 @@ nav.navbar { .coolfieldset.collapsed legend{ background: whitesmoke url(/static/images/collapsed.gif) no-repeat center left; +} + +.domain_link { + color: $grey; + font-size: 73%; + a { + color: $dark-grey; + } } \ No newline at end of file diff --git a/app/templates/community/_post_full.html b/app/templates/community/_post_full.html index 5615d996..e5585304 100644 --- a/app/templates/community/_post_full.html +++ b/app/templates/community/_post_full.html @@ -14,11 +14,9 @@
{{ post.url|shorten_url }} - {% if post.type == post_type_link %} - (domain) - {% endif %} -
+{{ post.url|shorten_url }} + +
{% endif %}submitted {{ moment(post.posted_at).fromNow() }} by {{ render_username(post.author) }}
@@ -48,9 +46,6 @@ {% if post.url %}{{ post.url|shorten_url }} - {% if post.type == post_type_link %} - (domain) - {% endif %}
{% endif %}submitted {{ moment(post.posted_at).fromNow() }} by diff --git a/app/templates/community/_post_teaser.html b/app/templates/community/_post_teaser.html index 8cafb17b..29483159 100644 --- a/app/templates/community/_post_teaser.html +++ b/app/templates/community/_post_teaser.html @@ -8,8 +8,11 @@