forked from Chainlit/chainlit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
75 lines (63 loc) · 2.09 KB
/
index.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
import { memo } from 'react';
import { useNavigate } from 'react-router-dom';
import { useAudio, useAuth, useConfig } from '@chainlit/react-client';
import AudioPresence from '@/components/AudioPresence';
import ButtonLink from '@/components/ButtonLink';
import { useSidebar } from '@/components/ui/sidebar';
import ApiKeys from './ApiKeys';
import ChatProfiles from './ChatProfiles';
import NewChatButton from './NewChat';
import ReadmeButton from './Readme';
import SidebarTrigger from './SidebarTrigger';
import { ThemeToggle } from './ThemeToggle';
import UserNav from './UserNav';
const Header = memo(() => {
const { audioConnection } = useAudio();
const navigate = useNavigate();
const { data } = useAuth();
const { config } = useConfig();
const { open, openMobile, isMobile } = useSidebar();
const sidebarOpen = isMobile ? openMobile : open;
const historyEnabled = data?.requireLogin && config?.dataPersistence;
const links = config?.ui?.header_links || [];
return (
<div
className="p-3 flex h-[60px] items-center justify-between gap-2 relative"
id="header"
>
<div className="flex items-center">
{historyEnabled ? !sidebarOpen ? <SidebarTrigger /> : null : null}
{historyEnabled ? (
!sidebarOpen ? (
<NewChatButton navigate={navigate} />
) : null
) : (
<NewChatButton navigate={navigate} />
)}
<ChatProfiles navigate={navigate} />
</div>
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2">
{audioConnection === 'on' ? (
<AudioPresence
type="server"
height={35}
width={70}
barCount={4}
barSpacing={2}
/>
) : null}
</div>
<div />
<div className="flex items-center gap-1">
<ReadmeButton />
<ApiKeys />
{links && (
links.map(link => <ButtonLink name={link.name} iconUrl={link.icon_url} url={link.url}/>)
)}
<ThemeToggle />
<UserNav />
</div>
</div>
);
});
export { Header };