From 302736af70bf69df514c6ea5a9983e4ab27053d0 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 13 Sep 2026 02:12:17 +0200 Subject: [PATCH] fix: the Search Sources card loads its saved settings again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PubMed read "Disabled" after every refresh while the database said true, and the Test button reported the truth — so the card was showing its defaults, not its settings. The browser said why, once asked: [Admin] Settings load failed: ReferenceError: loadWebSearch is not defined This file is a series of bare { } blocks, and a function declared in one is not in scope in another. loadWebSearch lives in the block at 322 and was called from the settings loader in the block at 42. Worse than not running: the call sat inside that loader's .then(), so it threw and took the rest of the handler with it. It now loads itself on tabChanged, which is what every other block in this file already does. There is a comment at the top of loadAdmin saying loadOidcConfig cannot be called from there for exactly this reason. Someone met this hazard before; the web search call was added later without seeing it. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01Dv6sqaY6Vq3ChZHMem3cnU --- public/js/admin.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/public/js/admin.js b/public/js/admin.js index 12aefd5a..47f7d5fc 100644 --- a/public/js/admin.js +++ b/public/js/admin.js @@ -85,7 +85,6 @@ function adminTabActive() { if (el) el.textContent = stats.todayApiCalls !== undefined ? stats.todayApiCalls : '—'; updateRegStatus(settings.registrationEnabled !== false); - loadWebSearch(); }) .catch(function(err) { console.error('[Admin] Settings load failed:', err); }); } @@ -420,6 +419,19 @@ function adminTabActive() { // Its own endpoints rather than the generic setter: the key is masked on read // and a blank field means "keep what is there", so changing the provider does // not silently wipe a working key. + // + // Loads itself on tabChanged, like every other block in this file. It used to + // be called from the settings loader in the block above, which cannot see it: + // this file is a series of bare { } blocks, and a function declared in one is + // not in scope in another. That call threw ReferenceError on every admin + // open, and because it sat inside the settings .then(), it took the rest of + // that handler down with it — so the card showed its defaults and PubMed read + // "Disabled" while the database said true. + document.addEventListener('tabChanged', function (e) { + if (e.detail && e.detail.tab === 'admin') loadWebSearch(); + }); + if (adminTabActive()) loadWebSearch(); + function loadWebSearch() { fetch('/api/admin/websearch', { headers: getAuthHeaders() }) .then(function(r) { return r.json(); })