diff --git a/app/components/chat/BaseChat.tsx b/app/components/chat/BaseChat.tsx index dd56edc..9faf9a2 100644 --- a/app/components/chat/BaseChat.tsx +++ b/app/components/chat/BaseChat.tsx @@ -12,6 +12,7 @@ import { Menu } from '~/components/sidebar/Menu.client'; import { IconButton } from '~/components/ui/IconButton'; import { Workbench } from '~/components/workbench/Workbench.client'; import { classNames } from '~/utils/classNames'; +import { ChatHistory } from './ChatHistory.client'; interface BaseChatProps { textareaRef?: React.RefObject | undefined; @@ -198,6 +199,7 @@ export const BaseChat = React.forwardRef( >
+ {() => }
{input.length > 3 ? (
diff --git a/app/components/chat/ChatHistory.client.tsx b/app/components/chat/ChatHistory.client.tsx new file mode 100644 index 0000000..2c3bada --- /dev/null +++ b/app/components/chat/ChatHistory.client.tsx @@ -0,0 +1,81 @@ +import { useEffect, useState } from 'react'; +import type { ChatHistoryItem } from '~/lib/persistence/useChatHistory'; +import { db } from '~/lib/persistence/useChatHistory'; +import { getAll } from '~/lib/persistence/db'; +import { useNavigate, useLoaderData } from '@remix-run/react'; +import { IconButton } from '~/components/ui/IconButton'; +import { classNames } from '~/utils/classNames'; +import { createScopedLogger } from '~/utils/logger'; + +const logger = createScopedLogger('ChatHistory'); + +export function ChatHistory() { + const [history, setHistory] = useState([]); + const [isOpen, setIsOpen] = useState(false); + const navigate = useNavigate(); + const { id: currentId } = useLoaderData<{ id?: string }>(); + + useEffect(() => { + if (!db) return; + + const loadHistory = async () => { + try { + const items = await getAll(db!); + // Filter items to only show history for the current chat + const filteredItems = items + .filter(item => item.urlId === currentId || item.id === currentId) + .sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime()); + setHistory(filteredItems); + } catch (error) { + logger.error('Failed to load chat history', error); + } + }; + + loadHistory(); + }, [currentId]); + + const handleRestore = (item: ChatHistoryItem) => { + navigate(`/chat/${item.id}`); + setIsOpen(false); + }; + + if (!db || history.length === 0) return null; + + return ( +
+ setIsOpen(!isOpen)} + className={classNames({ + 'text-bolt-elements-item-contentAccent!': isOpen, + })} + > +
+ + + {isOpen && ( +
+
+

Chat History

+
+ {history.map((item) => ( + + ))} +
+
+
+ )} +
+ ); +} \ No newline at end of file