Stale reload and focus responses overwrite newer state
This commit is contained in:
+37
-4
@@ -155,8 +155,20 @@ export async function loadProjects(): Promise<void> {
|
||||
notify("projects");
|
||||
}
|
||||
|
||||
const requestSeqs = new Map<string, number>();
|
||||
|
||||
function claimRequest(key: string): () => boolean {
|
||||
const seq = (requestSeqs.get(key) ?? 0) + 1;
|
||||
requestSeqs.set(key, seq);
|
||||
return () => requestSeqs.get(key) === seq;
|
||||
}
|
||||
|
||||
export async function loadTasks(projectId: string): Promise<void> {
|
||||
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") {
|
||||
@@ -169,12 +181,22 @@ export async function loadTasks(projectId: string): Promise<void> {
|
||||
}
|
||||
|
||||
export async function loadSessions(taskId: string): Promise<void> {
|
||||
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(): Promise<void> {
|
||||
state.inbox = await get("/api/inbox");
|
||||
const latest = claimRequest("inbox");
|
||||
const inbox = await get("/api/inbox");
|
||||
if (!latest()) {
|
||||
return;
|
||||
}
|
||||
state.inbox = inbox;
|
||||
notify("inbox");
|
||||
}
|
||||
|
||||
@@ -184,7 +206,12 @@ export async function loadLeadSessions(): Promise<void> {
|
||||
}
|
||||
|
||||
export async function loadFocus(): Promise<void> {
|
||||
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: Focus): void {
|
||||
@@ -210,8 +237,13 @@ export async function setFocus(change: { task_id?: string | null; project_id?: s
|
||||
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: string, tab: TaskTab = "transcript"): void {
|
||||
@@ -477,6 +509,7 @@ export function handleEvent(ev: ByreEvent): void {
|
||||
break;
|
||||
case "focus.updated":
|
||||
if (ev.actor !== state.me?.login) {
|
||||
claimRequest("focus");
|
||||
applyFocus(ev.payload as unknown as Focus);
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user