-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfile-sidebar.tsx
95 lines (90 loc) · 2.89 KB
/
file-sidebar.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
'use client';
import { Button } from '@/components/ui/button';
import Image from 'next/image';
import { useRouter } from 'next/navigation';
import { memo, useCallback, useEffect, useState } from 'react';
import { SquarePen } from 'lucide-react';
import SidebarSkeleton from './sidebar-skeleton';
import UserSettings from './user-settings';
import { SideBarItem } from './sidebar-item';
import { EventEnum } from '../const/EventEnum';
import {
SidebarContent,
SidebarGroup,
SidebarGroupContent,
SidebarTrigger,
Sidebar,
SidebarRail,
SidebarFooter,
} from './ui/sidebar';
import { cn } from '@/lib/utils';
export default function FileSidebar({ isCollapsed, isMobile, loading }) {
const [isSimple, setIsSimple] = useState(false);
const [currentChatid, setCurrentChatid] = useState('');
const handleNewChat = useCallback(() => {
window.history.replaceState({}, '', '/');
setCurrentChatid('');
const event = new Event(EventEnum.NEW_CHAT);
window.dispatchEvent(event);
}, []);
if (loading) return <SidebarSkeleton />;
// if (error) {
// console.error('Error loading chats:', error);
// return null;
// }
console.log(`${isCollapsed}, ${isMobile}, ${isSimple}`);
return (
<div
data-collapsed={isCollapsed}
className="relative justify-between group lg:bg-accent/0 lg:dark:bg-card/0 flex flex-col h-full"
>
<Sidebar collapsible="icon" side="left">
<SidebarTrigger
className={`lg:flex items-center justify-center cursor-pointer p-2 ml-3.5 mt-2`}
onClick={() => setIsSimple(!isSimple)}
></SidebarTrigger>
<Button
onClick={() => handleNewChat()}
size="setting"
variant="ghost"
className={`flex justify-between w-[90%] h-14 text-sm xl:text-lg font-normal items-center ml-[5%]`}
>
<Image
src="/codefox.svg"
alt="AI"
width={48}
height={48}
className={`flex-shrink-0 dark:invert ${isSimple ? 'm-auto' : ''}`}
/>
{!isSimple && (
<div
className={cn('flex items-center', {
'gap-7': !isMobile,
'gap-4': isMobile,
})}
>
New chat
{(!isCollapsed || isMobile) && (
<SquarePen
className={cn('shrink-0', {
'ml-[12.5%]': isSimple && !isMobile,
'm-3': !isSimple,
})}
/>
)}
</div>
)}
</Button>
<SidebarContent>
<SidebarGroup>
<SidebarGroupContent></SidebarGroupContent>
</SidebarGroup>
</SidebarContent>
<SidebarFooter>
<UserSettings isSimple={isSimple} />
</SidebarFooter>
<SidebarRail setIsSimple={setIsSimple} isSimple={isSimple} />
</Sidebar>
</div>
);
}