forked from miurla/morphic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
history-list.tsx
37 lines (33 loc) · 1023 Bytes
/
history-list.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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>
)
}