Skip to content

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

Forget a conversation's kept file preview when a new one opens there

AdityaUmaleee0f2d013859
diff --git a/src/components/FilePreviewPanel.dom.test.ts b/src/components/FilePreviewPanel.dom.test.ts
index 86c21ab80b..00c4fdab04 100644
--- a/src/components/FilePreviewPanel.dom.test.ts
+++ b/src/components/FilePreviewPanel.dom.test.ts
@@ -135,6 +135,22 @@ describe("a file opened from the chat on a wide window", () => {
expect(pane()?.getAttribute("data-file-preview")).toBe(PLAN.path);
});
+ it("stays closed on a return after the person opened and closed another file there while the first waited", async () => {
+ await render();
+ await openFile();
+ await render({ threadId: "t2" });
+ fixture.state = { ...fixture.state, computerOpen: true };
+ await render({ threadId: "t2" });
+ await render({ threadId: "t1" });
+ fixture.state = { ...fixture.state, computerOpen: false };
+ await render({ threadId: "t1" });
+ await openFile();
+ await act(async () => pane()!.querySelector<HTMLButtonElement>("button[aria-label='Close preview']")!.click());
+ await render({ threadId: "t2" });
+ await render({ threadId: "t1" });
+ expect(pane()).toBeNull();
+ });
+
it("stays closed in a conversation where it was never open", async () => {
await render();
await openFile();
diff --git a/src/lib/file-preview.ts b/src/lib/file-preview.ts
index 69c5f8a955..5b05132466 100644
--- a/src/lib/file-preview.ts
+++ b/src/lib/file-preview.ts
@@ -28,12 +28,17 @@ function set(next: FilePreview | null): void {
for (const listener of listeners) listener();
}
-export const openFilePreview = (preview: FilePreview): void => set({ ...preview });
-export const closeFilePreview = (): void => set(null);
-
/** The file each conversation the chat left had open beside it, shown again when the person comes back to it. */
const leftOpen = new Map<string, FilePreview>();
+/** A file opened in a conversation replaces the one it had kept from before, so closing it leaves that conversation
+ * with none. */
+export function openFilePreview(preview: FilePreview): void {
+ leftOpen.delete(preview.message.threadId);
+ set({ ...preview });
+}
+export const closeFilePreview = (): void => set(null);
+
/** The chat moved from one conversation to another: keeps the open file for the one it left, and shows the one the
* other had open when the person left it, if any and if `show`; otherwise that one stays kept for a later return. */
export function moveFilePreview(from: string | undefined, to: string | undefined, show: boolean): void {