mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-30 03:16:25 +02:00
feat: Document Selector in Chat.
- Still need improvements but lets use it first.
This commit is contained in:
parent
e8a19c496b
commit
d7bb31f894
12 changed files with 599 additions and 67 deletions
|
|
@ -120,8 +120,13 @@ export function AppSidebarProvider({
|
|||
// Use the API client instead of direct fetch - filter by current search space ID
|
||||
const chats: Chat[] = await apiClient.get<Chat[]>(`api/v1/chats/?limit=5&skip=0&search_space_id=${searchSpaceId}`);
|
||||
|
||||
// Sort chats by created_at in descending order (newest first)
|
||||
const sortedChats = chats.sort((a, b) =>
|
||||
new Date(b.created_at).getTime() - new Date(a.created_at).getTime()
|
||||
);
|
||||
// console.log("sortedChats", sortedChats);
|
||||
// Transform API response to the format expected by AppSidebar
|
||||
const formattedChats = chats.map(chat => ({
|
||||
const formattedChats = sortedChats.map(chat => ({
|
||||
name: chat.title || `Chat ${chat.id}`, // Fallback if title is empty
|
||||
url: `/dashboard/${chat.search_space_id}/researcher/${chat.id}`,
|
||||
icon: 'MessageCircleMore',
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ export function AppSidebar({
|
|||
</SidebarHeader>
|
||||
<SidebarContent>
|
||||
<NavMain items={processedNavMain} />
|
||||
{processedRecentChats.length > 0 && <NavProjects projects={processedRecentChats} />}
|
||||
{processedRecentChats.length > 0 && <NavProjects chats={processedRecentChats} />}
|
||||
<NavSecondary items={processedNavSecondary} className="mt-auto" />
|
||||
</SidebarContent>
|
||||
<SidebarFooter>
|
||||
|
|
|
|||
|
|
@ -43,9 +43,9 @@ interface ChatAction {
|
|||
}
|
||||
|
||||
export function NavProjects({
|
||||
projects,
|
||||
chats,
|
||||
}: {
|
||||
projects: {
|
||||
chats: {
|
||||
name: string
|
||||
url: string
|
||||
icon: LucideIcon
|
||||
|
|
@ -57,13 +57,13 @@ export function NavProjects({
|
|||
const { isMobile } = useSidebar()
|
||||
const router = useRouter()
|
||||
|
||||
const searchSpaceId = projects[0]?.search_space_id || ""
|
||||
const searchSpaceId = chats[0]?.search_space_id || ""
|
||||
|
||||
return (
|
||||
<SidebarGroup className="group-data-[collapsible=icon]:hidden">
|
||||
<SidebarGroupLabel>Recent Chats</SidebarGroupLabel>
|
||||
<SidebarMenu>
|
||||
{projects.map((item, index) => (
|
||||
{chats.map((item, index) => (
|
||||
<SidebarMenuItem key={item.id ? `chat-${item.id}` : `chat-${item.name}-${index}`}>
|
||||
<SidebarMenuButton>
|
||||
<item.icon />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue