Skip to content

Commit e84d776

Browse files
committed
cleanup for localstorage multi-chat support
1 parent d351fd1 commit e84d776

File tree

2 files changed

+57
-24
lines changed

2 files changed

+57
-24
lines changed

src/client/components/ChatV2/ChatV2.tsx

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { useTranslation } from 'react-i18next'
1212
import { handleCompletionStreamError } from './error'
1313
import { getCompletionStream } from './util'
1414

15-
import { Box, Typography } from '@mui/material'
15+
import { Box, Typography, Fade, Collapse } from '@mui/material'
1616
import SettingsIcon from '@mui/icons-material/Settings'
1717
import EmailIcon from '@mui/icons-material/Email'
1818
import DeleteIcon from '@mui/icons-material/Delete'
@@ -40,13 +40,15 @@ export const ChatV2 = () => {
4040
const [model, setModel] = useLocalStorageState<{ name: string }>('model-v2', {
4141
name: DEFAULT_MODEL,
4242
})
43-
const [system, setSystem] = useLocalStorageState<{ content: string }>('general-chat-system', { content: '' })
44-
const [message, setMessage] = useLocalStorageState<{ content: string }>('general-chat-current', { content: '' })
45-
const [messages, setMessages] = useLocalStorageState<Message[]>('general-chat-messages', [])
46-
const [prevResponse, setPrevResponse] = useLocalStorageState<{
47-
id: string
48-
}>('general-prev-response', { id: '' })
4943

44+
// local storage
45+
const localStoragePrefix = 'general'
46+
const [system, setSystem] = useLocalStorageState<{ content: string }>(`${localStoragePrefix}-chat-system`, { content: '' })
47+
const [message, setMessage] = useLocalStorageState<{ content: string }>(`${localStoragePrefix}-chat-current`, { content: '' })
48+
const [messages, setMessages] = useLocalStorageState<Message[]>(`${localStoragePrefix}-chat-messages`, [])
49+
const [prevResponse, setPrevResponse] = useLocalStorageState<{ id: string }>(`${localStoragePrefix}-prev-response`, { id: '' })
50+
51+
// States
5052
const [settingsModalOpen, setSettingsModalOpen] = useState(false)
5153
const [activePromptId, setActivePromptId] = useState('')
5254
const [fileName, setFileName] = useState<string>('')
@@ -63,6 +65,7 @@ export const ChatV2 = () => {
6365
const [ragIndexId, setRagIndexId] = useState<number | null>(null)
6466
const ragIndex = ragIndices?.find((index) => index.id === ragIndexId) ?? null
6567

68+
// Refs
6669
const appContainerRef = useContext(AppContext)
6770
const chatContainerRef = useRef<HTMLDivElement>(null)
6871
const conversationRef = useRef<HTMLElement>(null)
@@ -207,6 +210,12 @@ export const ChatV2 = () => {
207210
clearRetryTimeout()
208211
}
209212

213+
useEffect(() => {
214+
// Fethces data from local storage according to chat
215+
console.log("course changed")
216+
217+
}, [course])
218+
210219
useEffect(() => {
211220
// Scrolls to bottom on initial load only
212221
if (!appContainerRef.current || !conversationRef.current || !chatHeaderRef.current || messages.length === 0) return
@@ -253,8 +262,8 @@ export const ChatV2 = () => {
253262
minWidth: 1400,
254263
}}
255264
>
256-
{/* Course chats columns */}
257-
<Box sx={{ position: 'relative', flex: 1, borderRight: '1px solid lightgray' }}>
265+
{/* Chat selection column -------------------------------------------------------------------------------------------*/}
266+
<Box sx={{ position: 'relative', flex: 1, borderRight: '1px solid rgba(0, 0, 0, 0.12)' }}>
258267
<Box sx={{ position: 'sticky', top: 80, padding: '2rem 1.5rem' }}>
259268
<Typography variant="h6" fontWeight="light">
260269
Currechat
@@ -278,11 +287,11 @@ export const ChatV2 = () => {
278287
</Box>
279288
</Box>
280289

281-
{/* Chat view */}
290+
{/* Chat view column ------------------------------------------------------------------------------------------------ */}
282291
<Box
283292
ref={chatContainerRef}
284293
sx={{
285-
flex: 4,
294+
flex: 3,
286295
display: 'flex',
287296
position: 'relative',
288297
flexDirection: 'column',
@@ -301,11 +310,13 @@ export const ChatV2 = () => {
301310
zIndex: 10,
302311
}}
303312
>
304-
{course && (
305-
<Typography variant="h5" sx={{ textAlign: 'center', fontWeight: 'bold', mb: '1.5rem' }}>
306-
{course.id === 'sandbox' ? 'OHTE Sandbox' : course.id}
307-
</Typography>
308-
)}
313+
<Collapse in={!!course} timeout={100}>
314+
<Fade in={true} timeout={800}>
315+
<Typography variant="h5" sx={{ textAlign: 'center', fontWeight: 'bold', mb: '1.5rem' }}>
316+
{course?.id === 'sandbox' ? 'OHTE Sandbox' : course?.id}
317+
</Typography>
318+
</Fade>
319+
</Collapse>
309320

310321
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: '1.5rem' }}>
311322
{/* {disclaimerInfo && <Disclaimer disclaimer={disclaimerInfo} />}
@@ -358,15 +369,37 @@ export const ChatV2 = () => {
358369
</Box>
359370
</Box>
360371

361-
{/* Annotations columns */}
362-
<Box sx={{ flex: 1, borderLeft: 'none', position: 'relative' }}>
363-
{ragIndex && (
364-
<Box sx={{ position: 'sticky', top: 80 }}>
365-
<CitationsBox messages={messages} fileSearchResult={fileSearchResult} />
366-
</Box>
367-
)}
372+
{/* Annotations columns ----------------------------------------------------------------------------------------------------- */}
373+
<Box sx={{ position: 'relative', flex: 1 }}>
374+
<Box sx={{ position: 'sticky', top: 80, padding: '4rem 2rem 2rem 0' }}>
375+
{/* {ragIndex && ( */}
376+
{course && (
377+
<Box sx={{ height: '100%', display: 'flex', flexDirection: 'column', gap: '1.5rem' }}>
378+
<Typography variant="h6">Lähteet</Typography>
379+
<Box sx={{ flex: 1, borderRadius: '1rem', backgroundColor: 'rgba(0,0,0,0.0)', display: 'flex', flexDirection: 'column', gap: '1.5rem' }}>
380+
{/* <CitationsBox messages={messages} fileSearchResult={fileSearchResult} /> */}
381+
<Box sx={{ borderLeft: '4px solid #3f51b5', paddingLeft: '1rem', backgroundColor: 'white', borderRadius: '4px' }}>
382+
<Typography variant="body2" color="textSecondary">
383+
Make sure your ref is attached to a real DOM element (component="div" for MUI Box). Only access .current.clientHeight after the DOM is rendered...
384+
</Typography>
385+
</Box>
386+
<Box sx={{ borderLeft: '4px solid #3f51b5', paddingLeft: '1rem', backgroundColor: 'white', borderRadius: '4px' }}>
387+
<Typography variant="body2" color="textSecondary">
388+
Make sure your ref is attached to a real DOM element (component="div" for MUI Box). Only access .current.clientHeight after the DOM is rendered...
389+
</Typography>
390+
</Box>
391+
<Box sx={{ borderLeft: '4px solid #3f51b5', paddingLeft: '1rem', backgroundColor: 'white', borderRadius: '4px' }}>
392+
<Typography variant="body2" color="textSecondary">
393+
Make sure your ref is attached to a real DOM element (component="div" for MUI Box). Only access .current.clientHeight after the DOM is rendered...
394+
</Typography>
395+
</Box>
396+
</Box>
397+
</Box>
398+
)}
399+
</Box>
368400
</Box>
369401

402+
{/* Modal --------------------------------------*/}
370403
<SettingsModal
371404
open={settingsModalOpen}
372405
setOpen={setSettingsModalOpen}

src/client/components/ChatV2/Conversation.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const Conversation = ({
7373
isCompletionDone: boolean
7474
fileSearchResult: FileSearchResult
7575
}) => (
76-
<Box style={{ height: '100%', display: 'flex', flexDirection: 'column', gap: '2.5rem' }} ref={conversationRef}>
76+
<Box style={{ height: '100%', display: 'flex', flexDirection: 'column', gap: '2rem' }} ref={conversationRef}>
7777
{messages.length === 0 && <ConversationSplash />}
7878
{messages.map((message, idx) => {
7979
const isLastAssistantNode = idx === messages.length - 1 && message.role === 'assistant'

0 commit comments

Comments
 (0)