Use user name for tasks lookup with robust fallbacks

This commit is contained in:
2026-03-29 02:51:14 +00:00
parent d042f00230
commit 6abaf6c778
2 changed files with 86 additions and 22 deletions
+15 -11
View File
@@ -317,22 +317,25 @@
usersCache = Array.isArray(data.users) ? data.users : [];
const meId = String(data?.me?.id || '').trim();
const meName = data?.me?.name || data?.me?.email || 'Me';
const meLookupName = String(data?.me?.name || data?.me?.email || '').trim();
taskUserSelect.innerHTML = '';
for (const user of usersCache) {
const opt = document.createElement('option');
opt.value = user.id;
const lookupName = String(user.name || user.email || user.id || '').trim();
opt.value = lookupName;
opt.dataset.userId = user.id;
opt.textContent = `${user.name || user.email || user.id}${user.id === meId ? ' (Me)' : ''}`;
taskUserSelect.appendChild(opt);
}
if (meId) {
taskUserSelect.value = meId;
if (meLookupName) {
taskUserSelect.value = meLookupName;
}
writeOutput({ message: `Loaded ${usersCache.length} users`, me: { id: meId, name: meName } });
writeOutput({ message: `Loaded ${usersCache.length} users`, me: { id: meId, name: meName, lookupName: meLookupName } });
if (data?.warning) {
writeOutput({ message: `Loaded ${usersCache.length} users`, warning: data.warning, me: { id: meId, name: meName } });
writeOutput({ message: `Loaded ${usersCache.length} users`, warning: data.warning, me: { id: meId, name: meName, lookupName: meLookupName } });
}
}
@@ -367,9 +370,9 @@
async function loadTasks() {
await ensurePocketBaseClient();
const token = getCurrentToken();
const userId = String(taskUserSelect.value || '').trim();
const url = userId
? `/api/tasks/list?userId=${encodeURIComponent(userId)}`
const userName = String(taskUserSelect.value || '').trim();
const url = userName
? `/api/tasks/list?userName=${encodeURIComponent(userName)}`
: '/api/tasks/list';
const resp = await fetch(url, {
headers: { 'x-pb-token': token },
@@ -378,13 +381,14 @@
if (!resp.ok || !data?.success) {
throw new Error(data?.message || 'Failed to load tasks');
}
if (data?.userId && taskUserSelect.value !== data.userId) {
taskUserSelect.value = data.userId;
if (data?.userName && taskUserSelect.value !== data.userName) {
taskUserSelect.value = data.userName;
}
renderTasks(data.tasks || []);
writeOutput({
message: `Loaded ${data?.count ?? 0} task(s)`,
userId: data?.userId || userId,
userName: data?.userName || userName,
userId: data?.userId || undefined,
warning: data?.warning || undefined,
tasks: data.tasks || [],
});