v1.0.29: fix userId not restoring due to race condition
onSendToPropertyInspector (users list) arrives before onDidReceiveGlobalSettings (saved userId) in most cases, leaving globalUserId empty when populateUsers runs. Now cachedUsers stores the list, and onDidReceiveGlobalSettings re-populates if users already arrived — handles both orderings. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -162,6 +162,7 @@
|
||||
var credSaveTimer = null;
|
||||
var credConfigured = false;
|
||||
var globalUserId = "";
|
||||
var cachedUsers = [];
|
||||
|
||||
function setStatus(msg, cls) {
|
||||
var el = document.getElementById("statusText");
|
||||
@@ -201,15 +202,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
function populateUsers(users, savedUserId) {
|
||||
function populateUsers(users, userId) {
|
||||
cachedUsers = users;
|
||||
var sel = document.getElementById("userId");
|
||||
var current = savedUserId || sel.value;
|
||||
sel.innerHTML = '<option value="">— Select your name —</option>';
|
||||
users.forEach(function(u) {
|
||||
var opt = document.createElement("option");
|
||||
opt.value = u.id;
|
||||
opt.textContent = u.name;
|
||||
if (u.id === current) opt.selected = true;
|
||||
if (u.id === userId) opt.selected = true;
|
||||
sel.appendChild(opt);
|
||||
});
|
||||
}
|
||||
@@ -266,11 +267,9 @@
|
||||
var s = jsn.payload.settings || {};
|
||||
document.getElementById("notionToken").value = s.notionToken || "";
|
||||
globalUserId = s.userId || "";
|
||||
if (globalUserId) {
|
||||
var sel = document.getElementById("userId");
|
||||
if (sel.querySelector('option[value="' + globalUserId + '"]')) {
|
||||
sel.value = globalUserId;
|
||||
}
|
||||
if (globalUserId && cachedUsers.length > 0) {
|
||||
// Users already loaded — re-populate with correct selection
|
||||
populateUsers(cachedUsers, globalUserId);
|
||||
}
|
||||
|
||||
credConfigured = !!(s.notionToken && s.userId);
|
||||
|
||||
Reference in New Issue
Block a user