-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchat-layout.tsx
118 lines (114 loc) · 3.29 KB
/
chat-layout.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
'use client';
import React, { useEffect, useState, Dispatch, SetStateAction } from 'react';
import {
ResizableHandle,
ResizablePanel,
ResizablePanelGroup,
} from '@/components/ui/resizable';
import { cn } from '@/lib/utils';
import { Sidebar } from '../sidebar';
import Chat from './chat';
import { Message } from '../types';
interface ChatLayoutProps {
defaultLayout?: number[];
defaultCollapsed?: boolean;
navCollapsedSize: number;
chatId: string;
messages: Message[];
input: string;
handleInputChange: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;
handleSubmit: (e: React.FormEvent<HTMLFormElement>) => void;
loadingSubmit: boolean;
stop: () => void;
setSelectedModel: Dispatch<SetStateAction<string>>;
formRef: React.RefObject<HTMLFormElement>;
setMessages: Dispatch<SetStateAction<Message[]>>;
setInput: Dispatch<SetStateAction<string>>;
}
export function ChatLayout({
defaultLayout = [30, 160],
defaultCollapsed = false,
navCollapsedSize,
messages,
input,
handleInputChange,
handleSubmit,
stop,
chatId,
setSelectedModel,
loadingSubmit,
formRef,
setMessages,
setInput,
}: ChatLayoutProps) {
const [isCollapsed, setIsCollapsed] = useState(defaultCollapsed);
const [isMobile, setIsMobile] = useState(false);
useEffect(() => {
const checkScreenWidth = () => {
setIsMobile(window.innerWidth <= 1023);
};
checkScreenWidth();
window.addEventListener('resize', checkScreenWidth);
return () => {
window.removeEventListener('resize', checkScreenWidth);
};
}, []);
return (
<ResizablePanelGroup
direction="horizontal"
onLayout={(sizes: number[]) => {
document.cookie = `react-resizable-panels:layout=${JSON.stringify(
sizes
)}`;
}}
className="h-screen items-stretch"
>
<ResizablePanel
defaultSize={defaultLayout[0]}
collapsedSize={navCollapsedSize}
collapsible={true}
minSize={isMobile ? 0 : 12}
maxSize={isMobile ? 0 : 16}
onCollapse={() => {
setIsCollapsed(true);
document.cookie = `react-resizable-panels:collapsed=${JSON.stringify(
true
)}`;
}}
onExpand={() => {
setIsCollapsed(false);
document.cookie = `react-resizable-panels:collapsed=${JSON.stringify(
false
)}`;
}}
className={cn(
isCollapsed
? 'min-w-[50px] md:min-w-[70px] transition-all duration-300 ease-in-out'
: 'hidden md:block'
)}
>
<Sidebar isCollapsed={isCollapsed || isMobile} isMobile={isMobile} />
</ResizablePanel>
<ResizableHandle className={cn('hidden md:flex')} withHandle />
<ResizablePanel
className="h-full w-full flex justify-center"
defaultSize={defaultLayout[1]}
>
<Chat
chatId={chatId}
setSelectedModel={setSelectedModel}
messages={messages}
input={input}
handleInputChange={handleInputChange}
handleSubmit={handleSubmit}
loadingSubmit={loadingSubmit}
stop={stop}
formRef={formRef}
isMobile={isMobile}
setInput={setInput}
setMessages={setMessages}
/>
</ResizablePanel>
</ResizablePanelGroup>
);
}