diff --git a/starters/shopify-algolia/app/(ai-browse)/_components/ai-chat.tsx b/starters/shopify-algolia/app/(ai-browse)/_components/ai-chat.tsx new file mode 100644 index 00000000..de48d5eb --- /dev/null +++ b/starters/shopify-algolia/app/(ai-browse)/_components/ai-chat.tsx @@ -0,0 +1,116 @@ +"use client" + +import * as React from "react" +import { ShoppingBag, ShoppingCart } from "lucide-react" +import { Sidebar, SidebarContent, SidebarFooter, SidebarHeader, SidebarMenu, SidebarMenuButton, SidebarMenuItem } from "components/ui/sidebar" +import { ScrollArea } from "components/ui/scroll-area" +import { Textarea } from "components/ui/textarea" +import { toast } from "sonner" +import { cn } from "utils/cn" +import { MessageList } from "components/ui/message-list" +import { useAiCommerce } from "./ai-commerce-context" +import { Suggestions } from "./chat-suggestions" + +export function AiCommerceSidebar() { + const { handleSubmit, setInput, messages, isLoading, input } = useAiCommerce() + const textareaRef = React.useRef(null) + + const handleSubmitForm = (e: React.FormEvent) => { + handleSubmit(e) + } + + const handleInput = (event: React.ChangeEvent) => { + setInput(event.target.value) + } + + const adjustHeight = () => { + if (textareaRef.current) { + textareaRef.current.style.height = "auto" + textareaRef.current.style.height = `${textareaRef.current.scrollHeight + 2}px` + } + } + + React.useEffect(() => { + if (textareaRef.current) { + adjustHeight() + } + }, []) + + React.useEffect(() => { + if (textareaRef.current) { + const domValue = textareaRef.current.value + const finalValue = domValue || "" + setInput(finalValue) + adjustHeight() + } + // Only run once after hydration + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []) + + return ( + + + + +
+ AI-Commerce +
+
+
+
+ + +
+ 0} + messageOptions={{ animation: "scale", showTimeStamp: true }} + /> +
+
+
+ +
+
+