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:
+1
-1
@@ -42,7 +42,7 @@ async def lifespan(_app: FastAPI):
|
|||||||
|
|
||||||
app = FastAPI(
|
app = FastAPI(
|
||||||
title="FlowDeck",
|
title="FlowDeck",
|
||||||
version="2.4.6",
|
version="patch",
|
||||||
docs_url="/docs" if settings.log_level == "DEBUG" else None,
|
docs_url="/docs" if settings.log_level == "DEBUG" else None,
|
||||||
redoc_url=None,
|
redoc_url=None,
|
||||||
lifespan=lifespan,
|
lifespan=lifespan,
|
||||||
|
|||||||
+28
-8
@@ -877,14 +877,28 @@
|
|||||||
.catch(err => { this.toast('Failed to create sub-page: ' + err.message, 'error'); });
|
.catch(err => { this.toast('Failed to create sub-page: ' + err.message, 'error'); });
|
||||||
},
|
},
|
||||||
loadGiteaTree() {
|
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')
|
fetch('/api/gitea/projects/' + this.giteaOwner + '/' + this.giteaRepo + '/tree')
|
||||||
.then(r => r.json())
|
.then(function(r) {
|
||||||
.then(data => {
|
if (!r.ok) throw new Error('HTTP ' + r.status + ': ' + r.statusText);
|
||||||
|
return r.json();
|
||||||
|
})
|
||||||
|
.then(function(data) {
|
||||||
this.giteaTree = data.tree || [];
|
this.giteaTree = data.tree || [];
|
||||||
// Render tree items into the sidebar workspace section
|
if (!container) {
|
||||||
var container = document.getElementById('sidebar-workspace-items');
|
console.log('loadGiteaTree: #sidebar-workspace-items not found');
|
||||||
if (!container) return;
|
return;
|
||||||
|
}
|
||||||
container.innerHTML = '';
|
container.innerHTML = '';
|
||||||
if (!this.giteaTree.length) {
|
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>';
|
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>';
|
li.innerHTML = '<span class="page-icon">' + icon + '</span><span class="page-name">' + item.name + '</span>';
|
||||||
container.appendChild(li);
|
container.appendChild(li);
|
||||||
});
|
});
|
||||||
})
|
console.log('loadGiteaTree: rendered ' + this.giteaTree.length + ' items');
|
||||||
.catch(function() { /* silently ignore */ });
|
}.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() {
|
newPageInWorkspace() {
|
||||||
const name = prompt('File name:');
|
const name = prompt('File name:');
|
||||||
|
|||||||
@@ -218,8 +218,7 @@ function giteaWorkspace() {
|
|||||||
cb.style.cssText = 'flex-shrink:0;margin:0;display:none;';
|
cb.style.cssText = 'flex-shrink:0;margin:0;display:none;';
|
||||||
cb.addEventListener('click', function(ev) {
|
cb.addEventListener('click', function(ev) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
var gw = document.querySelector('[x-data]').__x.$data;
|
self.selectItem(item.path, li, ev);
|
||||||
gw.selectItem(item.path, li, ev);
|
|
||||||
});
|
});
|
||||||
li.appendChild(cb);
|
li.appendChild(cb);
|
||||||
// Icon
|
// Icon
|
||||||
@@ -234,8 +233,7 @@ function giteaWorkspace() {
|
|||||||
nameSpan.addEventListener('dblclick', function(ev) {
|
nameSpan.addEventListener('dblclick', function(ev) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
var gw = document.querySelector('[x-data]').__x.$data;
|
self.startInlineRename(nameSpan, item.path, li);
|
||||||
gw.startInlineRename(nameSpan, item.path, li);
|
|
||||||
});
|
});
|
||||||
li.appendChild(nameSpan);
|
li.appendChild(nameSpan);
|
||||||
container.appendChild(li);
|
container.appendChild(li);
|
||||||
@@ -250,9 +248,8 @@ function giteaWorkspace() {
|
|||||||
pli.innerHTML = '<span class="page-icon">🔒</span><span class="page-name">Private Pages</span>';
|
pli.innerHTML = '<span class="page-icon">🔒</span><span class="page-name">Private Pages</span>';
|
||||||
pli.addEventListener('click', function(e) {
|
pli.addEventListener('click', function(e) {
|
||||||
e.preventDefault(); e.stopPropagation();
|
e.preventDefault(); e.stopPropagation();
|
||||||
var gw = document.querySelector('[x-data]').__x.$data;
|
self.showPrivate = true; self.showFile = false; self.showEditor = false;
|
||||||
gw.showPrivate = true; gw.showFile = false; gw.showEditor = false;
|
self.loadPrivatePages();
|
||||||
gw.loadPrivatePages();
|
|
||||||
});
|
});
|
||||||
container.appendChild(pli);
|
container.appendChild(pli);
|
||||||
} catch(e) { console.error('Sidebar tree load failed:', e); }
|
} catch(e) { console.error('Sidebar tree load failed:', e); }
|
||||||
@@ -314,6 +311,7 @@ function giteaWorkspace() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async loadSubdir(path, el) {
|
async loadSubdir(path, el) {
|
||||||
|
var self = this;
|
||||||
// Check if already loaded
|
// Check if already loaded
|
||||||
var ul = el.querySelector('ul');
|
var ul = el.querySelector('ul');
|
||||||
if (ul) {
|
if (ul) {
|
||||||
@@ -343,8 +341,7 @@ function giteaWorkspace() {
|
|||||||
cb.style.cssText = 'flex-shrink:0;margin:0;display:none;';
|
cb.style.cssText = 'flex-shrink:0;margin:0;display:none;';
|
||||||
cb.addEventListener('click', function(ev) {
|
cb.addEventListener('click', function(ev) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
var gw = document.querySelector('[x-data]').__x.$data;
|
self.selectItem(child.path, li, ev);
|
||||||
gw.selectItem(child.path, li, ev);
|
|
||||||
});
|
});
|
||||||
li.appendChild(cb);
|
li.appendChild(cb);
|
||||||
// Icon
|
// Icon
|
||||||
@@ -358,8 +355,7 @@ function giteaWorkspace() {
|
|||||||
nameSpan.addEventListener('dblclick', function(ev) {
|
nameSpan.addEventListener('dblclick', function(ev) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
var gw = document.querySelector('[x-data]').__x.$data;
|
self.startInlineRename(nameSpan, child.path, li);
|
||||||
gw.startInlineRename(nameSpan, child.path, li);
|
|
||||||
});
|
});
|
||||||
li.appendChild(nameSpan);
|
li.appendChild(nameSpan);
|
||||||
ul.appendChild(li);
|
ul.appendChild(li);
|
||||||
|
|||||||
Reference in New Issue
Block a user