feat: UX improvements for list handling
This commit is contained in:
@@ -25,8 +25,6 @@ const createListBtn = document.getElementById('createListBtn');
|
||||
const listSelectionOverlay = document.getElementById('listSelectionOverlay');
|
||||
const listSelectionBody = document.getElementById('listSelectionBody');
|
||||
const closeListSelection = document.getElementById('closeListSelection');
|
||||
const saveListSelection = document.getElementById('saveListSelection');
|
||||
const cancelListSelection = document.getElementById('cancelListSelection');
|
||||
const listFilterWrapper = document.getElementById('listFilterWrapper');
|
||||
const listFilterChips = document.getElementById('listFilterChips');
|
||||
const clearListFilters = document.getElementById('clearListFilters');
|
||||
@@ -717,13 +715,6 @@ function setupListsManagement() {
|
||||
currentLinkForListSelection = null;
|
||||
});
|
||||
|
||||
cancelListSelection.addEventListener('click', () => {
|
||||
listSelectionOverlay.classList.remove('show');
|
||||
currentLinkForListSelection = null;
|
||||
});
|
||||
|
||||
saveListSelection.addEventListener('click', handleSaveListSelection);
|
||||
|
||||
// Close on backdrop click
|
||||
listSelectionOverlay.addEventListener('click', (e) => {
|
||||
if (e.target === listSelectionOverlay) {
|
||||
@@ -976,20 +967,27 @@ function handleAddToLists(linkId) {
|
||||
<span>${escapeHtml(list.name)}</span>
|
||||
</label>
|
||||
`).join('');
|
||||
|
||||
// Add event listeners to checkboxes for auto-save
|
||||
listSelectionBody.querySelectorAll('input[type="checkbox"]').forEach(checkbox => {
|
||||
checkbox.addEventListener('change', () => {
|
||||
handleCheckboxChange(linkId);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
listSelectionOverlay.classList.add('show');
|
||||
}
|
||||
|
||||
// Handle save list selection
|
||||
async function handleSaveListSelection() {
|
||||
if (!currentLinkForListSelection) return;
|
||||
// Handle checkbox change (auto-save)
|
||||
async function handleCheckboxChange(linkId) {
|
||||
if (!linkId) return;
|
||||
|
||||
const checkboxes = listSelectionBody.querySelectorAll('input[type="checkbox"]:checked');
|
||||
const selectedListIds = Array.from(checkboxes).map(cb => cb.value);
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/${currentLinkForListSelection}/lists`, {
|
||||
const response = await fetch(`${API_BASE}/${linkId}/lists`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
@@ -1004,20 +1002,23 @@ async function handleSaveListSelection() {
|
||||
}
|
||||
|
||||
// Update local array
|
||||
const linkIndex = allLinks.findIndex(l => l.id === currentLinkForListSelection);
|
||||
const linkIndex = allLinks.findIndex(l => l.id === linkId);
|
||||
if (linkIndex !== -1) {
|
||||
allLinks[linkIndex].listIds = selectedListIds;
|
||||
}
|
||||
|
||||
// Update display
|
||||
displayLinks(getFilteredLinks());
|
||||
|
||||
listSelectionOverlay.classList.remove('show');
|
||||
currentLinkForListSelection = null;
|
||||
showMessage('Link lists updated successfully!', 'success');
|
||||
// No need to refresh the display - the link is already visible
|
||||
// Only update if the link's visibility might have changed due to list filters
|
||||
// But since we're just assigning lists, not changing visibility, we skip the refresh
|
||||
} catch (error) {
|
||||
showMessage('Failed to update link lists', 'error');
|
||||
console.error('Error updating link lists:', error);
|
||||
// Revert checkbox state on error
|
||||
const link = allLinks.find(l => l.id === linkId);
|
||||
const linkListIds = link?.listIds || [];
|
||||
listSelectionBody.querySelectorAll('input[type="checkbox"]').forEach(checkbox => {
|
||||
checkbox.checked = linkListIds.includes(checkbox.value);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user