diff --git a/app/components/chat/BaseChat.tsx b/app/components/chat/BaseChat.tsx index 627d959..353e326 100644 --- a/app/components/chat/BaseChat.tsx +++ b/app/components/chat/BaseChat.tsx @@ -12,12 +12,14 @@ import { Messages } from './Messages.client'; import { SendButton } from './SendButton.client'; import { APIKeyManager } from './APIKeyManager'; import Cookies from 'js-cookie'; -import { importChat } from '~/utils/chatExport'; +import { exportChat, importChat } from '~/utils/chatExport'; import { toast } from 'react-toastify'; import * as Tooltip from '@radix-ui/react-tooltip'; import styles from './BaseChat.module.scss'; import type { ProviderInfo } from '~/utils/types'; +import WithTooltip from '~/components/ui/Tooltip'; +import { ExportChatButton } from '~/components/chat/ExportChatButton'; const EXAMPLE_PROMPTS = [ { text: 'Build a todo app in React using Tailwind' }, @@ -76,6 +78,7 @@ interface BaseChatProps { chatStarted?: boolean; isStreaming?: boolean; messages?: Message[]; + description?: string; enhancingPrompt?: boolean; promptEnhanced?: boolean; input?: string; @@ -101,6 +104,7 @@ export const BaseChat = React.forwardRef( enhancingPrompt = false, promptEnhanced = false, messages, + description, input = '', model, setModel, @@ -288,6 +292,7 @@ export const BaseChat = React.forwardRef( )} + {() => } {input.length > 3 ? (
diff --git a/app/components/chat/Chat.client.tsx b/app/components/chat/Chat.client.tsx index 31748b3..8b56419 100644 --- a/app/components/chat/Chat.client.tsx +++ b/app/components/chat/Chat.client.tsx @@ -7,7 +7,7 @@ import { useAnimate } from 'framer-motion'; import { memo, useEffect, useRef, useState } from 'react'; import { cssTransition, toast, ToastContainer } from 'react-toastify'; import { useMessageParser, usePromptEnhancer, useShortcuts, useSnapScroll } from '~/lib/hooks'; -import { useChatHistory } from '~/lib/persistence'; +import { description, useChatHistory } from '~/lib/persistence'; import { chatStore } from '~/lib/stores/chat'; import { workbenchStore } from '~/lib/stores/workbench'; import { fileModificationsToHTML } from '~/utils/diff'; @@ -29,10 +29,11 @@ export function Chat() { renderLogger.trace('Chat'); const { ready, initialMessages, storeMessageHistory } = useChatHistory(); + const title = useStore(description); return ( <> - {ready && } + {ready && } { return ( @@ -69,7 +70,7 @@ interface ChatProps { storeMessageHistory: (messages: Message[]) => Promise; } -export const ChatImpl = memo(({ initialMessages, storeMessageHistory }: ChatProps) => { +export const ChatImpl = memo(({ description, initialMessages, storeMessageHistory }: ChatProps) => { useShortcuts(); const textareaRef = useRef(null); @@ -252,6 +253,7 @@ export const ChatImpl = memo(({ initialMessages, storeMessageHistory }: ChatProp scrollRef={scrollRef} handleInputChange={handleInputChange} handleStop={abort} + description={description} messages={messages.map((message, i) => { if (message.role === 'user') { return message; diff --git a/app/components/chat/ExportChatButton.tsx b/app/components/chat/ExportChatButton.tsx new file mode 100644 index 0000000..5b0906d --- /dev/null +++ b/app/components/chat/ExportChatButton.tsx @@ -0,0 +1,16 @@ +import WithTooltip from '~/components/ui/Tooltip'; +import { IconButton } from '~/components/ui/IconButton'; +import { exportChat } from '~/utils/chatExport'; +import React from 'react'; +import type { Message } from 'ai'; + +export const ExportChatButton = ({description, messages}: {description: string, messages: Message[]}) => { + return ( + exportChat(messages || [], description)} + > +
+
+
); +} diff --git a/app/components/ui/Tooltip.tsx b/app/components/ui/Tooltip.tsx index f6d0bd2..956f340 100644 --- a/app/components/ui/Tooltip.tsx +++ b/app/components/ui/Tooltip.tsx @@ -1,7 +1,17 @@ import React from 'react'; import * as Tooltip from '@radix-ui/react-tooltip'; +import type {ReactNode} from 'react'; -const WithTooltip = ({ tooltip, children, sideOffset = 5, className = '', arrowClassName = '', tooltipStyle = {} }) => { +interface ToolTipProps { + tooltip: string, + children: ReactNode | ReactNode[]; + sideOffset?: number, + className?: string, + arrowClassName?: string, + tooltipStyle?: any, //TODO better type +} + +const WithTooltip = ({ tooltip, children, sideOffset = 5, className = '', arrowClassName = '', tooltipStyle = {} }: ToolTipProps) => { return (