An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
Update client components to directly use DBChat type
Yoshiki Miura2f079f0e6ad7
diff --git a/components/sidebar/chat-history-client.tsx b/components/sidebar/chat-history-client.tsxindex 7abc96b4..68995f62 100644--- a/components/sidebar/chat-history-client.tsx+++ b/components/sidebar/chat-history-client.tsx@@ -5,23 +5,20 @@ import {SidebarGroupLabel,SidebarMenu} from '@/components/ui/sidebar'-import { Chat } from '@/lib/types'+import { Chat as DBChat } from '@/lib/db/schema'import { useCallback, useEffect, useRef, useState, useTransition } from 'react'import { toast } from 'sonner'import { ChatHistorySkeleton } from './chat-history-skeleton'import { ChatMenuItem } from './chat-menu-item'import { ClearHistoryAction } from './clear-history-action'-// interface ChatHistoryClientProps {} // Removed empty interface-interface ChatPageResponse {- chats: Chat[]+ chats: DBChat[]nextOffset: number | null}export function ChatHistoryClient() {- // Removed props from function signature- const [chats, setChats] = useState<Chat[]>([])+ const [chats, setChats] = useState<DBChat[]>([])const [nextOffset, setNextOffset] = useState<number | null>(null)const [isLoading, setIsLoading] = useState(true)const loadMoreRef = useRef<HTMLDivElement>(null)@@ -34,10 +31,10 @@ export function ChatHistoryClient() {if (!response.ok) {throw new Error('Failed to fetch initial chat history')}- const { chats: newChats, nextOffset: newNextOffset } =+ const { chats: dbChats, nextOffset: newNextOffset } =(await response.json()) as ChatPageResponse- setChats(newChats)+ setChats(dbChats)setNextOffset(newNextOffset)} catch (error) {console.error('Failed to load initial chats:', error)@@ -73,10 +70,10 @@ export function ChatHistoryClient() {if (!response.ok) {throw new Error('Failed to fetch more chat history')}- const { chats: newChats, nextOffset: newNextOffset } =+ const { chats: dbChats, nextOffset: newNextOffset } =(await response.json()) as ChatPageResponse- setChats(prevChats => [...prevChats, ...newChats])+ setChats(prevChats => [...prevChats, ...dbChats])setNextOffset(newNextOffset)} catch (error) {console.error('Failed to load more chats:', error)@@ -127,7 +124,8 @@ export function ChatHistoryClient() {) : (<SidebarMenu>{chats.map(- (chat: Chat) => chat && <ChatMenuItem key={chat.id} chat={chat} />+ (chat: DBChat) =>+ chat && <ChatMenuItem key={chat.id} chat={chat} />)}</SidebarMenu>)}diff --git a/components/sidebar/chat-menu-item.tsx b/components/sidebar/chat-menu-item.tsxindex c95d8778..209516bd 100644--- a/components/sidebar/chat-menu-item.tsx+++ b/components/sidebar/chat-menu-item.tsx@@ -22,7 +22,7 @@ import {SidebarMenuButton,SidebarMenuItem} from '@/components/ui/sidebar'-import { Chat } from '@/lib/types'+import { Chat as DBChat } from '@/lib/db/schema'import { MoreHorizontal, Trash2 } from 'lucide-react'import Link from 'next/link'import { usePathname, useRouter } from 'next/navigation'@@ -31,7 +31,7 @@ import { toast } from 'sonner'import { Spinner } from '../ui/spinner'interface ChatMenuItemProps {- chat: Chat+ chat: DBChat}const formatDateWithTime = (date: Date | string) => {@@ -74,7 +74,8 @@ const formatDateWithTime = (date: Date | string) => {export function ChatMenuItem({ chat }: ChatMenuItemProps) {const pathname = usePathname()- const isActive = pathname === chat.path+ const path = `/search/${chat.id}`+ const isActive = pathname === pathconst router = useRouter()const [isPending, startTransition] = useTransition()const [isMenuOpen, setIsMenuOpen] = useState(false)@@ -115,7 +116,7 @@ export function ChatMenuItem({ chat }: ChatMenuItemProps) {isActive={isActive}className="h-auto flex-col gap-0.5 items-start p-2 pr-8">- <Link href={chat.path}>+ <Link href={path}><div className="text-xs font-medium truncate select-none w-full">{chat.title}</div>