Skip to content

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

fix(notifications): close an unpinned tray when re-selecting the open chat from another view

AdityaUmale794e128537ae
diff --git a/src/state/store.test.ts b/src/state/store.test.ts
index 253cd5bba4..975eb03712 100644
--- a/src/state/store.test.ts
+++ b/src/state/store.test.ts
@@ -3186,6 +3186,15 @@ describe("notifications feed", () => {
expect(reducer(open, { type: "switchTask", botId: "bot-1", threadId: "t-2" }).notificationsOpen).toBe(false);
});
+ it("unpinned, re-selecting the open chat from another view closes it", () => {
+ const open = { ...reducer(initialState, { type: "toggleNotifications", open: true }), selectedId: "bot-1", activeView: "team-map" as const,
+ bots: [{ id: "bot-1", threadId: "t-1" }] as AppState["bots"], groups: [{ id: "room-1", threadId: "room-t" }] as AppState["groups"] };
+ expect(reducer(open, { type: "select", id: "bot-1" }).notificationsOpen).toBe(false);
+ expect(reducer({ ...open, selectedId: "room-1" }, { type: "select", id: "room-1" }).notificationsOpen).toBe(false);
+ expect(reducer(open, { type: "switchTask", botId: "bot-1", threadId: "t-1" }).notificationsOpen).toBe(false);
+ expect(reducer({ ...open, notificationsPinned: true }, { type: "select", id: "bot-1" }).notificationsOpen).toBe(true);
+ });
+
it("unpinned, starting a new chat closes it", () => {
const open = reducer(initialState, { type: "toggleNotifications", open: true });
expect(reducer(open, { type: "newTask", botId: "bot-1" }).notificationsOpen).toBe(false);
diff --git a/src/state/store.tsx b/src/state/store.tsx
index 67bb3c8d5b..5abbd95a69 100644
--- a/src/state/store.tsx
+++ b/src/state/store.tsx
@@ -1081,7 +1081,7 @@ export function reducer(state: AppState, action: Action): AppState {
const room = state.groups.find((g) => g.id === action.id);
if (room) {
return {
- ...(action.id === state.selectedId ? state : closeUnpinnedTray(state)),
+ ...(action.id === state.selectedId && state.activeView === "chat" ? state : closeUnpinnedTray(state)),
unreadDivider: openedUnreadDivider(state, room.threadId, room.unread, room.messages, room.lastReadMessageId),
activeView: "chat",
selectedId: action.id,
@@ -1092,7 +1092,7 @@ export function reducer(state: AppState, action: Action): AppState {
return updateBot(
withMascotMotion(
{
- ...(action.id === state.selectedId ? state : closeUnpinnedTray(state)),
+ ...(action.id === state.selectedId && state.activeView === "chat" ? state : closeUnpinnedTray(state)),
unreadDivider: opened
? openedUnreadDivider(state, opened.threadId, threadOpensUnread(opened), visibleMessages(opened), threadReadCursor(opened))
: state.unreadDivider,
diff --git a/src/state/thread-navigation.ts b/src/state/thread-navigation.ts
index 2b5f3c107a..81724362ec 100644
--- a/src/state/thread-navigation.ts
+++ b/src/state/thread-navigation.ts
@@ -127,7 +127,7 @@ export function closeUnpinnedTray<T extends NotificationTray>(state: T): T {
/** Opening the chat already on screen is not leaving it. */
export function closeTrayUnlessShown(state: AppState, id: string, threadId: string): AppState {
- const shown = id === state.selectedId && [...state.bots, ...state.groups].find((chat) => chat.id === id)?.threadId === threadId;
+ const shown = state.activeView === "chat" && id === state.selectedId && [...state.bots, ...state.groups].find((chat) => chat.id === id)?.threadId === threadId;
return shown ? state : closeUnpinnedTray(state);
}