From 4cd94ecf4c2e9233d556cf5a64ec074c1efd2629 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sun, 15 Oct 2023 19:36:14 +1300 Subject: [PATCH] comment replies and large comment truncating --- app/static/js/scripts.js | 57 ++++++++++++++++++++++++++ app/static/scss/_typography.scss | 21 ++++++++++ app/static/structure.css | 47 ++++++++++++++++++++- app/static/structure.scss | 31 +++++++++++++- app/static/styles.css | 21 ++++++++++ app/templates/community/community.html | 4 +- app/templates/community/post.html | 35 ++++++++++------ 7 files changed, 199 insertions(+), 17 deletions(-) diff --git a/app/static/js/scripts.js b/app/static/js/scripts.js index 2a1acbf0..b6527e60 100644 --- a/app/static/js/scripts.js +++ b/app/static/js/scripts.js @@ -1,14 +1,45 @@ // fires after DOM is ready for manipulation document.addEventListener("DOMContentLoaded", function () { setupCommunityNameInput(); + setupShowMoreLinks(); }); // fires after all resources have loaded, including stylesheets and js files window.addEventListener("load", function () { setupPostTypeTabs(); // when choosing the type of your new post, store the chosen tab in a hidden field so the backend knows which fields to check + setupHideButtons(); }); +function setupShowMoreLinks() { + const comments = document.querySelectorAll('.comment'); + + comments.forEach(comment => { + const content = comment.querySelector('.comment_body'); + if (content && content.clientHeight > 400) { + content.style.overflow = 'hidden'; + content.style.maxHeight = '400px'; + const showMoreLink = document.createElement('a'); + showMoreLink.classList.add('show-more'); + showMoreLink.classList.add('hidable'); + showMoreLink.innerHTML = ''; + showMoreLink.href = '#'; + showMoreLink.addEventListener('click', function(event) { + event.preventDefault(); + content.classList.toggle('expanded'); + if (content.classList.contains('expanded')) { + content.style.overflow = 'visible'; + content.style.maxHeight = ''; + showMoreLink.innerHTML = ''; + } else { + content.style.overflow = 'hidden'; + showMoreLink.innerHTML = ''; + } + }); + content.insertAdjacentElement('afterend', showMoreLink); + } + }); +} function setupCommunityNameInput() { var communityNameInput = document.getElementById('community_name'); @@ -50,6 +81,32 @@ function setupPostTypeTabs() { } +function setupHideButtons() { + const hideEls = document.querySelectorAll('.hide_button'); + hideEls.forEach(hideEl => { + let isHidden = false; + + hideEl.addEventListener('click', event => { + event.preventDefault(); + const parentElement = hideEl.parentElement; + const hidables = parentElement.querySelectorAll('.hidable'); + + hidables.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 + }); + }); +} + function titleToURL(title) { // Convert the title to lowercase and replace spaces with hyphens return title.toLowerCase().replace(/\s+/g, '-'); diff --git a/app/static/scss/_typography.scss b/app/static/scss/_typography.scss index 1b2f1b0c..c8324d72 100644 --- a/app/static/scss/_typography.scss +++ b/app/static/scss/_typography.scss @@ -145,6 +145,27 @@ content: "\e90c"; } +.fe-reply { + position: relative; + top: 2px; +} + +.fe-reply::before { + content: "\e991"; +} + +.fe-report::before { + content: "\e967"; +} + +.fe-angles-down::before { + content: "\e932"; +} + +.fe-angles-up::before { + content: "\e935"; +} + a.no-underline { text-decoration: none; &:hover { diff --git a/app/static/structure.css b/app/static/structure.css index 5fc8ea26..503612fd 100644 --- a/app/static/structure.css +++ b/app/static/structure.css @@ -144,6 +144,27 @@ nav, etc which are used site-wide */ content: "\e90c"; } +.fe-reply { + position: relative; + top: 2px; +} + +.fe-reply::before { + content: "\e991"; +} + +.fe-report::before { + content: "\e967"; +} + +.fe-angles-down::before { + content: "\e932"; +} + +.fe-angles-up::before { + content: "\e935"; +} + a.no-underline { text-decoration: none; } @@ -345,6 +366,24 @@ fieldset legend { clear: both; margin-bottom: 20px; } +.comment .comment_body { + overflow: hidden; + position: relative; +} +.comment .comment_body.expanded { + max-height: none; +} +.comment .comment_body.expanded .show-more { + display: none; +} +.comment .show-more { + text-decoration: none; + display: block; + text-align: center; + background-color: #777; + color: white; + margin-bottom: 15px; +} .comment .comment_author img { width: 20px; height: 20px; @@ -352,7 +391,7 @@ fieldset legend { .comment .hide_button { float: right; display: block; - width: 60px; + width: 68px; padding: 5px; } .comment .hide_button a { @@ -395,5 +434,11 @@ fieldset legend { .comment .voting_buttons a { text-decoration: none; } +.comment .comment_actions { + margin-top: -10px; +} +.comment .comment_actions a { + text-decoration: none; +} /*# sourceMappingURL=structure.css.map */ diff --git a/app/static/structure.scss b/app/static/structure.scss index 2ce49242..b707b375 100644 --- a/app/static/structure.scss +++ b/app/static/structure.scss @@ -140,6 +140,28 @@ nav, etc which are used site-wide */ clear: both; margin-bottom: 20px; + .comment_body { + overflow: hidden; + position: relative; + + &.expanded { + max-height: none; + + .show-more { + display: none; + } + } + } + + .show-more { + text-decoration: none; + display: block; + text-align: center; + background-color: $dark-grey; + color: white; + margin-bottom: 15px; + } + .comment_author { img { width: 20px; @@ -150,7 +172,7 @@ nav, etc which are used site-wide */ .hide_button { float: right; display: block; - width: 60px; + width: 68px; padding: 5px; a { @@ -203,4 +225,11 @@ nav, etc which are used site-wide */ text-decoration: none; } } + + .comment_actions { + margin-top: -10px; + a { + text-decoration: none; + } + } } \ No newline at end of file diff --git a/app/static/styles.css b/app/static/styles.css index 112f60dc..d09aaaea 100644 --- a/app/static/styles.css +++ b/app/static/styles.css @@ -143,6 +143,27 @@ content: "\e90c"; } +.fe-reply { + position: relative; + top: 2px; +} + +.fe-reply::before { + content: "\e991"; +} + +.fe-report::before { + content: "\e967"; +} + +.fe-angles-down::before { + content: "\e932"; +} + +.fe-angles-up::before { + content: "\e935"; +} + a.no-underline { text-decoration: none; } diff --git a/app/templates/community/community.html b/app/templates/community/community.html index a0185c5e..73a91880 100644 --- a/app/templates/community/community.html +++ b/app/templates/community/community.html @@ -3,7 +3,7 @@ {% block app_content %}
-
+
{% if community.header_image() != '' %}
-
+
diff --git a/app/templates/community/post.html b/app/templates/community/post.html index 1508287f..900fca97 100644 --- a/app/templates/community/post.html +++ b/app/templates/community/post.html @@ -3,7 +3,7 @@ {% block app_content %}
-
+
{% if post.image_id %}
@@ -70,7 +70,9 @@ {% if post.comments_enabled %}
- {{ render_form(form) }} +
+ {{ render_form(form) }} +

@@ -86,7 +88,7 @@ {% include "community/_voting_buttons.html" %} {% endwith %}
- +
{% if comment['comment'].author.avatar_id %} @@ -94,17 +96,24 @@ {% endif %} {{ comment['comment'].author.user_name}} + {% if comment['comment'].author.id == post.author.id%}[S]{% endif %} {{ moment(comment['comment'].posted_at).fromNow(refresh=True) }}
- {{ comment['comment'].body_html | safe }} +
+ {{ comment['comment'].body_html | safe }} +
+
+ reply +
+ {% if comment['replies'] %} +
+ {% for reply in comment['replies'] %} + {{ render_comment(reply) | safe }} + {% endfor %} +
+ {% endif %}
- {% if comment['replies'] %} -
- {% for reply in comment['replies'] %} - {{ render_comment(reply) | safe }} - {% endfor %} -
- {% endif %} + {% endmacro %}
@@ -116,7 +125,7 @@
-
+
@@ -128,7 +137,7 @@ {% endif %}