From 69605dc3f9bb08f0534aa79453c9d74594b12bd7 Mon Sep 17 00:00:00 2001 From: djohnson Date: Sun, 24 Nov 2024 07:19:45 +0900 Subject: [PATCH] ChatStore should export ChatViewModels --- src/components/OmniBar.tsx | 4 ++-- src/components/chat/ChatListSection.tsx | 4 ++-- src/components/chat/ChatSettingsSection.tsx | 16 +++++++--------- src/core/chat/ChatStore.ts | 18 +++++++++--------- src/core/chat/ChatViewModel.ts | 6 +++++- src/features/settings/panels/chat/ChatForm.tsx | 4 ++-- .../settings/panels/chat/ChatPanel.tsx | 16 +++++++--------- src/utils/chatToDateLabel.ts | 6 +++--- 8 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/components/OmniBar.tsx b/src/components/OmniBar.tsx index 11e8a98..eafe67f 100644 --- a/src/components/OmniBar.tsx +++ b/src/components/OmniBar.tsx @@ -284,7 +284,7 @@ const useRegisterChatActions = () => { }, ] - _.orderBy(chatStore.chats, 'lastMessageDate', 'desc').forEach(chat => { + chatStore.orderedChats.forEach(chat => { const name = chat.name || 'new chat' return nextChatActions.push({ @@ -349,7 +349,7 @@ const useRegisterMessageActions = () => { const nextMessageActions: Action[] = [] chatStore.chats.forEach(chat => { - const messageCount = countMessagesWithText(chat.messageIds) + const messageCount = countMessagesWithText(chat.source.messageIds) if (messageCount > 0) { nextMessageActions.push( diff --git a/src/components/chat/ChatListSection.tsx b/src/components/chat/ChatListSection.tsx index 68f7560..ae9f511 100644 --- a/src/components/chat/ChatListSection.tsx +++ b/src/components/chat/ChatListSection.tsx @@ -10,13 +10,13 @@ import DocumentArrowUp from '~/icons/DocumentArrowUp' import Edit from '~/icons/Edit' import { chatStore } from '~/core/chat/ChatStore' -import { ChatModel } from '~/core/chat/ChatModel' +import { ChatViewModel } from '~/core/chat/ChatViewModel' import { chatTable } from '~/core/chat/ChatTable' export const ChatListSection = observer(({ onChatSelected }: { onChatSelected: () => void }) => { const { dateLabelToChatPairs } = chatStore - const handleChatSelected = async (chat: ChatModel) => { + const handleChatSelected = async (chat: ChatViewModel) => { await chatStore.selectChat(chat) onChatSelected() diff --git a/src/components/chat/ChatSettingsSection.tsx b/src/components/chat/ChatSettingsSection.tsx index 6e279aa..16d302f 100644 --- a/src/components/chat/ChatSettingsSection.tsx +++ b/src/components/chat/ChatSettingsSection.tsx @@ -32,8 +32,6 @@ export const ChatSettingsSection = observer(({ onBackClicked }: { onBackClicked: const chat = chatStore.selectedChat! - const chatModel = chat.source - const onExportClose = () => { setIsExportOpen(false) } @@ -43,7 +41,7 @@ export const ChatSettingsSection = observer(({ onBackClicked }: { onBackClicked: } const handleFormSubmit = handleSubmit(async formData => { - await chatTable.put({ ...chatModel, ...formData }) + await chatTable.put({ ...chat.source, ...formData }) reset(formData) }) @@ -60,12 +58,12 @@ export const ChatSettingsSection = observer(({ onBackClicked }: { onBackClicked: const link = document.createElement('a') link.href = URL.createObjectURL(new Blob([data], { type: 'application/json' })) - link.download = `llm-x-chat-${_.snakeCase(chatModel.name).replace('_', '-')}.json` + link.download = `llm-x-chat-${_.snakeCase(chat.name).replace('_', '-')}.json` link.click() } useEffect(() => { - reset({ name: chatModel.name || 'new chat' }) + reset({ name: chat.name || 'new chat' }) }, [chat]) useEffect(() => { @@ -93,12 +91,12 @@ export const ChatSettingsSection = observer(({ onBackClicked }: { onBackClicked: - {chatModel.name || 'new chat'} + {chat.name || 'new chat'} @@ -130,7 +128,7 @@ export const ChatSettingsSection = observer(({ onBackClicked }: { onBackClicked: )} control={control} name="name" - defaultValue={chatModel.name || 'new chat'} + defaultValue={chat.name || 'new chat'} rules={{ validate: validateName, }} @@ -152,7 +150,7 @@ export const ChatSettingsSection = observer(({ onBackClicked }: { onBackClicked: