Fix duplicated Upload & Folder cards if they were added to header and page was refreshed

This commit is contained in:
Ryan
2025-05-14 08:08:18 -04:00
committed by GitHub
parent f2f7697994
commit 492bab36ca
2 changed files with 25 additions and 13 deletions

View File

@@ -101,6 +101,8 @@
### 10. setAttribute + encodeURI to avoid “DOM text reinterpreted as HTML” alerts ### 10. setAttribute + encodeURI to avoid “DOM text reinterpreted as HTML” alerts
### 11. Fix duplicated Upload & Folder cards if they were added to header and page was refreshed
--- ---
## Changes 5/8/2025 ## Changes 5/8/2025

View File

@@ -32,23 +32,33 @@ export function loadSidebarOrder() {
updateSidebarVisibility(); updateSidebarVisibility();
} }
// NEW: Load header order from localStorage.
export function loadHeaderOrder() { export function loadHeaderOrder() {
const headerDropArea = document.getElementById('headerDropArea'); const headerDropArea = document.getElementById('headerDropArea');
if (!headerDropArea) return; if (!headerDropArea) return;
const orderStr = localStorage.getItem('headerOrder');
if (orderStr) { // 1) Clear out any icons that might already be in the drop area
const order = JSON.parse(orderStr); headerDropArea.innerHTML = '';
if (order.length > 0) {
order.forEach(id => { // 2) Read the saved array (or empty array if invalid/missing)
let stored;
try {
stored = JSON.parse(localStorage.getItem('headerOrder') || '[]');
} catch {
stored = [];
}
// 3) Deduplicate IDs
const uniqueIds = Array.from(new Set(stored));
// 4) Re-insert exactly one icon per saved card ID
uniqueIds.forEach(id => {
const card = document.getElementById(id); const card = document.getElementById(id);
// Only load if card is not already in header drop zone. if (card) insertCardInHeader(card, null);
if (card && card.parentNode.id !== 'headerDropArea') {
insertCardInHeader(card, null);
}
}); });
}
} // 5) Persist the cleaned, deduped list back to storage
localStorage.setItem('headerOrder', JSON.stringify(uniqueIds));
} }
// Internal helper: update sidebar visibility based on its content. // Internal helper: update sidebar visibility based on its content.