178 lines
10 KiB
Plaintext
178 lines
10 KiB
Plaintext
<!-- Quick Tips Box -->
|
|
<div class="bg-rules-bg p-4 rounded mb-4 text-primary">
|
|
<p><strong>Quick Tips:</strong> Keep it brief, keep it real. Share your desk moments, finds, or frustrations. Upvote what resonates!</p>
|
|
</div>
|
|
|
|
<!-- Filter and Sort Controls -->
|
|
<div class="mb-6 pb-4 bg-gray-100 rounded-md">
|
|
<div class="flex flex-col sm:flex-row justify-between space-y-4 sm:space-y-0">
|
|
<!-- Filter by Type -->
|
|
<div class="filter-controls flex flex-col space-y-3 sm:flex-row sm:space-y-0 sm:space-x-2 sm:items-center">
|
|
<button data-filter-type="all" class="filter-btn active w-full sm:w-auto flex items-center justify-center space-x-2 p-3 border-2 border-gray-300 rounded-md cursor-pointer hover:border-primary transition-colors duration-150 ease-in-out" title="All">
|
|
<i class="fas fa-list fa-fw text-primary"></i> <span class="text-sm font-action font-medium text-primary">All</span>
|
|
</button>
|
|
<button data-filter-type="win" class="filter-btn w-full sm:w-auto flex items-center justify-center space-x-2 p-3 border-2 border-gray-300 rounded-md cursor-pointer hover:border-primary transition-colors duration-150 ease-in-out" title="Wins">
|
|
<img src="/assets/images/icon_win.png" alt="Win" class="w-5 h-5 object-contain inline-block"> <span class="text-sm font-action font-medium text-primary">Wins</span>
|
|
</button>
|
|
<button data-filter-type="frustration" class="filter-btn w-full sm:w-auto flex items-center justify-center space-x-2 p-3 border-2 border-gray-300 rounded-md cursor-pointer hover:border-primary transition-colors duration-150 ease-in-out" title="Frustrations">
|
|
<img src="/assets/images/icon_frustrated.png" alt="Frustration" class="w-5 h-5 object-contain inline-block"> <span class="text-sm font-action font-medium text-primary">Frustrations</span>
|
|
</button>
|
|
<button data-filter-type="weird" class="filter-btn w-full sm:w-auto flex items-center justify-center space-x-2 p-3 border-2 border-gray-300 rounded-md cursor-pointer hover:border-primary transition-colors duration-150 ease-in-out" title="Weird">
|
|
<img src="/assets/images/icon_weird.png" alt="Weird" class="w-5 h-5 object-contain inline-block"> <span class="text-sm font-action font-medium text-primary">Weird</span>
|
|
</button>
|
|
</div>
|
|
|
|
<!-- Sort By Dropdown -->
|
|
<div class="sort-controls flex items-center space-x-2">
|
|
<label for="sort-select" class="text-sm font-medium text-gray-700">Sort by:</label>
|
|
<select id="sort-select" name="sort_by" class="sort-select text-sm font-action bg-white border border-gray-300 rounded-md px-3 py-1.5 focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary cursor-pointer">
|
|
<option value="new" selected>Newest</option>
|
|
<option value="new" selected>Nearby</option>
|
|
<option value="upvotes">Most Upvotes</option>
|
|
<option value="comments">Most Comments</option>
|
|
<!-- Add other options like 'today', 'nearby' here if data/logic becomes available -->
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Post List Container -->
|
|
<div id="post-list-container" class="post-list space-y-4">
|
|
{% assign sorted_posts = site.posts | sort: 'date' | reverse %}
|
|
{% for post in sorted_posts %}
|
|
<div class="post-item mb-4" data-type="{{ post.type | default: 'unknown' }}" data-date="{{ post.date | date_to_xmlschema }}" data-upvotes="{{ post.upvotes | default: 0 }}" data-comments="{{ post.comments_count | default: 0 }}">
|
|
<article class="flex flex-col md:flex-row items-start">
|
|
<div class="flex-1 text-left">
|
|
<div>
|
|
<!-- Post Title -->
|
|
<div class="flex items-center space-x-2 mb-0.5">
|
|
<p class="mt-0 mb-0">
|
|
<strong>
|
|
<a href="{{ post.url }}" class="text-text-title font-bold text-md md:text-sm hover:underline">
|
|
{{ post.title }}
|
|
</a>
|
|
</strong>
|
|
</p>
|
|
</div>
|
|
|
|
<!-- Post Metadata -->
|
|
<div class="mt-2 mb-1 text-sm flex flex-col md:flex-row items-start md:items-center md:space-x-2">
|
|
<div class="flex items-start space-x-2 mb-2 md:mb-0">
|
|
<span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center cursor-pointer hover:bg-link-hover">
|
|
<i class="fa-solid fa-arrow-up mr-1"></i> {{ post.upvotes }}
|
|
</span>
|
|
<span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center cursor-pointer hover:bg-link-hover">
|
|
<a href="/reply/"><i class="fas fa-reply mr-1"></i> REPLY</a>
|
|
</span>
|
|
<span class="bg-gray-200 text-gray-700 text-xs font-action px-4 py-2 rounded-full flex items-center cursor-pointer hover:bg-link-hover">
|
|
<i class="fas fa-comment mr-1"></i> {{ post.comments_count }}
|
|
</span>
|
|
</div>
|
|
<small class="text-sm font-action">
|
|
<a href="/user/" class="text-sm hover:underline">{{ post.author }}</a>
|
|
<span class="text-text-muted text-sm opacity-75">{{ post.date | date: "%d %b %Y" }}</span>
|
|
</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</article>
|
|
<hr class="border-border-light my-4">
|
|
</div>
|
|
{% endfor %}
|
|
</div>
|
|
|
|
<!-- More Link -->
|
|
<div class="pt-2">
|
|
<button type="submit" class="w-full md:w-auto px-6 py-3 bg-primary text-white text-sm font-medium rounded-md hover:bg-primary-dark focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary transition duration-150 ease-in-out font-monda font-action">More</button>
|
|
</div>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
const filterButtons = document.querySelectorAll('.filter-btn');
|
|
const sortSelect = document.getElementById('sort-select'); // Get the select dropdown
|
|
const postListContainer = document.getElementById('post-list-container');
|
|
const postItems = Array.from(postListContainer.querySelectorAll('.post-item')); // Convert NodeList to Array
|
|
|
|
let currentFilter = 'all';
|
|
let currentSort = sortSelect.value; // Default sort from selected option ('new')
|
|
|
|
function applyFiltersAndSorting() {
|
|
// 1. Filter
|
|
const filteredPosts = postItems.filter(post => {
|
|
if (currentFilter === 'all') {
|
|
return true; // Show all posts if filter is 'all'
|
|
}
|
|
return post.dataset.type === currentFilter;
|
|
});
|
|
|
|
// 2. Sort
|
|
filteredPosts.sort((a, b) => {
|
|
if (currentSort === 'new') {
|
|
// Sort by date descending (newest first)
|
|
return new Date(b.dataset.date) - new Date(a.dataset.date);
|
|
} else if (currentSort === 'upvotes') { // Changed from 'top'
|
|
// Sort by upvotes descending (highest first)
|
|
const scoreDiff = parseInt(b.dataset.upvotes) - parseInt(a.dataset.upvotes);
|
|
if (scoreDiff !== 0) {
|
|
return scoreDiff;
|
|
}
|
|
// Secondary sort by date for ties
|
|
return new Date(b.dataset.date) - new Date(a.dataset.date);
|
|
} else if (currentSort === 'comments') {
|
|
// Sort by comments descending (most first)
|
|
const commentDiff = parseInt(b.dataset.comments) - parseInt(a.dataset.comments);
|
|
if (commentDiff !== 0) {
|
|
return commentDiff;
|
|
}
|
|
// Secondary sort by date for ties
|
|
return new Date(b.dataset.date) - new Date(a.dataset.date);
|
|
}
|
|
// Add logic for other sort options like 'today', 'nearby' here if implemented
|
|
return 0; // Default no sort change
|
|
});
|
|
|
|
// 3. Update DOM
|
|
// Hide all posts initially
|
|
postItems.forEach(post => post.style.display = 'none');
|
|
// Clear container and append sorted+filtered posts
|
|
postListContainer.innerHTML = ''; // Clear current posts
|
|
filteredPosts.forEach(post => {
|
|
post.style.display = ''; // Make sure it's visible
|
|
postListContainer.appendChild(post); // Append in sorted order
|
|
});
|
|
|
|
// Update button active states
|
|
filterButtons.forEach(btn => {
|
|
const isActive = btn.dataset.filterType === currentFilter;
|
|
btn.classList.toggle('active', isActive);
|
|
// Apply styles consistent with submit.liquid active state
|
|
if (isActive) {
|
|
btn.classList.add('border-primary', 'bg-primary/10');
|
|
btn.classList.remove('border-gray-300', 'bg-transparent'); // Ensure default border is removed
|
|
} else {
|
|
btn.classList.add('border-gray-300', 'bg-transparent'); // Use bg-transparent or specific default bg
|
|
btn.classList.remove('border-primary', 'bg-primary/10');
|
|
}
|
|
});
|
|
// No active state styling needed for select dropdown itself
|
|
}
|
|
|
|
// Event Listeners for Filter Buttons
|
|
filterButtons.forEach(button => {
|
|
button.addEventListener('click', () => {
|
|
currentFilter = button.dataset.filterType;
|
|
applyFiltersAndSorting();
|
|
});
|
|
});
|
|
|
|
// Event Listener for Sort Dropdown
|
|
sortSelect.addEventListener('change', (event) => {
|
|
currentSort = event.target.value;
|
|
applyFiltersAndSorting();
|
|
});
|
|
|
|
// Initial application of filters and sorting on page load
|
|
applyFiltersAndSorting();
|
|
});
|
|
</script>
|