mirror of
https://github.com/olehomelchenko/astrolabe-nvc.git
synced 2025-12-21 21:22:23 +00:00
add asc/desc sorting
This commit is contained in:
15
index.html
15
index.html
@@ -47,9 +47,18 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="sort-controls">
|
<div class="sort-controls">
|
||||||
<span class="sort-label">Sort by:</span>
|
<span class="sort-label">Sort by:</span>
|
||||||
<button class="sort-btn active" data-sort="modified">Modified</button>
|
<button class="sort-btn active" data-sort="modified">
|
||||||
<button class="sort-btn" data-sort="created">Created</button>
|
<span class="sort-text">Modified</span>
|
||||||
<button class="sort-btn" data-sort="name">Name</button>
|
<span class="sort-arrow">⬇</span>
|
||||||
|
</button>
|
||||||
|
<button class="sort-btn" data-sort="created">
|
||||||
|
<span class="sort-text">Created</span>
|
||||||
|
<span class="sort-arrow">⬇</span>
|
||||||
|
</button>
|
||||||
|
<button class="sort-btn" data-sort="name">
|
||||||
|
<span class="sort-text">Name</span>
|
||||||
|
<span class="sort-arrow">⬇</span>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="search-controls">
|
<div class="search-controls">
|
||||||
<input type="text" id="snippet-search" placeholder="Search snippets..." />
|
<input type="text" id="snippet-search" placeholder="Search snippets..." />
|
||||||
|
|||||||
@@ -264,32 +264,60 @@ function renderSnippetList(searchQuery = null) {
|
|||||||
function initializeSortControls() {
|
function initializeSortControls() {
|
||||||
const sortButtons = document.querySelectorAll('.sort-btn');
|
const sortButtons = document.querySelectorAll('.sort-btn');
|
||||||
const currentSort = AppSettings.get('sortBy');
|
const currentSort = AppSettings.get('sortBy');
|
||||||
|
const currentOrder = AppSettings.get('sortOrder');
|
||||||
|
|
||||||
// Update active button based on settings
|
// Update active button and arrow based on settings
|
||||||
sortButtons.forEach(button => {
|
sortButtons.forEach(button => {
|
||||||
button.classList.remove('active');
|
button.classList.remove('active');
|
||||||
if (button.dataset.sort === currentSort) {
|
if (button.dataset.sort === currentSort) {
|
||||||
button.classList.add('active');
|
button.classList.add('active');
|
||||||
|
updateSortArrow(button, currentOrder);
|
||||||
|
} else {
|
||||||
|
updateSortArrow(button, 'desc'); // Default to desc for inactive buttons
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add click handler
|
// Add click handler
|
||||||
button.addEventListener('click', function() {
|
button.addEventListener('click', function() {
|
||||||
const newSort = this.dataset.sort;
|
const sortType = this.dataset.sort;
|
||||||
changeSortBy(newSort);
|
toggleSort(sortType);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change sort method
|
// Update sort arrow display
|
||||||
function changeSortBy(sortBy) {
|
function updateSortArrow(button, direction) {
|
||||||
// Save to settings
|
const arrow = button.querySelector('.sort-arrow');
|
||||||
AppSettings.set('sortBy', sortBy);
|
if (arrow) {
|
||||||
|
arrow.textContent = direction === 'desc' ? '⬇' : '⬆';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update button states
|
// Toggle sort method and direction
|
||||||
|
function toggleSort(sortType) {
|
||||||
|
const currentSort = AppSettings.get('sortBy');
|
||||||
|
const currentOrder = AppSettings.get('sortOrder');
|
||||||
|
|
||||||
|
let newOrder;
|
||||||
|
if (currentSort === sortType) {
|
||||||
|
// Same button clicked - toggle direction
|
||||||
|
newOrder = currentOrder === 'desc' ? 'asc' : 'desc';
|
||||||
|
} else {
|
||||||
|
// Different button clicked - default to desc
|
||||||
|
newOrder = 'desc';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save to settings
|
||||||
|
AppSettings.set('sortBy', sortType);
|
||||||
|
AppSettings.set('sortOrder', newOrder);
|
||||||
|
|
||||||
|
// Update button states and arrows
|
||||||
document.querySelectorAll('.sort-btn').forEach(btn => {
|
document.querySelectorAll('.sort-btn').forEach(btn => {
|
||||||
btn.classList.remove('active');
|
btn.classList.remove('active');
|
||||||
if (btn.dataset.sort === sortBy) {
|
if (btn.dataset.sort === sortType) {
|
||||||
btn.classList.add('active');
|
btn.classList.add('active');
|
||||||
|
updateSortArrow(btn, newOrder);
|
||||||
|
} else {
|
||||||
|
updateSortArrow(btn, 'desc'); // Default for inactive buttons
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -141,6 +141,18 @@ body {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font-size: 10px;
|
font-size: 10px;
|
||||||
font-family: 'MS Sans Serif', Tahoma, sans-serif;
|
font-family: 'MS Sans Serif', Tahoma, sans-serif;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sort-text {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sort-arrow {
|
||||||
|
font-size: 9px;
|
||||||
|
opacity: 0.7;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sort-btn:hover {
|
.sort-btn:hover {
|
||||||
|
|||||||
Reference in New Issue
Block a user