Skip to content

Commit 7a498f8

Browse files
add token count to v2
1 parent 0d96a29 commit 7a498f8

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/client/components/ChatV2/ChatBox.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
import { Send } from '@mui/icons-material'
2-
import { Container, IconButton, Paper, TextField } from '@mui/material'
3-
import { useState } from 'react'
2+
import { Box, Container, IconButton, Paper, TextField, Typography } from '@mui/material'
3+
import { useEffect, useState } from 'react'
4+
import useUserStatus from '../../hooks/useUserStatus';
5+
import { useParams } from 'react-router-dom';
6+
import { useTranslation } from 'react-i18next';
47

58
export const ChatBox = ({ disabled, onSubmit }: { disabled: boolean; onSubmit: (message: string) => void }) => {
9+
const { courseId } = useParams()
10+
const { userStatus, isLoading: statusLoading, refetch: refetchStatus } = useUserStatus(courseId)
611
const [message, setMessage] = useState<string>('')
712

13+
const { t, i18n } = useTranslation()
814
const handleSubmit = (e: React.FormEvent) => {
915
e.preventDefault()
1016
if (message.trim()) {
1117
onSubmit(message)
1218
setMessage('')
19+
refetchStatus()
1320
}
1421
}
22+
useEffect(() => {
23+
console.log('userStatus', userStatus)
24+
})
1525

26+
if(statusLoading) {
27+
return (<p>loading</p>)
28+
}
1629
return (
1730
<Container
1831
disableGutters
@@ -60,6 +73,12 @@ export const ChatBox = ({ disabled, onSubmit }: { disabled: boolean; onSubmit: (
6073
},
6174
}}
6275
/>
76+
<Box>
77+
<Typography variant="body1">
78+
{userStatus.usage} / {userStatus.limit} {t('status:tokensUsed')}
79+
</Typography>
80+
</Box>
81+
6382
</Paper>
6483
</Container>
6584
)

0 commit comments

Comments
 (0)