Stale reload and focus responses overwrite newer state
This commit is contained in:
Vendored
+35
-4
@@ -112,8 +112,18 @@ export async function loadProjects() {
|
||||
await Promise.all(state.projects.map((p) => loadTasks(p.id)));
|
||||
notify("projects");
|
||||
}
|
||||
const requestSeqs = new Map();
|
||||
function claimRequest(key) {
|
||||
const seq = (requestSeqs.get(key) ?? 0) + 1;
|
||||
requestSeqs.set(key, seq);
|
||||
return () => requestSeqs.get(key) === seq;
|
||||
}
|
||||
export async function loadTasks(projectId) {
|
||||
const latest = claimRequest(`tasks:${projectId}`);
|
||||
const tasks = await get("/api/projects/{projectId}/tasks", { path: { projectId } });
|
||||
if (!latest()) {
|
||||
return;
|
||||
}
|
||||
state.tasks.set(projectId, tasks);
|
||||
for (const t of tasks) {
|
||||
if (t.status === "active") {
|
||||
@@ -125,11 +135,21 @@ export async function loadTasks(projectId) {
|
||||
notify("tasks");
|
||||
}
|
||||
export async function loadSessions(taskId) {
|
||||
state.sessions.set(taskId, await get("/api/tasks/{taskId}/sessions", { path: { taskId } }));
|
||||
const latest = claimRequest(`sessions:${taskId}`);
|
||||
const sessions = await get("/api/tasks/{taskId}/sessions", { path: { taskId } });
|
||||
if (!latest()) {
|
||||
return;
|
||||
}
|
||||
state.sessions.set(taskId, sessions);
|
||||
notify("sessions", taskId);
|
||||
}
|
||||
export async function loadInbox() {
|
||||
state.inbox = await get("/api/inbox");
|
||||
const latest = claimRequest("inbox");
|
||||
const inbox = await get("/api/inbox");
|
||||
if (!latest()) {
|
||||
return;
|
||||
}
|
||||
state.inbox = inbox;
|
||||
notify("inbox");
|
||||
}
|
||||
export async function loadLeadSessions() {
|
||||
@@ -137,7 +157,12 @@ export async function loadLeadSessions() {
|
||||
notify("lead.sessions");
|
||||
}
|
||||
export async function loadFocus() {
|
||||
applyFocus(await get("/api/me/focus"));
|
||||
const latest = claimRequest("focus");
|
||||
const focus = await get("/api/me/focus");
|
||||
if (!latest()) {
|
||||
return;
|
||||
}
|
||||
applyFocus(focus);
|
||||
}
|
||||
export function applyFocus(f) {
|
||||
state.focus = f;
|
||||
@@ -160,8 +185,13 @@ export async function setFocus(change) {
|
||||
if (projectId) {
|
||||
next.project_id = projectId;
|
||||
}
|
||||
const latest = claimRequest("focus");
|
||||
applyFocus(next);
|
||||
applyFocus(await put("/api/me/focus", { body: next }));
|
||||
const focus = await put("/api/me/focus", { body: next });
|
||||
if (!latest()) {
|
||||
return;
|
||||
}
|
||||
applyFocus(focus);
|
||||
}
|
||||
export function focusTask(taskId, tab = "transcript") {
|
||||
setFocus({ task_id: taskId, tab }).catch((err) => console.error("set focus", err));
|
||||
@@ -403,6 +433,7 @@ export function handleEvent(ev) {
|
||||
break;
|
||||
case "focus.updated":
|
||||
if (ev.actor !== state.me?.login) {
|
||||
claimRequest("focus");
|
||||
applyFocus(ev.payload);
|
||||
}
|
||||
break;
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user