Files
project-behind-the-desk/_includes/post_list.liquid
T

171 lines
9.9 KiB
Plaintext

<!-- Quick Tips Box -->
<div id="quick-tips-box" class="relative p-4 rounded mb-4 border border-gray-300 text-gray-700">
<button
type="button"
aria-label="Close quick tips"
onclick="document.getElementById('quick-tips-box').style.display='none'"
class="absolute top-2 right-3 text-gray-500 hover:text-gray-700 focus:outline-none focus:ring-1 focus:ring-gray-500 rounded-md p-1">
<i class="fas fa-times"></i>
</button>
<p class="mr-8"> <!-- Ensure text doesn't overlap with the close button -->
<strong>Quick Tips:</strong> Keep it brief, keep it real. Share your desk moments, finds, or frustrations. Upvote what resonates!
</p>
</div>
{% assign filter_type = page.filter_type | default: 'all' %}
{% assign sort_by = page.sort_by | default: 'new' %}
<!-- Filter and Sort Controls -->
<div class="mb-6 bg-gray-100 rounded-md">
<div class="flex flex-row flex-wrap items-center justify-between gap-2">
<!-- Filter by Type -->
<div class="filter-controls flex items-center flex-wrap gap-2">
<a href="/" class="filter-btn flex items-center justify-center p-2 border-2 {% if filter_type == 'all' %}border-primary bg-primary/10{% else %}border-gray-300{% endif %} rounded-md hover:border-primary transition-colors">
<i class="fas fa-list fa-fw text-primary sm:mr-2"></i>
<span class="text-sm font-action font-medium text-primary hidden sm:inline">All</span>
</a>
<a href="/win/" class="filter-btn flex items-center justify-center p-2 border-2 {% if filter_type == 'win' %}border-primary bg-primary/10{% else %}border-gray-300{% endif %} rounded-md hover:border-primary transition-colors">
<img src="/assets/images/icon_win.png" alt="Win" class="w-5 h-5 object-contain inline-block sm:mr-2">
<span class="text-sm font-action font-medium text-primary hidden sm:inline">Wins</span>
</a>
<a href="/frustration/" class="filter-btn flex items-center justify-center p-2 border-2 {% if filter_type == 'frustration' %}border-primary bg-primary/10{% else %}border-gray-300{% endif %} rounded-md hover:border-primary transition-colors">
<img src="/assets/images/icon_frustrated.png" alt="Frustration" class="w-5 h-5 object-contain inline-block sm:mr-2">
<span class="text-sm font-action font-medium text-primary hidden sm:inline">Frustrations</span>
</a>
<a href="/weird/" class="filter-btn flex items-center justify-center p-2 border-2 {% if filter_type == 'weird' %}border-primary bg-primary/10{% else %}border-gray-300{% endif %} rounded-md hover:border-primary transition-colors">
<img src="/assets/images/icon_weird.png" alt="Weird" class="w-5 h-5 object-contain inline-block sm:mr-2">
<span class="text-sm font-action font-medium text-primary hidden sm:inline">Weird</span>
</a>
</div>
<!-- Sort Dropdown -->
<div class="sort-controls flex items-center space-x-1 sm:space-x-2">
<label class="text-sm font-medium text-gray-700 hidden sm:inline-block">Sort by:</label>
<div class="relative" id="custom-sort-dropdown">
<button type="button" onclick="toggleSortDropdown()" class="flex items-center justify-between w-full sm:w-auto text-left 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">
<span id="sort-selected-text">
{% if sort_by == 'new' %}Newest
{% elsif sort_by == 'nearby' %}Nearby
{% elsif sort_by == 'upvotes' %}Most Upvotes
{% elsif sort_by == 'comments' %}Most Comments
{% else %}Newest{% endif %}
</span>
<i id="sort-arrow-icon" class="fas fa-chevron-down ml-2 text-xs text-gray-500"></i>
</button>
<div id="sort-options-panel" class="absolute z-10 left-0 mt-1 w-full sm:w-auto sm:min-w-max bg-white border border-gray-300 rounded-md shadow-lg hidden">
<button type="button" onclick="selectSortOption('new', 'Newest')" class="block w-full text-left px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 hover:text-gray-900">Newest</button>
<button type="button" onclick="selectSortOption('nearby', 'Nearby')" class="block w-full text-left px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 hover:text-gray-900">Nearby</button>
<button type="button" onclick="selectSortOption('upvotes', 'Most Upvotes')" class="block w-full text-left px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 hover:text-gray-900">Most Upvotes</button>
<button type="button" onclick="selectSortOption('comments', 'Most Comments')" class="block w-full text-left px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 hover:text-gray-900">Most Comments</button>
</div>
</div>
</div>
</div>
</div>
<div id="result-count-container" class="mb-4 text-sm text-primary">
<p>
Showing <span id="results-count" class="font-semibold">20</span> results for <span class="font-semibold">"query"</span>.
</p>
</div>
<!-- Post List -->
<div id="post-list-container" class="post-list space-y-4">
{% assign posts = site.posts %}
{% if filter_type != 'all' %}
{% assign posts = posts | where: 'type', filter_type %}
{% endif %}
{% assign posts = posts | sort: 'date' | reverse %}
{% if posts == empty %}
<div class="text-center text-gray-500 font-action py-10">
<p>No results found for this filter.</p>
</div>
{% else %}
{% for post in posts %}
<div class="post-item mb-4">
<article class="flex flex-col md:flex-row items-start">
<div class="flex-1 text-left">
<!-- 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>
</article>
<hr class="border-border-light my-4">
</div>
{% endfor %}
{% endif %}
</div>
<!-- More Button -->
{% if posts != empty %}
<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>
{% endif %}
<script>
function toggleSortDropdown() {
const panel = document.getElementById('sort-options-panel');
const arrowIcon = document.getElementById('sort-arrow-icon');
panel.classList.toggle('hidden');
if (arrowIcon) {
arrowIcon.classList.toggle('fa-chevron-down');
arrowIcon.classList.toggle('fa-chevron-up');
}
}
function selectSortOption(value, text) {
document.getElementById('sort-selected-text').innerText = text;
const panel = document.getElementById('sort-options-panel');
const arrowIcon = document.getElementById('sort-arrow-icon');
panel.classList.add('hidden');
if (arrowIcon) {
arrowIcon.classList.remove('fa-chevron-up');
arrowIcon.classList.add('fa-chevron-down');
}
// Placeholder for actual sort logic.
// You would typically redirect or make an AJAX call here.
// Example: window.location.href = window.location.pathname + '?sort=' + value + '&filter={{ filter_type }}';
console.log('Selected sort: ' + value);
}
// Close dropdown if clicked outside
window.addEventListener('click', function(event) {
const dropdown = document.getElementById('custom-sort-dropdown');
const panel = document.getElementById('sort-options-panel');
if (dropdown && panel && !dropdown.contains(event.target) && !panel.classList.contains('hidden')) {
toggleSortDropdown(); // Reuse toggle to also fix arrow
}
});
</script>