fix: arbre collapse après drag-drop (expanded persistant via localStorage)
Avant: tout window.location.reload() réinitialisait expanded={},
causant le collapse de tous les dossiers après un drop.
Fix:
- expanded initialisé depuis localStorage('fd_ws_expanded')
- _saveExpandedState() sauve avant toute navigation/reload
- _reloadAfterAction() = save + reload
- toggleExpand, navigateToFolder, expandAll sauvent l'état
- Tous les reload (create, rename, delete, move, upload) passent par _reloadAfterAction()
This commit is contained in:
@@ -300,7 +300,10 @@ document.addEventListener('alpine:init', function() {
|
|||||||
newName:'',
|
newName:'',
|
||||||
parentFolder:null,
|
parentFolder:null,
|
||||||
target:null,
|
target:null,
|
||||||
expanded: {},
|
expanded: (function() {
|
||||||
|
try { return JSON.parse(localStorage.getItem('fd_ws_expanded') || '{}'); }
|
||||||
|
catch(e) { return {}; }
|
||||||
|
})(),
|
||||||
currentFolder: {{ current_folder_id }},
|
currentFolder: {{ current_folder_id }},
|
||||||
searchQuery: '',
|
searchQuery: '',
|
||||||
|
|
||||||
@@ -429,6 +432,7 @@ document.addEventListener('alpine:init', function() {
|
|||||||
toggleExpand(id, btn) {
|
toggleExpand(id, btn) {
|
||||||
this.expanded[id] = !(this.expanded[id] || false);
|
this.expanded[id] = !(this.expanded[id] || false);
|
||||||
this.expanded = Object.assign({}, this.expanded);
|
this.expanded = Object.assign({}, this.expanded);
|
||||||
|
this._saveExpandedState();
|
||||||
// For renderChildren static HTML: toggle chevron + sibling <ul>
|
// For renderChildren static HTML: toggle chevron + sibling <ul>
|
||||||
if (btn) {
|
if (btn) {
|
||||||
btn.classList.toggle('open', this.expanded[id]);
|
btn.classList.toggle('open', this.expanded[id]);
|
||||||
@@ -447,9 +451,19 @@ document.addEventListener('alpine:init', function() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
navigateToFolder(id) {
|
navigateToFolder(id) {
|
||||||
|
this._saveExpandedState();
|
||||||
window.location = '/local-workspace?folder=' + id;
|
window.location = '/local-workspace?folder=' + id;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_saveExpandedState() {
|
||||||
|
try { localStorage.setItem('fd_ws_expanded', JSON.stringify(this.expanded)); }
|
||||||
|
catch(e) {}
|
||||||
|
},
|
||||||
|
_reloadAfterAction() {
|
||||||
|
this._saveExpandedState();
|
||||||
|
this._reloadAfterAction();
|
||||||
|
},
|
||||||
|
|
||||||
// ── Expand / Collapse all ──
|
// ── Expand / Collapse all ──
|
||||||
expandAll() {
|
expandAll() {
|
||||||
var self = this;
|
var self = this;
|
||||||
@@ -597,7 +611,7 @@ document.addEventListener('alpine:init', function() {
|
|||||||
this.showCreate = false;
|
this.showCreate = false;
|
||||||
this.parentFolder = null;
|
this.parentFolder = null;
|
||||||
this.newName = '';
|
this.newName = '';
|
||||||
window.location.reload();
|
this._reloadAfterAction();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -622,7 +636,7 @@ document.addEventListener('alpine:init', function() {
|
|||||||
headers:{'Content-Type':'application/json'},
|
headers:{'Content-Type':'application/json'},
|
||||||
body:JSON.stringify({name:n})
|
body:JSON.stringify({name:n})
|
||||||
});
|
});
|
||||||
if (r.ok) { window.location.reload(); }
|
if (r.ok) { this._reloadAfterAction(); }
|
||||||
},
|
},
|
||||||
|
|
||||||
startDelete(node) {
|
startDelete(node) {
|
||||||
@@ -633,7 +647,7 @@ document.addEventListener('alpine:init', function() {
|
|||||||
async doDelete() {
|
async doDelete() {
|
||||||
if (!this.target) return;
|
if (!this.target) return;
|
||||||
var r = await fetch('/api/local-workspace/items/'+this.target.db_id, { method:'DELETE' });
|
var r = await fetch('/api/local-workspace/items/'+this.target.db_id, { method:'DELETE' });
|
||||||
if (r.ok) { window.location.reload(); }
|
if (r.ok) { this._reloadAfterAction(); }
|
||||||
},
|
},
|
||||||
|
|
||||||
// ── Drag & Drop ──
|
// ── Drag & Drop ──
|
||||||
@@ -829,7 +843,7 @@ document.addEventListener('alpine:init', function() {
|
|||||||
body: JSON.stringify(body)
|
body: JSON.stringify(body)
|
||||||
});
|
});
|
||||||
if (r.ok) {
|
if (r.ok) {
|
||||||
window.location.reload();
|
this._reloadAfterAction();
|
||||||
} else {
|
} else {
|
||||||
alert('Move failed');
|
alert('Move failed');
|
||||||
}
|
}
|
||||||
@@ -857,7 +871,7 @@ document.addEventListener('alpine:init', function() {
|
|||||||
var items = d.items || [];
|
var items = d.items || [];
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
self.uploading = false;
|
self.uploading = false;
|
||||||
window.location.reload();
|
this._reloadAfterAction();
|
||||||
}, 800);
|
}, 800);
|
||||||
} else {
|
} else {
|
||||||
this.uploadStatus = '✗ ' + (d.error || 'Upload failed');
|
this.uploadStatus = '✗ ' + (d.error || 'Upload failed');
|
||||||
|
|||||||
Reference in New Issue
Block a user