Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/test_back_to_top.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.test import Client, TestCase
from django.urls import reverse


class BackToTopButtonTests(TestCase):
def setUp(self):
self.client = Client()

def test_button_present_on_homepage(self):
"""The base template should include the back-to-top button element."""
response = self.client.get(reverse("index"))
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'id="back-to-top-btn"')
66 changes: 66 additions & 0 deletions web/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,73 @@ <h4 class="font-medium text-sm mb-2 text-gray-700 dark:text-gray-300">SUBSCRIBE
}
});
}

// Back to Top Button functionality
document.addEventListener('DOMContentLoaded', function () {

const backToTopBtn = document.getElementById('back-to-top-btn');
if (!backToTopBtn) return;

// Extracted visibility toggle
function updateBackToTopVisibility() {
if (window.scrollY > 300) {
backToTopBtn.classList.remove(
'opacity-0',
'invisible',
'pointer-events-none'
);
backToTopBtn.classList.add('opacity-100', 'visible');
} else {
backToTopBtn.classList.add(
'opacity-0',
'invisible',
'pointer-events-none'
);
backToTopBtn.classList.remove('opacity-100', 'visible');
}
}

// Initialize correctly on page load
updateBackToTopVisibility();

// Reuse same logic on scroll
window.addEventListener('scroll', updateBackToTopVisibility, {
passive: true
});

// Scroll action
backToTopBtn.addEventListener('click', function (e) {
e.preventDefault();
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});

});
Comment on lines +1131 to +1174

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

JavaScript indentation is inconsistent with the rest of the file.

Other script blocks in this file (e.g., lines 25–86, 1086–1130) use 8-space indentation. The new back-to-top code has no indentation, making the file inconsistent.

🔧 Proposed indentation fix
-        // Back to Top Button functionality
-document.addEventListener('DOMContentLoaded', function () {
-
-    const backToTopBtn = document.getElementById('back-to-top-btn');
-    if (!backToTopBtn) return;
-
-    // Extracted visibility toggle
-    function updateBackToTopVisibility() {
-        if (window.scrollY > 300) {
+        // Back to Top Button functionality
+        document.addEventListener('DOMContentLoaded', function () {
+            const backToTopBtn = document.getElementById('back-to-top-btn');
+            if (!backToTopBtn) return;
+
+            // Extracted visibility toggle
+            function updateBackToTopVisibility() {
+                if (window.scrollY > 300) {

Apply consistent 8-space indentation throughout the entire block (lines 1132–1174).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@web/templates/base.html` around lines 1131 - 1174, The new back-to-top script
block is misindented; reformat the entire DOMContentLoaded handler so it uses
the same 8-space indentation style as the rest of the file—indent the
document.addEventListener('DOMContentLoaded', ... ), the const backToTopBtn
declaration, the updateBackToTopVisibility() function body, the
window.addEventListener('scroll', updateBackToTopVisibility, { passive: true }),
and the backToTopBtn.addEventListener('click', ...) handler to match the
existing 8-space indentation used elsewhere.


</script>
<!-- Back to Top Button -->
<button id="back-to-top-btn"
aria-label="Scroll to top"
class="fixed bottom-8 right-8 z-[9999]
flex items-center justify-center
w-14 h-14 md:w-16 md:h-16
rounded-full
bg-teal-300 hover:bg-teal-400
dark:bg-teal-400 dark:hover:bg-teal-500
text-white shadow-lg
transition-all duration-300

focus:outline-none
focus-visible:ring-4
focus-visible:ring-teal-500/50
focus-visible:ring-offset-2
dark:focus-visible:ring-offset-gray-900

opacity-0 invisible pointer-events-none">
<i class="fas fa-arrow-up text-lg"></i>
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
</button>
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
{% block extra_js %}
{% endblock extra_js %}
</body>
Expand Down