diff --git a/app/actions.ts b/app/actions.ts index 075918f..94016a5 100644 --- a/app/actions.ts +++ b/app/actions.ts @@ -56,5 +56,5 @@ export async function removeChat({ id, path }: { id: string; path: string }) { await kv.zrem(`user:chat:${user.id}`, `chat:${id}`) revalidatePath('/') - revalidatePath('/chat/[id]') + revalidatePath(path) } diff --git a/components/chat-list.tsx b/components/chat-list.tsx index cf6b830..ef18c87 100644 --- a/components/chat-list.tsx +++ b/components/chat-list.tsx @@ -1,5 +1,3 @@ -'use client' - import { type Message } from 'ai-connector' import { Separator } from '@/components/ui/separator' diff --git a/components/sidebar-item.tsx b/components/sidebar-item.tsx index ea0295d..3fd627f 100644 --- a/components/sidebar-item.tsx +++ b/components/sidebar-item.tsx @@ -1,7 +1,6 @@ 'use client' import * as React from 'react' -import { useTransition } from 'react' import Link from 'next/link' import { usePathname, useRouter } from 'next/navigation' @@ -17,25 +16,21 @@ import { AlertDialogTitle } from '@/components/ui/alert-dialog' import { Button, buttonVariants } from '@/components/ui/button' -import { removeChat } from '@/app/actions' import { IconMessage, IconSpinner, IconTrash } from '@/components/ui/icons' -export function SidebarItem({ - title, - href, - id, - userId -}: { +interface SidebarItemProps { title: string href: string id: string - userId: string -}) { + removeChat: (args: { id: string; path: string }) => Promise +} + +export function SidebarItem({ title, href, id, removeChat }: SidebarItemProps) { const [open, setIsOpen] = React.useState(false) const pathname = usePathname() const router = useRouter() + const [isPending, startTransition] = React.useTransition() const isActive = pathname === href - const [isPending, startTransition] = useTransition() if (!id) return null @@ -85,7 +80,7 @@ export function SidebarItem({ onClick={event => { event.preventDefault() startTransition(async () => { - await removeChat({ id, userId, path: href }) + await removeChat({ id, path: href }) setIsOpen(false) router.push('/') }) diff --git a/components/sidebar-list.tsx b/components/sidebar-list.tsx index 95751b1..c729f20 100644 --- a/components/sidebar-list.tsx +++ b/components/sidebar-list.tsx @@ -1,27 +1,12 @@ -import { getChats } from '@/app/actions' +import { getChats, removeChat } from '@/app/actions' import { SidebarItem } from '@/components/sidebar-item' -import { LoginButton } from '@/components/login-button' export interface SidebarListProps { userId?: string } export async function SidebarList({ userId }: SidebarListProps) { - if (!userId) { - return ( -
-
-

You are not logged in!

-

- Please login for chat history. -

-
- -
- ) - } - const chats = await getChats(userId) return ( @@ -32,9 +17,9 @@ export async function SidebarList({ userId }: SidebarListProps) { ))} @@ -46,5 +31,3 @@ export async function SidebarList({ userId }: SidebarListProps) { ) } - -SidebarList.displayName = 'SidebarList' diff --git a/components/sidebar.tsx b/components/sidebar.tsx index 0e8c628..c210dd1 100644 --- a/components/sidebar.tsx +++ b/components/sidebar.tsx @@ -21,6 +21,7 @@ export interface SidebarProps { export function Sidebar({ userId, children }: SidebarProps) { const { signOut } = useClerk() + return (