@@ -10,7 +10,7 @@ import { BeatLoader } from "react-spinners";
10
10
import { useDebouncedCallback } from "use-debounce" ;
11
11
import { Input } from "@chakra-ui/react" ;
12
12
import SimpleMarkdown from "@/markdown/SimpleMarkdown" ;
13
- import { SharedApi } from "@/types/shared" ;
13
+ import type { Chat , Conversation , SharedApi } from "@/types/shared" ;
14
14
15
15
const ChatInput = styled ( "input" ) `
16
16
background: #ffffff;
@@ -93,10 +93,10 @@ export const ChatRoom = ({
93
93
} : ChatRoomProps ) => {
94
94
const chatsWrapper = React . useRef < HTMLDivElement > ( null ) ;
95
95
const [ disable , setDisable ] = React . useState ( false ) ;
96
- const [ chatHistory , setChatHistory ] = React . useState < any > ( [ ] ) ;
96
+ const [ chatHistory , setChatHistory ] = React . useState < Chat [ ] > ( [ ] ) ;
97
97
const [ message , setMessage ] = React . useState ( initMessage ?? "" ) ;
98
98
99
- const [ conversations , setConversations ] = useState < any > ( [ ] ) ;
99
+ const [ conversations , setConversations ] = useState < Conversation [ ] > ( [ ] ) ;
100
100
const [ currentConversation , setCurrentConversation ] = useState < number | null > ( null ) ;
101
101
// editing conversation name
102
102
const [ editing , setEditing ] = useState < number | null > ( null ) ;
@@ -110,11 +110,11 @@ export const ChatRoom = ({
110
110
method : "POST" ,
111
111
body : JSON . stringify ( {
112
112
action : "get_conversations" ,
113
- } as any ) ,
113
+ } ) ,
114
114
} ) ;
115
- const data = ( await response . json ( ) ) as any ;
115
+ const data = await response . json ( ) ;
116
116
if ( ! response . ok ) {
117
- alert ( "Error: " + JSON . stringify ( ( data as any ) . error ) ) ;
117
+ alert ( "Error: " + JSON . stringify ( data . error ) ) ;
118
118
return ;
119
119
}
120
120
setConversations ( data ) ;
@@ -155,7 +155,7 @@ export const ChatRoom = ({
155
155
async function changeConversationName ( conversationId : number , name : string ) {
156
156
await changeConversationNameApi ( conversationId , name ) ;
157
157
158
- setConversations ( ( c : any [ ] ) =>
158
+ setConversations ( ( c ) =>
159
159
c . map ( ( conversation ) => {
160
160
if ( conversation . id === conversationId ) {
161
161
return {
@@ -175,7 +175,7 @@ export const ChatRoom = ({
175
175
if ( conversationId == null ) {
176
176
return ;
177
177
}
178
- setEditingName ( conversations . find ( ( c : any ) => c . id === conversationId ) ?. name ?? "" ) ;
178
+ setEditingName ( conversations . find ( ( c ) => c . id === conversationId ) ?. name ?? "" ) ;
179
179
setEditing ( conversationId ) ;
180
180
return ;
181
181
}
@@ -208,7 +208,7 @@ export const ChatRoom = ({
208
208
if ( ! data ) {
209
209
return ;
210
210
}
211
- setConversations ( conversations . filter ( ( conversation : any ) => conversation . id !== conversationId ) ) ;
211
+ setConversations ( conversations . filter ( ( conversation ) => conversation . id !== conversationId ) ) ;
212
212
}
213
213
214
214
async function deleteAllConversations ( ) {
@@ -242,7 +242,7 @@ export const ChatRoom = ({
242
242
// TODO(CGQAQ): custom name of user
243
243
// name: "User",
244
244
} ,
245
- ] as any ;
245
+ ] as Chat [ ] ;
246
246
247
247
setChatHistory ( [ ...updatedHistory ] ) ;
248
248
@@ -312,7 +312,7 @@ export const ChatRoom = ({
312
312
New chat
313
313
</ div >
314
314
< div className = "overflow-y-auto overflow-container" >
315
- { conversations . map ( ( conversation : any ) => (
315
+ { conversations . map ( ( conversation ) => (
316
316
< div
317
317
key = { conversation . id }
318
318
className = { `${
@@ -399,7 +399,7 @@ export const ChatRoom = ({
399
399
ref = { chatsWrapper }
400
400
className = "flex flex-col gap-4 w-full px-4 max-h-[80%] overflow-y-auto mt-11 scroll-smooth"
401
401
>
402
- { chatHistory . map ( ( chat : any , index : number ) => {
402
+ { chatHistory . map ( ( chat , index ) => {
403
403
return (
404
404
< div key = { index } className = "flex flex-col gap-14 " >
405
405
{ chat . role === "user" ? (
0 commit comments