Skip to content

An AI-powered search engine with a generative UI

refactor: remove deprecated history and sidebar components

Yoshiki Miurafd759ed72726
diff --git a/components/history-container.tsx b/components/history-container.tsx
deleted file mode 100644
index ce3b1999..00000000
--- a/components/history-container.tsx
+++ /dev/null
@@ -1,20 +0,0 @@
-import React from 'react'
-import { History } from './history'
-import { HistoryList } from './history-list'
-
-const HistoryContainer: React.FC = async () => {
- const enableSaveChatHistory = process.env.ENABLE_SAVE_CHAT_HISTORY === 'true'
- if (!enableSaveChatHistory) {
- return null
- }
-
- return (
- <div>
- <History>
- <HistoryList userId="anonymous" />
- </History>
- </div>
- )
-}
-
-export default HistoryContainer
diff --git a/components/history-item.tsx b/components/history-item.tsx
deleted file mode 100644
index ea7a3b29..00000000
--- a/components/history-item.tsx
+++ /dev/null
@@ -1,73 +0,0 @@
-'use client'
-
-import React from 'react'
-import Link from 'next/link'
-import { usePathname } from 'next/navigation'
-import { Chat } from '@/lib/types'
-import { cn } from '@/lib/utils'
-
-type HistoryItemProps = {
- chat: Chat
-}
-
-const formatDateWithTime = (date: Date | string) => {
- const parsedDate = new Date(date)
- const now = new Date()
- const yesterday = new Date()
- yesterday.setDate(yesterday.getDate() - 1)
-
- const formatTime = (date: Date) => {
- return date.toLocaleString('en-US', {
- hour: '2-digit',
- minute: '2-digit',
- hour12: true
- })
- }
-
- if (
- parsedDate.getDate() === now.getDate() &&
- parsedDate.getMonth() === now.getMonth() &&
- parsedDate.getFullYear() === now.getFullYear()
- ) {
- return `Today, ${formatTime(parsedDate)}`
- } else if (
- parsedDate.getDate() === yesterday.getDate() &&
- parsedDate.getMonth() === yesterday.getMonth() &&
- parsedDate.getFullYear() === yesterday.getFullYear()
- ) {
- return `Yesterday, ${formatTime(parsedDate)}`
- } else {
- return parsedDate.toLocaleString('en-US', {
- year: 'numeric',
- month: '2-digit',
- day: '2-digit',
- hour: '2-digit',
- minute: '2-digit',
- hour12: true
- })
- }
-}
-
-const HistoryItem: React.FC<HistoryItemProps> = ({ chat }) => {
- const pathname = usePathname()
- const isActive = pathname === chat.path
-
- return (
- <Link
- href={chat.path}
- className={cn(
- 'flex flex-col hover:bg-muted cursor-pointer p-2 rounded border',
- isActive ? 'bg-muted/70 border-border' : 'border-transparent'
- )}
- >
- <div className="text-xs font-medium truncate select-none">
- {chat.title}
- </div>
- <div className="text-xs text-muted-foreground">
- {formatDateWithTime(chat.createdAt)}
- </div>
- </Link>
- )
-}
-
-export default HistoryItem
diff --git a/components/history-list.tsx b/components/history-list.tsx
deleted file mode 100644
index 12ced3e3..00000000
--- a/components/history-list.tsx
+++ /dev/null
@@ -1,37 +0,0 @@
-import React, { cache } from 'react'
-import HistoryItem from './history-item'
-import { Chat } from '@/lib/types'
-import { getChats } from '@/lib/actions/chat'
-import { ClearHistory } from './clear-history'
-
-type HistoryListProps = {
- userId?: string
-}
-
-const loadChats = cache(async (userId?: string) => {
- return await getChats(userId)
-})
-
-// Start of Selection
-export async function HistoryList({ userId }: HistoryListProps) {
- const chats = await loadChats(userId)
-
- return (
- <div className="flex flex-col flex-1 space-y-3 h-full">
- <div className="flex flex-col space-y-0.5 flex-1 overflow-y-auto">
- {!chats?.length ? (
- <div className="text-foreground/30 text-sm text-center py-4">
- No search history
- </div>
- ) : (
- chats?.map(
- (chat: Chat) => chat && <HistoryItem key={chat.id} chat={chat} />
- )
- )}
- </div>
- <div className="mt-auto">
- <ClearHistory empty={!chats?.length} />
- </div>
- </div>
- )
-}
diff --git a/components/history-skeleton.tsx b/components/history-skeleton.tsx
deleted file mode 100644
index e21c1d85..00000000
--- a/components/history-skeleton.tsx
+++ /dev/null
@@ -1,12 +0,0 @@
-import React from 'react'
-import { Skeleton } from './ui/skeleton'
-
-export function HistorySkeleton() {
- return (
- <div className="flex flex-col flex-1 space-y-1.5 overflow-auto">
- {Array.from({ length: 3 }).map((_, i) => (
- <Skeleton key={i} className="w-full h-12 rounded" />
- ))}
- </div>
- )
-}
diff --git a/components/history.tsx b/components/history.tsx
deleted file mode 100644
index f8c8b910..00000000
--- a/components/history.tsx
+++ /dev/null
@@ -1,52 +0,0 @@
-'use client'
-
-import { Button } from '@/components/ui/button'
-import {
- Sheet,
- SheetContent,
- SheetHeader,
- SheetTitle,
- SheetTrigger
-} from '@/components/ui/sheet'
-import { History as HistoryIcon, Menu } from 'lucide-react'
-import { useRouter } from 'next/navigation'
-import { Suspense, useTransition } from 'react'
-import { HistorySkeleton } from './history-skeleton'
-
-type HistoryProps = {
- children?: React.ReactNode
-}
-
-export function History({ children }: HistoryProps) {
- const router = useRouter()
- const [isPending, startTransition] = useTransition()
-
- const onOpenChange = (open: boolean) => {
- if (open) {
- startTransition(() => {
- router.refresh()
- })
- }
- }
-
- return (
- <Sheet onOpenChange={onOpenChange}>
- <SheetTrigger asChild>
- <Button variant="ghost" size="icon">
- <Menu />
- </Button>
- </SheetTrigger>
- <SheetContent className="w-64 rounded-tl-xl rounded-bl-xl">
- <SheetHeader>
- <SheetTitle className="flex items-center gap-1 text-sm font-normal mb-2">
- <HistoryIcon size={14} />
- History
- </SheetTitle>
- </SheetHeader>
- <div className="my-2 h-full pb-12 md:pb-10">
- <Suspense fallback={<HistorySkeleton />}>{children}</Suspense>
- </div>
- </SheetContent>
- </Sheet>
- )
-}
diff --git a/components/sidebar.tsx b/components/sidebar.tsx
deleted file mode 100644
index 55156d45..00000000
--- a/components/sidebar.tsx
+++ /dev/null
@@ -1,9 +0,0 @@
-import HistoryContainer from './history-container'
-
-export async function Sidebar() {
- return (
- <div className="h-screen p-2 fixed top-0 right-0 flex-col justify-center pb-24 hidden lg:flex">
- <HistoryContainer />
- </div>
- )
-}