Spaces:
Sleeping
Sleeping
Commit
·
ecff993
1
Parent(s):
5a653e1
Styling hover
Browse files- app/static/script.js +27 -2
app/static/script.js
CHANGED
|
@@ -77,10 +77,35 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 77 |
console.log(`Rendering essay ${index + 1}:`, essay);
|
| 78 |
const li = document.createElement('li');
|
| 79 |
const promptText = essay.prompt ? essay.prompt : '[No prompt text]';
|
| 80 |
-
const viewCount = essay.view_count ??
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
li.classList.add('cursor-pointer', 'hover:text-orange-700');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
li.addEventListener('click', () => {
|
| 85 |
promptInput.value = essay.prompt;
|
| 86 |
promptInput.dispatchEvent(new Event('input'));
|
|
|
|
| 77 |
console.log(`Rendering essay ${index + 1}:`, essay);
|
| 78 |
const li = document.createElement('li');
|
| 79 |
const promptText = essay.prompt ? essay.prompt : '[No prompt text]';
|
| 80 |
+
const viewCount = essay.view_count ?? 0; // Get view count, default to 0
|
| 81 |
+
|
| 82 |
+
// Create span for prompt text
|
| 83 |
+
const promptSpan = document.createElement('span');
|
| 84 |
+
promptSpan.textContent = promptText;
|
| 85 |
+
|
| 86 |
+
// Create span for view count (initially hidden)
|
| 87 |
+
const viewCountSpan = document.createElement('span');
|
| 88 |
+
viewCountSpan.classList.add('view-count-display', 'ml-2', 'text-gray-500'); // Add styling
|
| 89 |
+
viewCountSpan.textContent = `(Views: ${viewCount})`;
|
| 90 |
+
viewCountSpan.style.display = 'none'; // Hide by default
|
| 91 |
+
|
| 92 |
+
// Append spans to list item
|
| 93 |
+
li.appendChild(promptSpan);
|
| 94 |
+
li.appendChild(viewCountSpan);
|
| 95 |
|
| 96 |
li.classList.add('cursor-pointer', 'hover:text-orange-700');
|
| 97 |
+
|
| 98 |
+
// Event listeners for hover effect
|
| 99 |
+
li.addEventListener('mouseenter', () => {
|
| 100 |
+
if (currentSort.field === 'views') {
|
| 101 |
+
viewCountSpan.style.display = 'inline'; // Show on hover if sorting by views
|
| 102 |
+
}
|
| 103 |
+
});
|
| 104 |
+
|
| 105 |
+
li.addEventListener('mouseleave', () => {
|
| 106 |
+
viewCountSpan.style.display = 'none'; // Always hide when mouse leaves
|
| 107 |
+
});
|
| 108 |
+
|
| 109 |
li.addEventListener('click', () => {
|
| 110 |
promptInput.value = essay.prompt;
|
| 111 |
promptInput.dispatchEvent(new Event('input'));
|