From 2d16e8bb4fdb5449e257d80db39973dd4c86bd1d Mon Sep 17 00:00:00 2001 From: Enrico Ros Date: Sat, 16 Mar 2024 20:44:54 -0700 Subject: [PATCH] UserFlags: show on messages --- src/apps/chat/components/ChatDrawer.tsx | 2 +- src/apps/chat/components/ChatDrawerItem.tsx | 24 +++++++++++-------- .../chat/components/useChatNavRenderItems.tsx | 8 ++++++- src/common/state/store-chats.ts | 8 +++++++ 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/apps/chat/components/ChatDrawer.tsx b/src/apps/chat/components/ChatDrawer.tsx index 64136a781..6dbf9aa7c 100644 --- a/src/apps/chat/components/ChatDrawer.tsx +++ b/src/apps/chat/components/ChatDrawer.tsx @@ -185,7 +185,7 @@ function ChatDrawer(props: { {showPersonaIcons && } - Persona Icons + Icons {showRelativeSize && } diff --git a/src/apps/chat/components/ChatDrawerItem.tsx b/src/apps/chat/components/ChatDrawerItem.tsx index d3117f12f..c6b70747a 100644 --- a/src/apps/chat/components/ChatDrawerItem.tsx +++ b/src/apps/chat/components/ChatDrawerItem.tsx @@ -54,6 +54,7 @@ export interface ChatNavigationItemData { isAlsoOpen: string | false; isEmpty: boolean; title: string; + userFlagsSummary: string | undefined; folder: DFolder | null | undefined; // null: 'All', undefined: do not show folder select updatedAt: number; messageCount: number; @@ -87,7 +88,7 @@ function ChatDrawerItem(props: { // derived state const { onConversationBranch, onConversationExport, onConversationFolderChange } = props; - const { conversationId, isActive, isAlsoOpen, title, folder, messageCount, assistantTyping, systemPurposeId, searchFrequency } = props.item; + const { conversationId, isActive, isAlsoOpen, title, userFlagsSummary, folder, messageCount, assistantTyping, systemPurposeId, searchFrequency } = props.item; const isNew = messageCount === 0; @@ -220,16 +221,19 @@ function ChatDrawerItem(props: { /> )} - {/* Display search frequency if it exists and is greater than 0 */} - {searchFrequency > 0 && ( - - - {searchFrequency} - - - )} + {/* Right text */} + {searchFrequency > 0 ? ( + // Display search frequency if it exists and is greater than 0 + + {searchFrequency} + + ) : (userFlagsSummary && props.showSymbols) ? ( + + {userFlagsSummary} + + ) : null} - , [assistantTyping, handleTitleEditBegin, handleTitleEditCancel, handleTitleEditChange, isActive, isEditingTitle, isNew, props.showSymbols, searchFrequency, textSymbol, title]); + , [assistantTyping, handleTitleEditBegin, handleTitleEditCancel, handleTitleEditChange, isActive, isEditingTitle, isNew, props.showSymbols, searchFrequency, textSymbol, title, userFlagsSummary]); const progressBarFixedComponent = React.useMemo(() => progress > 0 && ( diff --git a/src/apps/chat/components/useChatNavRenderItems.tsx b/src/apps/chat/components/useChatNavRenderItems.tsx index 6a6f7df21..7e9e218c5 100644 --- a/src/apps/chat/components/useChatNavRenderItems.tsx +++ b/src/apps/chat/components/useChatNavRenderItems.tsx @@ -1,7 +1,7 @@ import { shallow } from 'zustand/shallow'; import type { DFolder } from '~/common/state/store-folders'; -import { conversationTitle, DConversationId, messageHasUserFlag, useChatStore } from '~/common/state/store-chats'; +import { conversationTitle, DConversationId, DMessageUserFlag, messageHasUserFlag, messageUserFlagToEmoji, useChatStore } from '~/common/state/store-chats'; import type { ChatNavigationItemData } from './ChatDrawerItem'; @@ -113,6 +113,11 @@ export function useChatNavRenderItems( searchFrequency = titleFrequency + messageFrequency; } + // union of message flags -> emoji string + const allFlags = new Set(); + _c.messages.forEach(_m => _m.userFlags?.forEach(flag => allFlags.add(flag))); + const userFlagsSummary = !allFlags.size ? undefined : Array.from(allFlags).map(messageUserFlagToEmoji).join(''); + // create the ChatNavigationData return { type: 'nav-item-chat-data', @@ -121,6 +126,7 @@ export function useChatNavRenderItems( isAlsoOpen, isEmpty: !_c.messages.length && !_c.userTitle, title, + userFlagsSummary, folder: !allFolders.length ? undefined // don't show folder select if folders are disabled : _c.id === activeConversationId // only show the folder for active conversation(s) diff --git a/src/common/state/store-chats.ts b/src/common/state/store-chats.ts index 19d6c43ee..ff1db05cf 100644 --- a/src/common/state/store-chats.ts +++ b/src/common/state/store-chats.ts @@ -101,6 +101,14 @@ export function messageToggleUserFlag(message: DMessage, flag: DMessageUserFlag) return [...(message.userFlags || []), flag]; } +const dMessageUserFlagToEmojiMap: Record = { + starred: '⭐️', +}; + +export function messageUserFlagToEmoji(flag: DMessageUserFlag): string { + return dMessageUserFlagToEmojiMap[flag] || '❓'; +} + /// Conversations Store