182 lines
10 KiB
Plaintext
182 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 p-4 bg-gray-100 rounded-md">
|
|
<div class="flex flex-col sm:flex-row justify-between items-center 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">
|
|
<span class="text-sm font-medium text-gray-700 mr-2 hidden sm:inline">Show:</span>
|
|
<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 -->
|
|
<div class="sort-controls flex items-center space-x-2">
|
|
<span class="text-sm font-medium text-gray-700 mr-2">Sort by:</span>
|
|
<button data-sort-by="new" class="sort-btn active px-3 py-1 text-sm font-action bg-white border border-gray-300 rounded-md hover:bg-gray-50">New</button>
|
|
<button data-sort-by="top" class="sort-btn px-3 py-1 text-sm font-action bg-white border border-gray-300 rounded-md hover:bg-gray-50">Top</button>
|
|
</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 }}">
|
|
<article class="flex flex-col md:flex-row items-start">
|
|
<div class="flex-1 text-left">
|
|
<div>
|
|
<!-- Icon and Post Title -->
|
|
<div class="flex items-center space-x-2 mb-0.5">
|
|
{% assign post_type = post.type | default: 'unknown' %}
|
|
{% if post_type == "frustration" %}
|
|
<img src="/assets/images/icon_frustrated.png" alt="Frustration" class="w-5 h-5 object-contain flex-shrink-0" title="Frustration">
|
|
{% elsif post_type == "weird" %}
|
|
<img src="/assets/images/icon_weird.png" alt="Weird" class="w-5 h-5 object-contain flex-shrink-0" title="Weird">
|
|
{% elsif post_type == "win" %}
|
|
<img src="/assets/images/icon_win.png" alt="Win" class="w-5 h-5 object-contain flex-shrink-0" title="Win">
|
|
{% endif %}
|
|
<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">
|
|
<i class="fas fa-reply mr-1"></i> REPLY
|
|
</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="#" 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 sortButtons = document.querySelectorAll('.sort-btn');
|
|
const postListContainer = document.getElementById('post-list-container');
|
|
const postItems = Array.from(postListContainer.querySelectorAll('.post-item')); // Convert NodeList to Array
|
|
|
|
let currentFilter = 'all';
|
|
let currentSort = 'new'; // Default sort
|
|
|
|
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 === 'top') {
|
|
// Sort by upvotes descending (highest first)
|
|
// Add secondary sort by date for ties
|
|
const scoreDiff = parseInt(b.dataset.upvotes) - parseInt(a.dataset.upvotes);
|
|
if (scoreDiff !== 0) {
|
|
return scoreDiff;
|
|
}
|
|
return new Date(b.dataset.date) - new Date(a.dataset.date); // Newest first if votes are equal
|
|
}
|
|
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');
|
|
}
|
|
});
|
|
sortButtons.forEach(btn => {
|
|
btn.classList.toggle('active', btn.dataset.sortBy === currentSort);
|
|
if (btn.dataset.sortBy === currentSort) {
|
|
btn.classList.add('bg-blue-200', 'border-blue-400'); // Example active style
|
|
} else {
|
|
btn.classList.remove('bg-blue-200', 'border-blue-400');
|
|
}
|
|
});
|
|
}
|
|
|
|
// Event Listeners for Filter Buttons
|
|
filterButtons.forEach(button => {
|
|
button.addEventListener('click', () => {
|
|
currentFilter = button.dataset.filterType;
|
|
applyFiltersAndSorting();
|
|
});
|
|
});
|
|
|
|
// Event Listeners for Sort Buttons
|
|
sortButtons.forEach(button => {
|
|
button.addEventListener('click', () => {
|
|
currentSort = button.dataset.sortBy;
|
|
applyFiltersAndSorting();
|
|
});
|
|
});
|
|
|
|
// Initial application of filters and sorting on page load
|
|
applyFiltersAndSorting();
|
|
});
|
|
</script>
|