feat: Implement custom sort dropdown for mobile layout
This commit is contained in:
1 parent
1994d19fae
commit
9876a05e5b
1 file changed
+55
-7
@@ -40,13 +40,25 @@
|
|||||||
|
|
||||||
<!-- Sort Dropdown -->
|
<!-- Sort Dropdown -->
|
||||||
<div class="sort-controls flex items-center space-x-1 sm:space-x-2">
|
<div class="sort-controls flex items-center space-x-1 sm:space-x-2">
|
||||||
<label for="sort-select" class="text-sm font-medium text-gray-700 hidden sm:inline-block">Sort by:</label>
|
<label class="text-sm font-medium text-gray-700 hidden sm:inline-block">Sort by:</label>
|
||||||
<select id="sort-select" 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">
|
<div class="relative" id="custom-sort-dropdown">
|
||||||
<option value="new" selected>Newest</option>
|
<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">
|
||||||
<option value="nearby">Nearby</option>
|
<span id="sort-selected-text">
|
||||||
<option value="upvotes">Most Upvotes</option>
|
{% if sort_by == 'new' %}Newest
|
||||||
<option value="comments">Most Comments</option>
|
{% elsif sort_by == 'nearby' %}Nearby
|
||||||
</select>
|
{% 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>
|
||||||
</div>
|
</div>
|
||||||
@@ -120,3 +132,39 @@
|
|||||||
<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>
|
<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>
|
</div>
|
||||||
{% endif %}
|
{% 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>
|
||||||
Reference in new issue
Block a user