Skip to content

Commit b94572a

Browse files
committed
add sandbox environment to ui
1 parent b010f70 commit b94572a

File tree

2 files changed

+47
-29
lines changed

2 files changed

+47
-29
lines changed

src/client/components/ChatV2/ChatV2.tsx

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const ChatV2 = () => {
6666
const appContainerRef = useContext(AppContext)
6767
const chatContainerRef = useRef<HTMLDivElement>(null)
6868
const conversationRef = useRef<HTMLElement>(null)
69-
const settingsRef = useRef<HTMLElement>(null)
69+
const chatHeaderRef = useRef<HTMLElement>(null)
7070
const inputFieldRef = useRef<HTMLElement>(null)
7171

7272
const [setRetryTimeout, clearRetryTimeout] = useRetryTimeout()
@@ -209,7 +209,7 @@ export const ChatV2 = () => {
209209

210210
useEffect(() => {
211211
// Scrolls to bottom on initial load only
212-
if (!appContainerRef.current || !conversationRef.current || !settingsRef.current || messages.length === 0) return
212+
if (!appContainerRef.current || !conversationRef.current || !chatHeaderRef.current || messages.length === 0) return
213213
if (isCompletionDone) {
214214
const container = appContainerRef.current
215215
if (container) {
@@ -223,13 +223,13 @@ export const ChatV2 = () => {
223223

224224
useEffect(() => {
225225
// Scrolls to last assistant message on text generation
226-
if (!appContainerRef.current || !conversationRef.current || !settingsRef.current || messages.length === 0) return
226+
if (!appContainerRef.current || !conversationRef.current || !chatHeaderRef.current || messages.length === 0) return
227227

228228
const lastNode = conversationRef.current.lastElementChild as HTMLElement
229229

230230
if (lastNode.classList.contains('message-role-assistant') && !isCompletionDone) {
231231
const container = appContainerRef.current
232-
const settingsHeight = settingsRef.current.clientHeight
232+
const settingsHeight = chatHeaderRef.current.clientHeight
233233

234234
const containerRect = container.getBoundingClientRect()
235235
const lastNodeRect = lastNode.getBoundingClientRect()
@@ -259,12 +259,22 @@ export const ChatV2 = () => {
259259
<Typography variant="h6" fontWeight="light">
260260
Currechat
261261
</Typography>
262-
<CourseOption link="/v2">Basic</CourseOption>
263262

264-
<Typography variant="h6" fontWeight="light" sx={{ mt: '2rem' }}>
263+
<Box sx={{ display: 'flex', flexDirection: 'column', gap: '0.2rem', padding: '0.5rem' }}>
264+
<CourseOption link="/v2" isActive={!course}>
265+
Tavallinen
266+
</CourseOption>
267+
</Box>
268+
269+
<Typography variant="h6" fontWeight="light" mt={'2rem'} mb="0.2rem">
265270
Kurssichatit
266271
</Typography>
267-
<CourseOption link="/v2/sandbox">Ohtu sandbox</CourseOption>
272+
273+
<Box sx={{ display: 'flex', flexDirection: 'column', gap: '0.2rem', padding: '0.5rem' }}>
274+
<CourseOption link="/v2/sandbox" isActive={!!course}>
275+
OHTE sandbox
276+
</CourseOption>
277+
</Box>
268278
</Box>
269279
</Box>
270280

@@ -280,30 +290,36 @@ export const ChatV2 = () => {
280290
}}
281291
>
282292
<Box
283-
ref={settingsRef}
293+
ref={chatHeaderRef}
284294
sx={{
285295
position: 'sticky',
286296
top: 80,
287297
display: 'flex',
288-
justifyContent: 'center',
289-
alignItems: 'center',
290-
gap: '1.2rem',
298+
flexDirection: 'column',
291299
backgroundColor: 'white',
292300
padding: '1.8rem 1rem 0.8rem 1rem',
293301
zIndex: 10,
294302
}}
295303
>
296-
{/* {disclaimerInfo && <Disclaimer disclaimer={disclaimerInfo} />}
304+
{course && (
305+
<Typography variant="h4" sx={{ textAlign: 'center', fontWeight: 'bold', mb: '1.5rem' }}>
306+
{course.id}
307+
</Typography>
308+
)}
309+
310+
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: '1.5rem' }}>
311+
{/* {disclaimerInfo && <Disclaimer disclaimer={disclaimerInfo} />}
297312
{/* <SettingsButton startIcon={<AddCommentIcon />}>Alustus</SettingsButton> */}
298-
<SettingsButton startIcon={<SettingsIcon />} onClick={() => setSettingsModalOpen(true)}>
299-
Keskustelun asetukset
300-
</SettingsButton>
301-
<SettingsButton startIcon={<EmailIcon />} onClick={() => alert('Ei toimi vielä')}>
302-
Tallenna sähköpostina
303-
</SettingsButton>
304-
<SettingsButton startIcon={<DeleteIcon />} onClick={handleReset}>
305-
Tyhjennä
306-
</SettingsButton>
313+
<SettingsButton startIcon={<SettingsIcon />} onClick={() => setSettingsModalOpen(true)}>
314+
Keskustelun asetukset
315+
</SettingsButton>
316+
<SettingsButton startIcon={<EmailIcon />} onClick={() => alert('Ei toimi vielä')}>
317+
Tallenna sähköpostina
318+
</SettingsButton>
319+
<SettingsButton startIcon={<DeleteIcon />} onClick={handleReset}>
320+
Tyhjennä
321+
</SettingsButton>
322+
</Box>
307323
</Box>
308324

309325
<Box
@@ -319,7 +335,7 @@ export const ChatV2 = () => {
319335
>
320336
<Conversation
321337
conversationRef={conversationRef}
322-
expandedNodeHeight={window.innerHeight - settingsRef.current?.clientHeight - inputFieldRef.current?.clientHeight}
338+
expandedNodeHeight={window.innerHeight - chatHeaderRef.current?.clientHeight - inputFieldRef.current?.clientHeight}
323339
messages={messages}
324340
completion={completion}
325341
isCompletionDone={isCompletionDone}
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
import { useState, type ReactNode } from 'react'
22
import { Typography } from '@mui/material'
3-
import { Link } from 'react-router-dom'
3+
import { useNavigate } from 'react-router-dom'
44

5-
export default function CourseOption({ children, link }: { children: ReactNode; link: string }) {
5+
export default function CourseOption({ children, link, isActive }: { children: ReactNode; link: string, isActive: boolean }) {
66
const [isHovered, setIsHovered] = useState<boolean>(false)
7+
const navigate = useNavigate()
78

89
return (
910
<Typography
1011
sx={{
11-
backgroundColor: isHovered ? '#efefef' : 'transparent',
12-
color: 'black',
12+
backgroundColor: isHovered || isActive ? '#efefef' : 'transparent',
1313
cursor: 'pointer',
1414
borderRadius: '0.5rem',
1515
padding: '0.5rem 1rem',
1616
transitionDuration: '200ms',
1717
textDecoration: 'none',
18+
display: 'flex',
19+
alignItems: 'center',
20+
gap: '0.5rem',
1821
}}
1922
onMouseEnter={() => setIsHovered(true)}
2023
onMouseLeave={() => setIsHovered(false)}
24+
onClick={() => navigate(link)}
2125
>
22-
<Link style={{ textDecoration: 'none', textTransform: 'none' }} to={link}>
23-
{children}
24-
</Link>
26+
{children}
2527
</Typography>
2628
)
2729
}

0 commit comments

Comments
 (0)