Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Sidebar: rows keep their place while the app is in use; unread and work show as marks (#7552)

Milind Sonib8cf45d552a2
diff --git a/src/components/Sidebar.bot-reorder.dom.test.ts b/src/components/Sidebar.bot-reorder.dom.test.ts
index d159da6c83..ac6c57cefd 100644
--- a/src/components/Sidebar.bot-reorder.dom.test.ts
+++ b/src/components/Sidebar.bot-reorder.dom.test.ts
@@ -104,46 +104,45 @@ for (const advanced of [false, true]) {
expect(saved()).toEqual([{ type: "botsOrdered", botIds: ["alpha", "bravo", "delta", "charlie"] }]);
});
- it("puts a bot dropped above a working one first among the rest, without storing the working one's place", () => {
- // Saved alpha, bravo, charlie, delta; delta is working, so it is drawn first.
+ it("keeps a working bot in its place, and a bot dropped above it lands there", () => {
render([bot("alpha"), bot("bravo"), bot("charlie"), bot("delta", { busy: true })]);
- expect(order()).toEqual(["delta", "alpha", "bravo", "charlie"]);
- dragOnto("charlie", "delta", "top");
- expect(saved()).toEqual([{ type: "botsOrdered", botIds: ["charlie", "alpha", "bravo", "delta"] }]);
+ expect(order()).toEqual(["alpha", "bravo", "charlie", "delta"]);
+ dragOnto("alpha", "delta", "top");
+ expect(saved()).toEqual([{ type: "botsOrdered", botIds: ["bravo", "charlie", "alpha", "delta"] }]);
});
- it("says only a keyboard move the rows show: Alt+Up past a working bot changes nothing", () => {
+ it("moves a bot past a working one with Alt+arrow, as the rows show", () => {
render([bot("alpha"), bot("bravo"), bot("delta", { busy: true })]);
- expect(order()).toEqual(["delta", "alpha", "bravo"]);
+ expect(order()).toEqual(["alpha", "bravo", "delta"]);
const press = (id: string, key: string) => flushSync(() => document.querySelector(`[data-sidebar-bot-row="${id}"]`)!
.dispatchEvent(new KeyboardEvent("keydown", { key, altKey: true, bubbles: true, cancelable: true })));
press("alpha", "ArrowUp");
expect(saved()).toEqual([]);
expect(document.body.textContent).not.toContain("moved to position");
- press("alpha", "ArrowDown");
- expect(saved()).toEqual([{ type: "botsOrdered", botIds: ["bravo", "alpha", "delta"] }]);
- expect(document.body.textContent).toContain("Alpha moved to position 3 of 3");
+ press("bravo", "ArrowDown");
+ expect(saved()).toEqual([{ type: "botsOrdered", botIds: ["alpha", "delta", "bravo"] }]);
+ expect(document.body.textContent).toContain("Bravo moved to position 3 of 3");
});
- it("moves a bot below a waiting one's place among the rows as drawn", () => {
+ it("keeps a bot waiting on the person in its place, and drops a bot below it there", () => {
render([bot("alpha"), bot("bravo", { activity: "waiting-on-you" }), bot("charlie"), bot("delta")]);
- expect(order()).toEqual(["bravo", "alpha", "charlie", "delta"]);
+ expect(order()).toEqual(["alpha", "bravo", "charlie", "delta"]);
dragOnto("delta", "bravo", "bottom");
- expect(saved()).toEqual([{ type: "botsOrdered", botIds: ["delta", "alpha", "bravo", "charlie"] }]);
+ expect(saved()).toEqual([{ type: "botsOrdered", botIds: ["alpha", "bravo", "delta", "charlie"] }]);
});
- it("plans among the rows left in place while Unread lists another bot of the same list", () => {
- // Saved alpha, bravo, charlie, delta, echo; delta is working, echo is unread and listed in Unread above.
+ it("plans with an unread bot in its own place, like any other row", () => {
+ // Saved alpha, bravo, charlie, delta, echo; delta is working and echo is unread, and both stay where they are.
const unread = bot("echo", { tasks: [{ threadId: "echo-t", title: "Chat", createdAt: 1, unread: true }] });
render([bot("alpha"), bot("bravo"), bot("charlie"), bot("delta", { busy: true }), unread]);
- expect(order()).toEqual(["echo", "delta", "alpha", "bravo", "charlie"]);
- dragOnto("charlie", "delta", "top");
- expect(saved()).toEqual([{ type: "botsOrdered", botIds: ["charlie", "alpha", "bravo", "delta"] }]);
+ expect(order()).toEqual(["alpha", "bravo", "charlie", "delta", "echo"]);
+ dragOnto("echo", "alpha", "top");
+ expect(saved()).toEqual([{ type: "botsOrdered", botIds: ["echo", "alpha", "bravo", "charlie", "delta"] }]);
dispatch.mockReset();
flushSync(() => document.querySelector('[data-sidebar-bot-row="alpha"]')!
.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowDown", altKey: true, bubbles: true, cancelable: true })));
- expect(saved()).toEqual([{ type: "botsOrdered", botIds: ["bravo", "alpha", "charlie", "delta"] }]);
- expect(document.body.textContent).toContain("Alpha moved to position 3 of 4");
+ expect(saved()).toEqual([{ type: "botsOrdered", botIds: ["bravo", "alpha", "charlie", "delta", "echo"] }]);
+ expect(document.body.textContent).toContain("Alpha moved to position 2 of 5");
});
});
}
diff --git a/src/components/Sidebar.departments.test.ts b/src/components/Sidebar.departments.test.ts
index 521bc462e3..dd753a6ea1 100644
--- a/src/components/Sidebar.departments.test.ts
+++ b/src/components/Sidebar.departments.test.ts
@@ -350,24 +350,24 @@ describe("bots that are working or waiting on the person", () => {
fixture.state = { ...fixture.state, bots: fixture.state.bots.map((item) => (item.id === id ? { ...item, ...extra } : item)) };
};
- it("move to the top of their own list, in the person's order, and go back when done", () => {
+ it("keep their place in their own list while they work or wait, and after", () => {
busy("cleo", { busy: true });
busy("bea", { activity: "waiting-on-you" });
busy("echo", { busy: true });
- expect(listed()).toEqual(["bea", "cleo", "atlas", "echo", "dodo"]);
+ expect(listed()).toEqual(["atlas", "bea", "cleo", "dodo", "echo"]);
busy("cleo", { busy: false });
busy("bea", { activity: "idle" });
busy("echo", { busy: false });
expect(listed()).toEqual(["atlas", "bea", "cleo", "dodo", "echo"]);
});
- it("count a working thread, but not a wait on a teammate", () => {
+ it("keep their place for a working thread too", () => {
busy("cleo", { tasks: [{ threadId: "c1", title: "Run", createdAt: 1, busy: true } as Task] });
busy("bea", { waitingForTeammates: true });
- expect(listed()).toEqual(["cleo", "atlas", "bea", "dodo", "echo"]);
+ expect(listed()).toEqual(["atlas", "bea", "cleo", "dodo", "echo"]);
});
- it("never store the shown order: Alt+Up/Down and drops use the person's own order", () => {
+ it("Alt+Up/Down and drops use the person's own order, a working bot in its place", () => {
busy("cleo", { busy: true });
row("atlas").botDrag!.step("atlas", 1);
expect(actions()).toEqual([{ type: "botsOrdered", botIds: ["bea", "atlas", "cleo"] }]);
diff --git a/src/components/Sidebar.one-list.dom.test.ts b/src/components/Sidebar.one-list.dom.test.ts
index f648639db0..fe3ebb1797 100644
--- a/src/components/Sidebar.one-list.dom.test.ts
+++ b/src/components/Sidebar.one-list.dom.test.ts
@@ -114,20 +114,21 @@ describe("switch on: one list", () => {
it("lists My Cloud's bots in the same list as this computer's, with no group or heading of their own", async () => {
window.ogb = { placesTogether: page } as never;
await render();
- expect(ids('[data-sidebar-section-id="builtin:bots"]')).toEqual(["git", "ledger", "cloud:scout"]);
- expect(ids('[data-sidebar-section-id="builtin:unread"]')).toEqual(["cloud:tech"]);
+ expect(ids('[data-sidebar-section-id="builtin:bots"]')).toEqual(["git", "ledger", "cloud:scout", "cloud:tech"]);
+ expect(q('[data-sidebar-section-id="builtin:unread"]')).toBeNull();
expect([...host.querySelectorAll("[data-section]")].map((header) => header.getAttribute("data-section"))).not.toContain("On My Cloud");
expect(q("[data-other-place]")).toBeNull();
expect(q('[data-sidebar-bot-row="cloud:scout"]')!.textContent).toContain("Open issues");
expect(q('[data-sidebar-bot-row="cloud:tech"]')!.textContent).toContain("Deploy passed on staging.");
});
- it("unread rows of both places share the one Unread group, newest first", async () => {
+ it("unread rows of both places keep their places in the one list", async () => {
window.ogb = { placesTogether: page } as never;
const nova = bot("nova", { unread: true, tasks: [{ threadId: "nova-t", title: "Chat", createdAt: 1, updatedAt: 5_000, unread: true }] });
answer = async () => said({ other: { home: "cloud", state: "ready", bots: [row("old", { unread: true, lastAt: 1_000 }), row("tech", { unread: true, lastAt: 9_000 })] } });
await render([...OWN, nova]);
- expect(ids('[data-sidebar-section-id="builtin:unread"]')).toEqual(["cloud:tech", "nova", "cloud:old"]);
+ expect(ids('[data-sidebar-section-id="builtin:bots"]')).toEqual(["git", "ledger", "nova", "cloud:old", "cloud:tech"]);
+ expect(q('[data-sidebar-section-id="builtin:unread"]')).toBeNull();
});
it("a bot with the same id in both places is two rows, each its own", async () => {
@@ -228,7 +229,7 @@ describe("switch on: one list", () => {
it("the rail's two circles: this computer's page has the one list; My Cloud's page lists My Cloud's bots only, as with the switch off", async () => {
window.ogb = { placesTogether: page } as never;
await render();
- expect(ids('[data-sidebar-section-id="builtin:bots"]')).toEqual(["git", "ledger", "cloud:scout"]);
+ expect(ids('[data-sidebar-section-id="builtin:bots"]')).toEqual(["git", "ledger", "cloud:scout", "cloud:tech"]);
await act(async () => root.unmount());
resetPlacesTogetherForTest(); resetPlaceRowsForTest();
root = createRoot(host);
@@ -245,34 +246,19 @@ describe("switch on: one list", () => {
expect(cloudPage).not.toContain("data-other-place");
});
- it("rows of the other place never push rows under the pointer: they come in plain at the end, and take their place once the list is quiet", async () => {
- vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout", "Date"] });
- try {
- window.ogb = { placesTogether: page } as never;
- let release!: (value: PlacesTogetherState) => void;
- answer = () => new Promise((resolve) => { release = resolve; });
- await render();
- const aside = q("aside")!;
- aside.dispatchEvent(new Event("pointerenter"));
- const local = ids();
- await act(async () => release(said({ other: { home: "cloud", state: "ready", bots: [row("tech", { unread: true, lastAt: 9_000 }), row("scout", { working: true })] } })));
- // The pointer is over the list: this computer's rows stay where they were, the new rows wait at the end, plain.
- expect(ids().slice(0, local.length)).toEqual(local);
- expect(ids('[data-sidebar-section-id="builtin:bots"]')).toEqual(["git", "ledger", "cloud:tech", "cloud:scout"]);
- expect(q('[data-sidebar-section-id="builtin:unread"]')).toBeNull();
- await act(async () => { vi.advanceTimersByTime(10_000); });
- expect(q('[data-sidebar-section-id="builtin:unread"]')).toBeNull();
- // Gone from the list, then a click on it within the quiet time: still waiting.
- aside.dispatchEvent(new Event("pointerleave"));
- aside.dispatchEvent(new Event("pointerdown"));
- await act(async () => { vi.advanceTimersByTime(1_500); });
- expect(q('[data-sidebar-section-id="builtin:unread"]')).toBeNull();
- await act(async () => { vi.advanceTimersByTime(600); });
- expect(ids('[data-sidebar-section-id="builtin:unread"]')).toEqual(["cloud:tech"]);
- expect(ids('[data-sidebar-section-id="builtin:bots"]')).toEqual(["cloud:scout", "git", "ledger"]);
- } finally {
- vi.useRealTimers();
- }
+ it("rows of the other place come in at the end and show their marks at once, with the pointer on the list, moving no row", async () => {
+ window.ogb = { placesTogether: page } as never;
+ let release!: (value: PlacesTogetherState) => void;
+ answer = () => new Promise((resolve) => { release = resolve; });
+ await render();
+ q("aside")!.dispatchEvent(new Event("pointerenter"));
+ const local = ids();
+ await act(async () => release(said({ other: { home: "cloud", state: "ready", bots: [row("tech", { unread: true, lastAt: 9_000 }), row("scout", { working: true })] } })));
+ expect(ids().slice(0, local.length)).toEqual(local);
+ expect(ids('[data-sidebar-section-id="builtin:bots"]')).toEqual(["git", "ledger", "cloud:tech", "cloud:scout"]);
+ expect(q('[data-sidebar-section-id="builtin:unread"]')).toBeNull();
+ // No wait for the list to go quiet: Scout's working mark shows now, in its place.
+ expect(q('[data-sidebar-bot-row="cloud:scout"] [data-testid="working-dot"]')).not.toBeNull();
});
it("an answer that changes nothing moves nothing: the same rows stay, the same elements", async () => {
@@ -329,6 +315,6 @@ describe("switch on: one list", () => {
expect(ids()).toEqual(["mausbot", "git", "ledger"].filter((id) => q(`[data-sidebar-bot-row="${id}"]`)));
expect(ids('[data-sidebar-section-id="builtin:bots"]')).toEqual(["git", "ledger"]);
await act(async () => release(said()));
- expect(ids('[data-sidebar-section-id="builtin:bots"]')).toEqual(["git", "ledger", "cloud:scout"]);
+ expect(ids('[data-sidebar-section-id="builtin:bots"]')).toEqual(["git", "ledger", "cloud:scout", "cloud:tech"]);
});
});
diff --git a/src/components/Sidebar.simple-layout.test.ts b/src/components/Sidebar.simple-layout.test.ts
index 8e9d737aba..e23775c329 100644
--- a/src/components/Sidebar.simple-layout.test.ts
+++ b/src/components/Sidebar.simple-layout.test.ts
@@ -47,7 +47,6 @@ import { initialState, reducer } from "@/state/store";
import { BOTS_SECTION_ID, CHANNELS_SECTION_ID, PINNED_SECTION_ID, UNREAD_SECTION_ID, userSectionId } from "@/lib/sidebar-layout";
import { SIDEBAR_COLLAPSED_SECTIONS_KEY, SIDEBAR_DENSITY_KEY, SIDEBAR_SECTION_ORDER_KEY, SIDEBAR_WIDTH_KEY, SIMPLE_SIDEBAR_SECTION_ORDER_KEY, SIMPLE_SIDEBAR_WIDTH_KEY, setSidebarDensity } from "@/lib/sidebar-preferences";
import { Sidebar, TeamMenuItems } from "./Sidebar";
-import { BOT_ROW_DRAG_TYPE } from "@/lib/sidebar-bot-drop";
import type { BotRowDrag } from "./SidebarBotDrag";
const drawSidebar = (Sidebar as unknown as { type: (props: import("react").ComponentProps<typeof Sidebar>) => import("react").ReactNode }).type;
import { PinnedBotRoster } from "./PinnedCircleThreads";
@@ -406,8 +405,7 @@ describe("Simple-mode sidebar layout", () => {
});
});
-describe("the sidebar's Unread section", () => {
- const unreadHeader = (tree: ReactElement<Props>[]) => headers(tree).find((header) => header.props.name === "Unread");
+describe("unread bots keep their place", () => {
const thread = (id: string, updatedAt: number, unread = true) => ({ threadId: `${id}-thread`, title: id, createdAt: 1, updatedAt, unread });
const withUnread = () => {
fixture.state = { ...fixture.state, bots: [
@@ -418,214 +416,66 @@ describe("the sidebar's Unread section", () => {
bot("eve", { section: "Work" }),
] };
};
+ const rowOf = (tree: ReactElement<Props>[], id: string) => tree.find((node) => (node.props.bot as Bot | undefined)?.id === id)!.props as { botDrag: BotRowDrag };
- it("is absent while every bot is read", () => {
- const { tree } = render();
- expect(sectionOrder(tree)).not.toContain(UNREAD_SECTION_ID);
- expect(unreadHeader(tree)).toBeUndefined();
- });
-
- it("gathers the unread bots of the main list and of departments above the rest, newest first, with their count", () => {
+ it("lists an unread bot in its own place, with no Unread list and no Bots heading", () => {
withUnread();
const { tree } = render();
- expect(sectionOrder(tree)).toEqual([UNREAD_SECTION_ID, BOTS_SECTION_ID, CHANNELS_SECTION_ID, userSectionId("Work")]);
- expect(listedBots(tree)).toEqual(["cora", "dodo", "bea", "atlas", "eve"]);
- expect(unreadHeader(tree)!.props).toMatchObject({ count: 3, reorderable: false, line: true });
- expect(headers(tree).map((header) => [header.props.name, "count" in header.props])).toEqual([["Unread", true], ["Bots", false], ["Group chats", false], ["Work", false]]);
- });
-
- it("keeps the bot opened from it listed in its place, and sends it back to its own place once another chat is open", () => {
- withUnread();
- render();
- fixture.state = reducer(fixture.state, { type: "select", id: "dodo" });
- let tree = render().tree;
- expect(listedBots(tree)).toEqual(["cora", "dodo", "bea", "atlas", "eve"]);
- expect(unreadHeader(tree)!.props.count).toBe(2);
- expect(tree.find((node) => (node.props.bot as Bot | undefined)?.id === "dodo")!.props.botDrag).toBeUndefined();
-
- fixture.state = reducer(fixture.state, { type: "select", id: "cora" });
- tree = render().tree;
- expect(listedBots(tree)).toEqual(["cora", "bea", "atlas", "dodo", "eve"]);
- expect(unreadHeader(tree)!.props.count).toBe(1);
-
- fixture.state = reducer(fixture.state, { type: "select", id: "room" });
- tree = render().tree;
- expect(listedBots(tree)).toEqual(["bea", "atlas", "cora", "dodo", "eve"]);
-
- fixture.state = reducer(fixture.state, { type: "select", id: "bea" });
- tree = render().tree;
- expect(sectionOrder(tree)).toEqual([UNREAD_SECTION_ID, BOTS_SECTION_ID, CHANNELS_SECTION_ID, userSectionId("Work")]);
- expect(listedBots(tree)).toEqual(["bea", "atlas", "cora", "dodo", "eve"]);
- expect("count" in unreadHeader(tree)!.props).toBe(false);
-
- fixture.state = reducer(reducer(fixture.state, { type: "select", id: "bea" }), { type: "showFiles" });
- tree = render().tree;
expect(sectionOrder(tree)).toEqual([BOTS_SECTION_ID, CHANNELS_SECTION_ID, userSectionId("Work")]);
+ expect(sectionOrder(tree)).not.toContain(UNREAD_SECTION_ID);
expect(listedBots(tree)).toEqual(["atlas", "bea", "cora", "dodo", "eve"]);
+ expect(headers(tree).map((header) => header.props.name)).toEqual(["Group chats", "Work"]);
});
- it("sends the bot opened from it back to its own place once another conversation with that bot is open", () => {
- const openDodo = () => {
- withUnread();
- render();
- fixture.state = reducer(fixture.state, { type: "select", id: "dodo" });
- expect(listedBots(render().tree)).toEqual(["cora", "dodo", "bea", "atlas", "eve"]);
- };
- openDodo();
- fixture.state = reducer(fixture.state, { type: "newTask", botId: "dodo" });
- expect(fixture.state.newChat?.botId).toBe("dodo");
- let tree = render().tree;
- expect(listedBots(tree)).toEqual(["cora", "bea", "atlas", "dodo", "eve"]);
- expect(unreadHeader(tree)!.props.count).toBe(2);
-
- openDodo();
- fixture.state = { ...fixture.state, bots: fixture.state.bots.map((candidate) => (candidate.id === "dodo" ? { ...candidate, tasks: [...candidate.tasks!, { ...thread("dodo", 5, false), threadId: "dodo-other" }] } : candidate)) };
- expect(listedBots(render().tree)).toEqual(["cora", "dodo", "bea", "atlas", "eve"]);
- fixture.state = reducer(fixture.state, { type: "switchTask", botId: "dodo", threadId: "dodo-other" });
- tree = render().tree;
- expect(listedBots(tree)).toEqual(["cora", "bea", "atlas", "dodo", "eve"]);
- expect(unreadHeader(tree)!.props.count).toBe(2);
- });
-
- it("keeps a held bot listed when it is marked unread or gets a new message, by the normal rule", () => {
- withUnread();
- render();
+ it("moves no row when a bot is opened, gets a reply, is marked unread, works or waits on the person while the app is in use", () => {
+ const shown = () => { const { tree } = render(); return { sections: sectionOrder(tree), bots: listedBots(tree) }; };
+ const before = shown();
fixture.state = reducer(fixture.state, { type: "select", id: "bea" });
- expect(listedBots(render().tree)).toEqual(["cora", "dodo", "bea", "atlas", "eve"]);
-
- fixture.state = reducer(fixture.state, { type: "markUnread", botId: "bea" });
- fixture.state = { ...fixture.state, bots: fixture.state.bots.map((candidate) => (candidate.id === "bea" ? { ...candidate, tasks: [thread("bea", 20)] } : candidate)) };
- let tree = render().tree;
- expect(listedBots(tree)).toEqual(["cora", "dodo", "bea", "atlas", "eve"]);
- expect(unreadHeader(tree)!.props.count).toBe(3);
-
- fixture.state = { ...fixture.state, bots: fixture.state.bots.map((candidate) => (candidate.id === "bea" ? { ...candidate, tasks: [thread("bea", 90)] } : candidate)) };
- tree = render().tree;
- expect(listedBots(tree)).toEqual(["bea", "cora", "dodo", "atlas", "eve"]);
- });
-
- it("brings a read bot to it when it is marked unread", () => {
+ expect(shown()).toEqual(before);
+ fixture.state = { ...fixture.state, bots: fixture.state.bots.map((candidate) => (candidate.id === "bea" ? { ...candidate, unread: true, tasks: [thread("bea", 90)] } : candidate)) };
+ expect(shown()).toEqual(before);
fixture.state = reducer(fixture.state, { type: "markUnread", botId: "dodo" });
- const { tree } = render();
- expect(sectionOrder(tree)[0]).toBe(UNREAD_SECTION_ID);
- expect(listedBots(tree)).toEqual(["dodo", "atlas", "bea"]);
- expect(unreadHeader(tree)!.props.count).toBe(1);
- });
-
- it("arranges the rows left in place around a held one with Alt+arrow", () => {
- vi.stubGlobal("requestAnimationFrame", () => 0);
- vi.stubGlobal("fetch", () => new Promise(() => {}));
- fixture.state = { ...fixture.state, bots: [bot("atlas"), bot("bea", { unread: true }), bot("cora"), bot("dodo", { section: "Work" })] };
- render();
- fixture.state = reducer(fixture.state, { type: "select", id: "bea" });
- const tree = render().tree;
- expect(listedBots(tree)).toEqual(["bea", "atlas", "cora", "dodo"]);
- rowOf(tree, "atlas").botDrag.step("atlas", 1);
- expect(fixture.dispatch).toHaveBeenCalledWith({ type: "botsOrdered", botIds: ["cora", "atlas"] });
- });
-
- it("keeps a department whose bots are all unread, and takes no drag on its own rows", () => {
- withUnread();
- fixture.state = { ...fixture.state, sections: [], bots: fixture.state.bots.filter((candidate) => candidate.id !== "eve") };
- const { tree } = render();
- expect(sectionOrder(tree)).toContain(userSectionId("Work"));
- const rows = tree.filter((node) => (node.props.bot as Bot | undefined) !== undefined);
- expect(rows.map((row) => [(row.props.bot as Bot).id, row.props.botDrag !== undefined])).toEqual([["cora", false], ["dodo", false], ["bea", false], ["atlas", true]]);
- });
-
- const rowOf = (tree: ReactElement<Props>[], id: string) => tree.find((node) => (node.props.bot as Bot | undefined)?.id === id)!.props as { botDrag: BotRowDrag };
- const sectionZone = (tree: ReactElement<Props>[], id: string) => tree.find((node) => node.props["data-sidebar-section-id"] === id)!.props as unknown as Record<"onDragOver" | "onDrop", (event: unknown) => void>;
- const dragEvent = (types: string[] = []) => ({
- preventDefault: vi.fn(), stopPropagation: () => {}, clientY: 0, dataTransfer: { types, setData: () => {}, getData: () => "" },
- currentTarget: { querySelectorAll: () => [], getBoundingClientRect: () => ({ top: 0, height: 40 }) },
+ expect(shown()).toEqual(before);
+ fixture.state = { ...fixture.state, bots: fixture.state.bots.map((candidate) => (candidate.id === "bea" ? { ...candidate, busy: true, activity: "working" as const } : candidate.id === "dodo" ? { ...candidate, activity: "waiting-on-you" as const } : candidate)) };
+ expect(shown()).toEqual(before);
+ fixture.state = reducer(fixture.state, { type: "select", id: "room" });
+ expect(shown()).toEqual(before);
});
- it.each([["cora", -1], ["atlas", 1]] as const)("moves %s past the row it is shown next to with Alt+arrow, not past one Unread is listing", (id, direction) => {
+ it("moves a bot past an unread one with Alt+arrow, as the person sees them", () => {
vi.stubGlobal("requestAnimationFrame", () => 0);
vi.stubGlobal("fetch", () => new Promise(() => {}));
fixture.state = { ...fixture.state, bots: [bot("atlas"), bot("bea", { unread: true }), bot("cora"), bot("dodo", { section: "Work" })] };
let tree = render().tree;
- expect(listedBots(tree)).toEqual(["bea", "atlas", "cora", "dodo"]);
-
- rowOf(tree, id).botDrag.step(id, direction);
- expect(fixture.dispatch).toHaveBeenCalledWith({ type: "botsOrdered", botIds: ["cora", "atlas"] });
- fixture.state = reducer(fixture.state, { type: "botsOrdered", botIds: ["cora", "atlas"] });
- tree = render().tree;
- expect(listedBots(tree)).toEqual(["bea", "cora", "atlas", "dodo"]);
- expect(fixture.state.bots.map((candidate) => candidate.id)).toEqual(["cora", "bea", "atlas", "dodo"]);
- });
-
- it("offers the main list to a bot dragged out of its department while every bot of that list is unread", () => {
- fixture.state = { ...fixture.state, bots: [bot("atlas", { unread: true }), bot("bea", { unread: true }), bot("dodo", { section: "Work" })] };
- let tree = render().tree;
- expect(sectionOrder(tree)).toEqual([UNREAD_SECTION_ID, CHANNELS_SECTION_ID, userSectionId("Work")]);
-
- rowOf(tree, "dodo").botDrag.row("dodo").onDragStart(dragEvent() as never);
+ expect(listedBots(tree)).toEqual(["atlas", "bea", "cora", "dodo"]);
+ rowOf(tree, "atlas").botDrag.step("atlas", 1);
+ expect(fixture.dispatch).toHaveBeenCalledWith({ type: "botsOrdered", botIds: ["bea", "atlas", "cora"] });
+ fixture.state = reducer(fixture.state, { type: "botsOrdered", botIds: ["bea", "atlas", "cora"] });
tree = render().tree;
- expect(sectionOrder(tree)).toEqual([UNREAD_SECTION_ID, BOTS_SECTION_ID, CHANNELS_SECTION_ID, userSectionId("Work")]);
- expect(tree.some((node) => node.props["data-bot-drop-slot"] === "")).toBe(true);
-
- sectionZone(tree, BOTS_SECTION_ID).onDrop(dragEvent([BOT_ROW_DRAG_TYPE]));
- expect(fixture.dispatch).toHaveBeenCalledWith({ type: "updateBot", botId: "dodo", patch: { section: "" } });
+ expect(listedBots(tree)).toEqual(["bea", "atlas", "cora", "dodo"]);
});
- it("takes no dragged section and shows no line for one, since it has no place in the order", () => {
+ it("keeps the rail's groups as they are", () => {
withUnread();
- const lines = (tree: ReactElement<Props>[]) => tree.filter((node) => node.props.className === "mx-2 h-0.5 rounded-full bg-accent").length;
- let tree = render().tree;
- headers(tree).find((header) => header.props.name === "Work")!.props.onDragStart!(dragEvent() as never);
- tree = render().tree;
-
- const overBots = dragEvent();
- sectionZone(tree, BOTS_SECTION_ID).onDragOver(overBots);
- expect(overBots.preventDefault).toHaveBeenCalled();
- expect(lines(render().tree)).toBe(1);
-
- const overUnread = dragEvent();
- sectionZone(tree, UNREAD_SECTION_ID).onDragOver(overUnread);
- expect(overUnread.preventDefault).not.toHaveBeenCalled();
- expect(lines(render().tree)).toBe(0);
+ setSidebarDensity("icons");
+ const { tree } = render();
+ expect(sectionOrder(tree)).toEqual([BOTS_SECTION_ID, CHANNELS_SECTION_ID, userSectionId("Work")]);
+ expect(listedBots(tree)).toEqual(["atlas", "bea", "cora", "dodo", "eve"]);
});
- it("leaves pinned bots and the Chief where they are, and sits under Advanced's Pinned heading", () => {
+ it("leaves pinned bots and the Chief where they are, in Simple and Advanced", () => {
fixture.state = { ...fixture.state, bots: [
bot("chief", { chiefOfStaff: true, unread: true }), bot("atlas", { pinned: true, unread: true }), bot("bea", { unread: true }), bot("cora"),
] };
let tree = render().tree;
const grid = tree.find((node) => node.type === SidebarTileGrid)!.props as Parameters<typeof SidebarTileGrid>[0];
expect([grid.primary?.id, ...grid.pinned.map((candidate) => candidate.id)]).toEqual(["chief", "atlas"]);
- expect(sectionOrder(tree).slice(0, 2)).toEqual([UNREAD_SECTION_ID, BOTS_SECTION_ID]);
+ expect(sectionOrder(tree)[0]).toBe(BOTS_SECTION_ID);
expect(listedBots(tree)).toEqual(["bea", "cora"]);
fixture.advanced = true;
tree = render().tree;
- expect(sectionOrder(tree).slice(0, 2)).toEqual([PINNED_SECTION_ID, UNREAD_SECTION_ID]);
+ expect(sectionOrder(tree)).toEqual([PINNED_SECTION_ID, CHANNELS_SECTION_ID, BOTS_SECTION_ID, userSectionId("Work")]);
expect(listedBots(tree)).toEqual(["chief", "bea", "cora"]);
- expect(unreadHeader(tree)!.props).toMatchObject({ count: 1, reorderable: false, line: false });
- });
-
- it("stays at the top whatever order the sections were dragged into", () => {
- withUnread();
- fixture.storage.set(SIMPLE_SIDEBAR_SECTION_ORDER_KEY, JSON.stringify([userSectionId("Work"), CHANNELS_SECTION_ID, BOTS_SECTION_ID]));
- expect(sectionOrder(render().tree)).toEqual([UNREAD_SECTION_ID, userSectionId("Work"), CHANNELS_SECTION_ID, BOTS_SECTION_ID]);
- });
-
- it("gives way to a search, which lists every match in its own place", () => {
- withUnread();
- (render().tree.find((node) => node.type === SidebarSearchToggle)!.props as Parameters<typeof SidebarSearchToggle>[0]).onToggle();
- (render().tree.find((node) => node.type === SidebarSearchPill)!.props as Parameters<typeof SidebarSearchPill>[0]).onQuery("o");
- const { tree } = render();
- expect(sectionOrder(tree)).not.toContain(UNREAD_SECTION_ID);
- expect(listedBots(tree)).toEqual(["cora", "dodo"]);
- });
-
- it("leads the rail as a group of its own, with no heading", () => {
- withUnread();
- setSidebarDensity("icons");
- const { tree } = render();
- expect(sectionOrder(tree)).toEqual([UNREAD_SECTION_ID, BOTS_SECTION_ID, CHANNELS_SECTION_ID, userSectionId("Work")]);
- expect(listedBots(tree)).toEqual(["cora", "dodo", "bea", "atlas", "eve"]);
- expect(headers(tree)).toEqual([]);
- expect(tree.filter((node) => node.type === SidebarRailSeparator)).toHaveLength(3);
});
});
diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx
index 09ec7866e4..2d1e3bcfdb 100644
--- a/src/components/Sidebar.tsx
+++ b/src/components/Sidebar.tsx
@@ -85,7 +85,7 @@ import { PHONE_TOP_BUTTON, SIMPLE_CORNER_BUTTON, SIMPLE_ROW_FOCUS, SIMPLE_TOP_BU
import { isSidebarToggle } from "@/lib/keyboard-shortcuts";
import { SidebarRailSeparator, SimpleRailFooter } from "./SidebarSimpleRail";
import { useShowThreads } from "@/lib/thread-preferences";
-import { useBotUnread, useUnreadHold } from "./unread-notice";
+import { useBotUnread } from "./unread-notice";
import { attentionHasRunningWork, attentionJump, crossBotAttentionThreads, hasCrossBotRunningWork, runningRoutineRun, SidebarBotActivity, sidebarBotActivityTasks, sidebarBotStatus } from "./SidebarBotActivity";
import { SidebarNoBots, SidebarTileGrid } from "./SidebarTiles";
import { BotContextMenu } from "./SidebarBotMenu";
@@ -1093,15 +1093,14 @@ export const Sidebar = memo(function Sidebar({ open, onClose, collapseToIcons =
b.projects?.some((folder) => folder.name.toLowerCase().includes(q)),
);
const visibleGroups = sideLists.groups.filter((g) => !q || g.name.toLowerCase().includes(q) || g.tasks?.some((task) => task.title.toLowerCase().includes(q)));
- const viewerEmail = useViewerEmail(), placed = useOtherPlaceBots(q, sidebarRef), placeHere = useOneListHere();
+ const viewerEmail = useViewerEmail(), placed = useOtherPlaceBots(q), placeHere = useOneListHere();
const parts = partitionSidebarBots(botDrag.preview(matchingBots), { universalPins, viewerEmail, welcoming: useWelcomingBot(), searching: Boolean(q) });
const saved = withOtherPlace(simpleDesk ? withPrimaryTile(parts, myDefaultBot(state.bots, viewerEmail)?.id) : { ...parts, primary: null }, placed);
- // Shown order only: a drag or Alt+Up/Down moves a bot among the rows as drawn and saves it into the saved order of the
- // rows left in place; a row Unread lists is in neither.
- const floats = (bot: Bot) => { const { waiting, working } = sidebarBotStatus(bot, state.pendingQueued); return waiting || working; };
+ // Rows keep their place while the app is in use: unread, work and a wait on the person show as marks on the row, never
+ // as a move to the top or into an Unread list. Only a pin, a drag, Alt+Up/Down or a move to a department moves a row.
+ const floats = () => false;
const { primary, unsectionedChief } = saved;
- const { pinnedBots, filed, unreadBots, unreadCount, sectionChiefs, sectionedBots, unsectionedBots, inPlace } = sidebarBotRows(saved, floats, !q,
- useUnreadHold(state.activeView === "chat" ? state.selectedId : null, sideLists.bots, state.newChat?.botId));
+ const { pinnedBots, filed, unreadBots, unreadCount, sectionChiefs, sectionedBots, unsectionedBots, inPlace } = sidebarBotRows(saved, floats, false);
const { botChats, sectionedRooms, unsectionedRooms } = partitionSidebarGroups(visibleGroups);
const sectionNames = sectionsInUse([...(state.sections ?? []).filter((name) => !q || name.toLowerCase().includes(q.toLowerCase())), ...botDrag.pending], [...filed, ...sectionedRooms]);
diff --git a/src/components/SidebarSectionHeader.test.ts b/src/components/SidebarSectionHeader.test.ts
index 8f2dfbdba2..6ed01021fa 100644
--- a/src/components/SidebarSectionHeader.test.ts
+++ b/src/components/SidebarSectionHeader.test.ts
@@ -198,18 +198,31 @@ describe("SidebarSectionHeader as a Simple-mode line", () => {
expect(renderToStaticMarkup(line())).not.toContain("lucide-chevron-right");
});
- it("marks a collapsed line with one dot, the most urgent of waiting, unread and working, and no number", () => {
+ it("marks a collapsed line with a dot for waiting and one for unread, so a wait never hides unread rows", () => {
const marks = (attention: { waiting: number; unread: number; working: number }) =>
renderToStaticMarkup(line({ collapsed: true, attention })).match(/data-section-mark="(\w+)"/g) ?? [];
- expect(marks({ waiting: 1, unread: 2, working: 1 })).toEqual(['data-section-mark="waiting"']);
+ expect(marks({ waiting: 1, unread: 3, working: 1 })).toEqual(['data-section-mark="waiting"', 'data-section-mark="unread"']);
+ expect(marks({ waiting: 1, unread: 0, working: 1 })).toEqual(['data-section-mark="waiting"']);
expect(marks({ waiting: 0, unread: 2, working: 1 })).toEqual(['data-section-mark="unread"']);
expect(marks({ waiting: 0, unread: 0, working: 3 })).toEqual(['data-section-mark="working"']);
expect(marks({ waiting: 0, unread: 0, working: 0 })).toEqual([]);
+ expect(renderToStaticMarkup(line({ collapsed: false, attention: { waiting: 1, unread: 0, working: 0 } }))).not.toContain("data-section-mark");
+ });
+
+ it("shows how many rows inside need the person, in the count's own type, beside the dots", () => {
+ const needs = (attention: { waiting: number; unread: number; working: number; needsYou?: number }) =>
+ /data-section-needs=""[^>]*>(\d+)</.exec(renderToStaticMarkup(line({ collapsed: true, attention })))?.[1];
+ expect(needs({ waiting: 1, unread: 3, working: 0 })).toBe("4");
+ expect(needs({ waiting: 0, unread: 12, working: 0 })).toBe("12");
+ // A waiting bot that is also unread is one row.
+ expect(needs({ waiting: 1, unread: 3, working: 0, needsYou: 3 })).toBe("3");
+ expect(needs({ waiting: 0, unread: 0, working: 2 })).toBeUndefined();
const html = renderToStaticMarkup(line({ collapsed: true, attention: { waiting: 0, unread: 12, working: 0 } }));
- expect(html).not.toContain(">12<");
- expect(html).not.toContain("text-[9px]");
+ expect(html).toContain("text-[12px] leading-4 tabular-nums text-ink-tertiary");
expect(html).toContain('title="12 unread"');
- expect(renderToStaticMarkup(line({ collapsed: false, attention: { waiting: 1, unread: 0, working: 0 } }))).not.toContain("data-section-mark");
+ expect(html).not.toContain("text-[9px]");
+ expect(renderToStaticMarkup(line({ collapsed: false, attention: { waiting: 0, unread: 2, working: 0 } }))).not.toContain("data-section-needs");
+ expect(renderToStaticMarkup(line({ collapsed: true, alert: true, attention: { waiting: 1, unread: 2, working: 0 } }))).not.toContain("data-section-needs");
});
it("draws the working pulse still when motion is reduced", () => {
diff --git a/src/components/SidebarSectionHeader.tsx b/src/components/SidebarSectionHeader.tsx
index eb2b276982..97b509e324 100644
--- a/src/components/SidebarSectionHeader.tsx
+++ b/src/components/SidebarSectionHeader.tsx
@@ -254,23 +254,32 @@ const SECTION_MARK: Record<SectionMark, string> = {
working: "size-1.5 animate-pulse bg-success motion-reduce:animate-none",
};
-function sectionMark(attention: SidebarSectionAttention | undefined): SectionMark | null {
- if (!attention) return null;
- if (attention.waiting > 0) return "waiting";
- if (attention.unread > 0) return "unread";
- if (attention.working > 0) return "working";
- return null;
+/** Waiting and unread each keep their own dot, so a wait never hides unread rows; working shows only when neither does. */
+function sectionMarks(attention: SidebarSectionAttention | undefined): SectionMark[] {
+ if (!attention) return [];
+ const marks: SectionMark[] = [];
+ if (attention.waiting > 0) marks.push("waiting");
+ if (attention.unread > 0) marks.push("unread");
+ if (marks.length === 0 && attention.working > 0) marks.push("working");
+ return marks;
+}
+
+/** How many rows inside need the person: unread or waiting on them. */
+function needsYouCount(attention: SidebarSectionAttention | undefined): number {
+ return attention ? attention.needsYou ?? attention.unread + attention.waiting : 0;
}
function SectionAttention({ attention, label, alert }: { attention?: SidebarSectionAttention; label: string; alert?: boolean }) {
- const mark = alert ? null : sectionMark(attention);
+ const marks = alert ? [] : sectionMarks(attention);
+ const needs = alert ? 0 : needsYouCount(attention);
return (
<>
- {mark && (
- <span aria-hidden="true" title={label} data-section-mark={mark} className="flex size-4 shrink-0 items-center justify-center">
+ {needs > 0 && <span aria-hidden="true" title={label} data-section-needs="" className="shrink-0 text-[12px] leading-4 tabular-nums text-ink-tertiary">{needs}</span>}
+ {marks.map((mark) => (
+ <span key={mark} aria-hidden="true" title={label} data-section-mark={mark} className="flex size-4 shrink-0 items-center justify-center">
<span className={cn("rounded-full", SECTION_MARK[mark])} />
</span>
- )}
+ ))}
{label && <span className="sr-only">{label}</span>}
{alert && (
<>
diff --git a/src/lib/place-rows.ts b/src/lib/place-rows.ts
index a0ab6a0c47..3d1fbe4d2d 100644
--- a/src/lib/place-rows.ts
+++ b/src/lib/place-rows.ts
@@ -10,7 +10,7 @@
// Everything here is keyed by a place, not by "My Cloud": today the places are this computer and My Cloud, and a
// person's own always-on machine (a server of their own, or a computer at home) is meant to join the same list later
// as one more place, with its own key, kind, name and state.
-import { useEffect, useSyncExternalStore, type Dispatch, type RefObject } from "react";
+import type { Dispatch } from "react";
import { BOT_BODY_IDS, type BotBodyId } from "../../shared/bot-body";
import { MASCOT_FACE_COLORS, mascotBodyColorSchema, mascotMaterialSchema, type MascotFaceColor } from "../../shared/bot-avatar";
import type { Action, Bot } from "@/state/store";
@@ -123,10 +123,8 @@ function placedList(state: PlacesTogetherState | null): readonly PlacedBot[] {
/** The other place's bots for the one list, matching the sidebar's search (`query`, already trimmed and lower case).
* The same empty list while the switch is off, in a browser, and on any other place's page. */
-export function useOtherPlaceBots(query: string, list?: RefObject<HTMLElement | null>): readonly PlacedBot[] {
- useQuietList(list);
- const answered = usePlacesTogetherPart(placedList);
- const all = useSyncExternalStore(subscribeQuiet, () => settled(answered), () => settled(answered));
+export function useOtherPlaceBots(query: string): readonly PlacedBot[] {
+ const all = usePlacesTogetherPart(placedList);
if (!query || !all.length) return all;
if (lastSearch.all !== all || lastSearch.query !== query) {
lastSearch = { all, query, found: all.filter((bot) => bot.name.toLowerCase().includes(query) || bot.title.toLowerCase().includes(query)) };
@@ -136,76 +134,8 @@ export function useOtherPlaceBots(query: string, list?: RefObject<HTMLElement |
/** The last search's rows, kept while the list and the words stay the same (no hook: the sidebar calls this on every draw). */
let lastSearch: { all: readonly PlacedBot[]; query: string; found: readonly PlacedBot[] } = { all: NONE, query: "", found: NONE };
-// Rows of the other place never push rows the person can already see. They come in after this page's own and are
-// ranked (Unread, working first) only while the list is quiet: the pointer is not over it and it has not been clicked,
-// typed in or scrolled for QUIET_MS. Until then a new row of the other place is listed at the end of the main list as
-// a plain row, and a row that changed keeps the place it had; both take their place once the list is quiet.
-export const QUIET_MS = 2_000;
-const quiet = { inside: false, lastAt: -Infinity, version: 0, pending: false, timer: null as ReturnType<typeof setTimeout> | null };
-const quietListeners = new Set<() => void>();
-const subscribeQuiet = (listener: () => void) => { quietListeners.add(listener); return () => { quietListeners.delete(listener); }; };
-const isQuiet = () => !quiet.inside && Date.now() - quiet.lastAt >= QUIET_MS;
-/** What each row of the other place was last ranked by. */
-let ranked = new Map<string, PlacedBot>();
-const plain = new WeakMap<PlacedBot, PlacedBot>();
-let lastSettled: { answered: readonly PlacedBot[]; version: number; list: readonly PlacedBot[] } | null = null;
-
-function settleWhenQuiet(): void {
- if (quiet.timer !== null) clearTimeout(quiet.timer);
- quiet.timer = null;
- if (quiet.inside || !quiet.pending) return;
- quiet.timer = setTimeout(() => {
- quiet.timer = null;
- if (!isQuiet()) { settleWhenQuiet(); return; }
- quiet.version += 1;
- for (const listener of quietListeners) listener();
- }, Math.max(0, quiet.lastAt + QUIET_MS - Date.now()));
-}
-
-/** A row of the other place as it is ranked before its place in the list is settled: no unread, no work, no time. */
-function plainRow(bot: PlacedBot): PlacedBot {
- let row = plain.get(bot);
- if (!row) { row = { ...bot, unread: false, busy: undefined, activity: undefined, lastAt: undefined }; plain.set(bot, row); }
- return row;
-}
-
-function settled(answered: readonly PlacedBot[]): readonly PlacedBot[] {
- if (lastSettled && lastSettled.answered === answered && lastSettled.version === quiet.version) return lastSettled.list;
- let list: readonly PlacedBot[];
- if (isQuiet()) {
- ranked = new Map(answered.map((bot) => [bot.id, bot]));
- quiet.pending = false;
- list = answered;
- } else {
- const next = answered.map((bot) => ranked.get(bot.id) ?? plainRow(bot));
- quiet.pending = next.some((bot, index) => bot !== answered[index]);
- const before = lastSettled?.list;
- list = before && before.length === next.length && next.every((bot, index) => bot === before[index]) ? before : next;
- settleWhenQuiet();
- }
- lastSettled = { answered, version: quiet.version, list };
- return list;
-}
-
-/** Follows the pointer and the person's clicks, keys and scrolling on the list, for QUIET_MS. */
-function useQuietList(list?: RefObject<HTMLElement | null>): void {
- useEffect(() => {
- const element = list?.current;
- if (!element) return;
- const touched = () => { quiet.lastAt = Date.now(); settleWhenQuiet(); };
- const enter = () => { quiet.inside = true; settleWhenQuiet(); };
- const leave = () => { quiet.inside = false; settleWhenQuiet(); };
- const events: Array<[string, () => void]> = [["pointerenter", enter], ["pointerleave", leave], ["pointerdown", touched], ["keydown", touched], ["wheel", touched]];
- for (const [name, handler] of events) element.addEventListener(name, handler, { passive: true });
- element.addEventListener("scroll", touched, { capture: true, passive: true });
- return () => {
- for (const [name, handler] of events) element.removeEventListener(name, handler);
- element.removeEventListener("scroll", touched, { capture: true });
- quiet.inside = false;
- };
- }, [list]);
-}
-
+// Rows of the other place come in after this page's own and keep their place, like every row: unread and work show as
+// marks on the row as soon as the other place says so, never as a move.
/** The sidebar's parts with the other place's rows after this place's own in the main list: the busy-first order and
* Unread then take every row the same way. Departments, pins and tiles stay this place's own. */
export function withOtherPlace<T extends { unsectionedBots: Bot[] }>(parts: T, placed: readonly PlacedBot[]): T {
@@ -323,9 +253,5 @@ export function resetPlaceRowsForTest(): void {
lastList = NONE;
lastSearch = { all: NONE, query: "", found: NONE };
lastRows = null;
- ranked = new Map();
- lastSettled = null;
- if (quiet.timer !== null) clearTimeout(quiet.timer);
- Object.assign(quiet, { inside: false, lastAt: -Infinity, version: 0, pending: false, timer: null });
openers.clear();
}
diff --git a/src/lib/sidebar-attention.test.ts b/src/lib/sidebar-attention.test.ts
index 7f14fe7534..c4b871cb1f 100644
--- a/src/lib/sidebar-attention.test.ts
+++ b/src/lib/sidebar-attention.test.ts
@@ -12,7 +12,7 @@ describe("collapsed sidebar attention", () => {
[{ unread: true }, { busyBotId: "writer" }],
);
- expect(attention).toEqual({ unread: 2, waiting: 1, working: 2 });
+ expect(attention).toEqual({ unread: 2, waiting: 1, working: 2, needsYou: 2 });
expect(sidebarAttentionLabel(attention)).toBe(
"1 waiting for you, 2 unread, 2 working",
);
@@ -21,6 +21,14 @@ describe("collapsed sidebar attention", () => {
it("does not count a waiting bot twice as working", () => {
expect(
sidebarSectionAttention([{ busy: true, activity: "waiting-on-you" }], []),
- ).toEqual({ unread: 0, waiting: 1, working: 0 });
+ ).toEqual({ unread: 0, waiting: 1, working: 0, needsYou: 1 });
+ });
+
+ it("counts each row that needs the person once, though a waiting bot is unread too", () => {
+ const attention = sidebarSectionAttention(
+ [{ unread: true, activity: "waiting-on-you" }, { unread: true }, { unread: true }, { activity: "waiting-on-you" }, { busy: true }],
+ [{ unread: true }],
+ );
+ expect(attention).toMatchObject({ unread: 4, waiting: 2, needsYou: 5 });
});
});
diff --git a/src/lib/sidebar-attention.ts b/src/lib/sidebar-attention.ts
index 632b6930bc..27f2a86c13 100644
--- a/src/lib/sidebar-attention.ts
+++ b/src/lib/sidebar-attention.ts
@@ -18,6 +18,8 @@ export type SidebarSectionAttention = {
unread: number;
waiting: number;
working: number;
+ /** Rows that are unread or wait on the person, each counted once (a waiting bot is often unread too). */
+ needsYou?: number;
};
export function sidebarSectionAttention(
@@ -29,6 +31,8 @@ export function sidebarSectionAttention(
bots.filter(botShowsUnread).length +
groups.filter((group) => Boolean(group.unread)).length,
waiting: bots.filter((bot) => bot.activity === "waiting-on-you").length,
+ needsYou: bots.filter((bot) => botShowsUnread(bot) || bot.activity === "waiting-on-you").length +
+ groups.filter((group) => Boolean(group.unread)).length,
working:
bots.filter(
(bot) =>