Skip to content

Commit

Permalink
Show Split chats in the Drawer. Fixes #389
Browse files Browse the repository at this point in the history
  • Loading branch information
enricoros committed Feb 4, 2024
1 parent 90e7701 commit 0015704
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/apps/chat/AppChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ export function AppChat() {
<ChatDrawerMemo
activeConversationId={focusedConversationId}
activeFolderId={activeFolderId}
chatPanesConversationIds={chatPanes.map(pane => pane.conversationId).filter(Boolean) as DConversationId[]}
disableNewButton={isFocusedChatEmpty}
onConversationActivate={setFocusedConversationId}
onConversationDelete={handleConversationDelete}
Expand All @@ -411,7 +412,7 @@ export function AppChat() {
onConversationsDeleteAll={handleConversationsDeleteAll}
setActiveFolderId={setActiveFolderId}
/>,
[activeFolderId, focusedConversationId, handleConversationDelete, handleConversationExport, handleConversationImportDialog, handleConversationNew, handleConversationsDeleteAll, isFocusedChatEmpty, setFocusedConversationId],
[activeFolderId, chatPanes, focusedConversationId, handleConversationDelete, handleConversationExport, handleConversationImportDialog, handleConversationNew, handleConversationsDeleteAll, isFocusedChatEmpty, setFocusedConversationId],
);

const menuItems = React.useMemo(() =>
Expand Down
6 changes: 4 additions & 2 deletions src/apps/chat/components/applayout/ChatDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const useFolders = (activeFolderId: string | null) => useFolderStore(({ e
* Optimization: return a reduced version of the DConversation object for 'Drawer Items' purposes,
* to avoid unnecessary re-renders on each new character typed by the assistant
*/
export const useChatNavigationItemsData = (activeFolder: DFolder | null, allFolders: DFolder[], activeConversationId: DConversationId | null): ChatNavigationItemData[] =>
export const useChatNavigationItemsData = (activeFolder: DFolder | null, allFolders: DFolder[], activeConversationId: DConversationId | null, chatPanesConversationIds: DConversationId[]): ChatNavigationItemData[] =>
useChatStore(({ conversations }) => {

const activeConversations = activeFolder
Expand All @@ -61,6 +61,7 @@ export const useChatNavigationItemsData = (activeFolder: DFolder | null, allFold
return activeConversations.map((_c): ChatNavigationItemData => ({
conversationId: _c.id,
isActive: _c.id === activeConversationId,
isAlsoOpen: chatPanesConversationIds.includes(_c.id),
isEmpty: !_c.messages.length && !_c.userTitle,
title: conversationTitle(_c),
folder: !allFolders.length
Expand All @@ -84,6 +85,7 @@ export const ChatDrawerMemo = React.memo(ChatDrawer);
function ChatDrawer(props: {
activeConversationId: DConversationId | null,
activeFolderId: string | null,
chatPanesConversationIds: DConversationId[],
disableNewButton: boolean,
onConversationActivate: (conversationId: DConversationId) => void,
onConversationDelete: (conversationId: DConversationId, bypassConfirmation: boolean) => void,
Expand All @@ -103,7 +105,7 @@ function ChatDrawer(props: {
// external state
const { closeDrawer, closeDrawerOnMobile } = useOptimaDrawers();
const { activeFolder, allFolders, enableFolders, toggleEnableFolders } = useFolders(props.activeFolderId);
const chatNavItems = useChatNavigationItemsData(activeFolder, allFolders, props.activeConversationId);
const chatNavItems = useChatNavigationItemsData(activeFolder, allFolders, props.activeConversationId, props.chatPanesConversationIds);
const showSymbols = useUIPreferencesStore(state => state.zenMode !== 'cleaner');

// derived state
Expand Down
34 changes: 20 additions & 14 deletions src/apps/chat/components/applayout/ChatDrawerItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { InlineTextarea } from '~/common/components/InlineTextarea';


export const FadeInButton = styled(IconButton)({
opacity: 0.5,
opacity: 0.667,
transition: 'opacity 0.2s',
'&:hover': { opacity: 1 },
});
Expand All @@ -35,6 +35,7 @@ export const ChatDrawerItemMemo = React.memo(ChatDrawerItem);
export interface ChatNavigationItemData {
conversationId: DConversationId;
isActive: boolean;
isAlsoOpen: boolean;
isEmpty: boolean;
title: string;
folder: DFolder | null | undefined; // null: 'All', undefined: do not show folder select
Expand Down Expand Up @@ -67,7 +68,7 @@ function ChatDrawerItem(props: {

// derived state
const { onConversationExport, onConversationFolderChange } = props;
const { conversationId, isActive, title, folder, messageCount, assistantTyping, systemPurposeId, searchFrequency } = props.item;
const { conversationId, isActive, isAlsoOpen, title, folder, messageCount, assistantTyping, systemPurposeId, searchFrequency } = props.item;
const isNew = messageCount === 0;


Expand Down Expand Up @@ -210,19 +211,28 @@ function ChatDrawerItem(props: {
), [progress]);


return isActive ? (
return (isActive || isAlsoOpen) ? (

// Active Conversation
// Active or Also Open
<Sheet
variant={isActive ? 'solid' : 'plain'}
variant={isActive ? 'solid' : 'outlined'}
invertedColors={isActive}
onClick={!isActive ? handleConversationActivate : undefined}
sx={{
// common
// position: 'relative', // for the progress bar (now disabled)
'--ListItem-minHeight': '2.75rem',
position: 'relative', // for the progress bar
// '--variant-borderWidth': '0.125rem',
border: 'none', // there's a default border of 1px and invisible.. hmm

// differences between primary and secondary variants
...(isActive ? {
border: 'none', // there's a default border of 1px and invisible.. hmm
} : {
// '--variant-borderWidth': '0.125rem',
cursor: 'pointer',
}),

// style
backgroundColor: isActive ? 'neutral.solidActiveBg' : 'neutral.softBg',
borderRadius: 'md',
mx: '0.25rem',
'&:hover > button': {
Expand All @@ -235,14 +245,11 @@ function ChatDrawerItem(props: {

{/* Title row */}
<Box sx={{ display: 'flex', gap: 'var(--ListItem-gap)', minHeight: '2.25rem', alignItems: 'center' }}>

{titleRowComponent}

</Box>

{/* buttons row */}
<Box sx={{ display: 'flex', gap: 1, minHeight: '2.25rem', alignItems: 'center' }}>

<ListItemDecorator />

{/* Current Folder color, and change initiator */}
Expand Down Expand Up @@ -284,7 +291,6 @@ function ChatDrawerItem(props: {
</Tooltip>
</>}


{/* --> */}
<Box sx={{ flex: 1 }} />

Expand All @@ -304,13 +310,13 @@ function ChatDrawerItem(props: {
</FadeInButton>
</Tooltip>
</>}

</Box>

</ListItem>

{/* Optional progress bar, underlay */}
{progressBarFixedComponent}
{/* NOTE: disabled on 20240204: quite distracting on the active chat sheet */}
{/*{progressBarFixedComponent}*/}

</Sheet>

Expand Down

0 comments on commit 0015704

Please sign in to comment.