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(
|
||||
title="FlowDeck",
|
||||
version="2.4.6",
|
||||
version="patch",
|
||||
docs_url="/docs" if settings.log_level == "DEBUG" else None,
|
||||
redoc_url=None,
|
||||
lifespan=lifespan,
|
||||
|
||||
+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:');
|
||||
|
||||
@@ -218,8 +218,7 @@ function giteaWorkspace() {
|
||||
cb.style.cssText = 'flex-shrink:0;margin:0;display:none;';
|
||||
cb.addEventListener('click', function(ev) {
|
||||
ev.stopPropagation();
|
||||
var gw = document.querySelector('[x-data]').__x.$data;
|
||||
gw.selectItem(item.path, li, ev);
|
||||
self.selectItem(item.path, li, ev);
|
||||
});
|
||||
li.appendChild(cb);
|
||||
// Icon
|
||||
@@ -234,8 +233,7 @@ function giteaWorkspace() {
|
||||
nameSpan.addEventListener('dblclick', function(ev) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
var gw = document.querySelector('[x-data]').__x.$data;
|
||||
gw.startInlineRename(nameSpan, item.path, li);
|
||||
self.startInlineRename(nameSpan, item.path, li);
|
||||
});
|
||||
li.appendChild(nameSpan);
|
||||
container.appendChild(li);
|
||||
@@ -250,9 +248,8 @@ function giteaWorkspace() {
|
||||
pli.innerHTML = '<span class="page-icon">🔒</span><span class="page-name">Private Pages</span>';
|
||||
pli.addEventListener('click', function(e) {
|
||||
e.preventDefault(); e.stopPropagation();
|
||||
var gw = document.querySelector('[x-data]').__x.$data;
|
||||
gw.showPrivate = true; gw.showFile = false; gw.showEditor = false;
|
||||
gw.loadPrivatePages();
|
||||
self.showPrivate = true; self.showFile = false; self.showEditor = false;
|
||||
self.loadPrivatePages();
|
||||
});
|
||||
container.appendChild(pli);
|
||||
} catch(e) { console.error('Sidebar tree load failed:', e); }
|
||||
@@ -314,6 +311,7 @@ function giteaWorkspace() {
|
||||
},
|
||||
|
||||
async loadSubdir(path, el) {
|
||||
var self = this;
|
||||
// Check if already loaded
|
||||
var ul = el.querySelector('ul');
|
||||
if (ul) {
|
||||
@@ -343,8 +341,7 @@ function giteaWorkspace() {
|
||||
cb.style.cssText = 'flex-shrink:0;margin:0;display:none;';
|
||||
cb.addEventListener('click', function(ev) {
|
||||
ev.stopPropagation();
|
||||
var gw = document.querySelector('[x-data]').__x.$data;
|
||||
gw.selectItem(child.path, li, ev);
|
||||
self.selectItem(child.path, li, ev);
|
||||
});
|
||||
li.appendChild(cb);
|
||||
// Icon
|
||||
@@ -358,8 +355,7 @@ function giteaWorkspace() {
|
||||
nameSpan.addEventListener('dblclick', function(ev) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
var gw = document.querySelector('[x-data]').__x.$data;
|
||||
gw.startInlineRename(nameSpan, child.path, li);
|
||||
self.startInlineRename(nameSpan, child.path, li);
|
||||
});
|
||||
li.appendChild(nameSpan);
|
||||
ul.appendChild(li);
|
||||
|
||||
Reference in New Issue
Block a user