feat(chat): add comments panel collapse functionality and integrate with inbox sidebar

This commit is contained in:
Anish Sarkar 2026-01-27 20:59:03 +05:30
parent a3b6012fb2
commit 6d05a13167
4 changed files with 86 additions and 36 deletions

View file

@ -17,6 +17,8 @@ interface CurrentThreadState {
visibility: ChatVisibility | null;
hasComments: boolean;
addingCommentToMessageId: number | null;
/** Whether the right-side comments panel is collapsed (desktop only) */
commentsCollapsed: boolean;
}
const initialState: CurrentThreadState = {
@ -24,6 +26,7 @@ const initialState: CurrentThreadState = {
visibility: null,
hasComments: false,
addingCommentToMessageId: null,
commentsCollapsed: false,
};
export const currentThreadAtom = atom<CurrentThreadState>(initialState);
@ -34,6 +37,8 @@ export const commentsEnabledAtom = atom(
export const showCommentsGutterAtom = atom((get) => {
const thread = get(currentThreadAtom);
// Hide gutter if comments are collapsed
if (thread.commentsCollapsed) return false;
return (
thread.visibility === "SEARCH_SPACE" &&
(thread.hasComments || thread.addingCommentToMessageId !== null)
@ -55,3 +60,19 @@ export const setThreadVisibilityAtom = atom(null, (get, set, newVisibility: Chat
export const resetCurrentThreadAtom = atom(null, (_, set) => {
set(currentThreadAtom, initialState);
});
/** Atom to read whether comments panel is collapsed */
export const commentsCollapsedAtom = atom(
(get) => get(currentThreadAtom).commentsCollapsed
);
/** Atom to toggle the comments collapsed state */
export const toggleCommentsCollapsedAtom = atom(null, (get, set) => {
const current = get(currentThreadAtom);
set(currentThreadAtom, { ...current, commentsCollapsed: !current.commentsCollapsed });
});
/** Atom to explicitly set the comments collapsed state */
export const setCommentsCollapsedAtom = atom(null, (get, set, collapsed: boolean) => {
set(currentThreadAtom, { ...get(currentThreadAtom), commentsCollapsed: collapsed });
});