fix: sidebar Gitea tree loading — race condition + silent errors + wrong Alpine scope
- loadGiteaTree: skip if giteaWorkspace component already loaded tree
- loadGiteaTree: check r.ok, add console.error logging, show error in UI
- loadGiteaTree: use .bind(this) for correct this in callbacks
- gitea_workspace.html: replace querySelector('[x-data]') with captured self
in loadSidebarTree, loadSubdir, Private Pages click handlers
- Prevents loadGiteaTree from overwriting loadSidebarTree results
on /gitea-workspace page
This commit is contained in:
+28
-8
@@ -877,14 +877,28 @@
|
||||
.catch(err => { this.toast('Failed to create sub-page: ' + err.message, 'error'); });
|
||||
},
|
||||
loadGiteaTree() {
|
||||
if (!this.giteaWorkspace || !this.giteaOwner || !this.giteaRepo) return;
|
||||
if (!this.giteaWorkspace || !this.giteaOwner || !this.giteaRepo) {
|
||||
console.log('loadGiteaTree: skipped (giteaWorkspace=' + this.giteaWorkspace + ', owner=' + this.giteaOwner + ', repo=' + this.giteaRepo + ')');
|
||||
return;
|
||||
}
|
||||
// Skip if giteaWorkspace component already loaded the tree (has data-gitea-path items)
|
||||
var container = document.getElementById('sidebar-workspace-items');
|
||||
if (container && container.querySelector('[data-gitea-path]')) {
|
||||
console.log('loadGiteaTree: skipped (tree already loaded by giteaWorkspace component)');
|
||||
return;
|
||||
}
|
||||
console.log('loadGiteaTree: fetching /api/gitea/projects/' + this.giteaOwner + '/' + this.giteaRepo + '/tree');
|
||||
fetch('/api/gitea/projects/' + this.giteaOwner + '/' + this.giteaRepo + '/tree')
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
.then(function(r) {
|
||||
if (!r.ok) throw new Error('HTTP ' + r.status + ': ' + r.statusText);
|
||||
return r.json();
|
||||
})
|
||||
.then(function(data) {
|
||||
this.giteaTree = data.tree || [];
|
||||
// Render tree items into the sidebar workspace section
|
||||
var container = document.getElementById('sidebar-workspace-items');
|
||||
if (!container) return;
|
||||
if (!container) {
|
||||
console.log('loadGiteaTree: #sidebar-workspace-items not found');
|
||||
return;
|
||||
}
|
||||
container.innerHTML = '';
|
||||
if (!this.giteaTree.length) {
|
||||
container.innerHTML = '<li class="sidebar-item empty-hint"><span class="page-icon">📄</span><span class="page-name text-dim">No files yet</span></li>';
|
||||
@@ -897,8 +911,14 @@
|
||||
li.innerHTML = '<span class="page-icon">' + icon + '</span><span class="page-name">' + item.name + '</span>';
|
||||
container.appendChild(li);
|
||||
});
|
||||
})
|
||||
.catch(function() { /* silently ignore */ });
|
||||
console.log('loadGiteaTree: rendered ' + this.giteaTree.length + ' items');
|
||||
}.bind(this))
|
||||
.catch(function(err) {
|
||||
console.error('loadGiteaTree failed:', err.message || err);
|
||||
if (container) {
|
||||
container.innerHTML = '<li class="sidebar-item empty-hint"><span class="page-icon">⚠️</span><span class="page-name text-dim">Could not load tree: ' + (err.message || 'Unknown error') + '</span></li>';
|
||||
}
|
||||
});
|
||||
},
|
||||
newPageInWorkspace() {
|
||||
const name = prompt('File name:');
|
||||
|
||||
Reference in New Issue
Block a user