@@ -10,7 +10,7 @@ import { BeatLoader } from "react-spinners";
1010import { useDebouncedCallback } from "use-debounce" ;
1111import { Input } from "@chakra-ui/react" ;
1212import SimpleMarkdown from "@/markdown/SimpleMarkdown" ;
13- import { SharedApi } from "@/types/shared" ;
13+ import type { Chat , Conversation , SharedApi } from "@/types/shared" ;
1414
1515const ChatInput = styled ( "input" ) `
1616 background: #ffffff;
@@ -93,10 +93,10 @@ export const ChatRoom = ({
9393} : ChatRoomProps ) => {
9494 const chatsWrapper = React . useRef < HTMLDivElement > ( null ) ;
9595 const [ disable , setDisable ] = React . useState ( false ) ;
96- const [ chatHistory , setChatHistory ] = React . useState < any > ( [ ] ) ;
96+ const [ chatHistory , setChatHistory ] = React . useState < Chat [ ] > ( [ ] ) ;
9797 const [ message , setMessage ] = React . useState ( initMessage ?? "" ) ;
9898
99- const [ conversations , setConversations ] = useState < any > ( [ ] ) ;
99+ const [ conversations , setConversations ] = useState < Conversation [ ] > ( [ ] ) ;
100100 const [ currentConversation , setCurrentConversation ] = useState < number | null > ( null ) ;
101101 // editing conversation name
102102 const [ editing , setEditing ] = useState < number | null > ( null ) ;
@@ -110,11 +110,11 @@ export const ChatRoom = ({
110110 method : "POST" ,
111111 body : JSON . stringify ( {
112112 action : "get_conversations" ,
113- } as any ) ,
113+ } ) ,
114114 } ) ;
115- const data = ( await response . json ( ) ) as any ;
115+ const data = await response . json ( ) ;
116116 if ( ! response . ok ) {
117- alert ( "Error: " + JSON . stringify ( ( data as any ) . error ) ) ;
117+ alert ( "Error: " + JSON . stringify ( data . error ) ) ;
118118 return ;
119119 }
120120 setConversations ( data ) ;
@@ -155,7 +155,7 @@ export const ChatRoom = ({
155155 async function changeConversationName ( conversationId : number , name : string ) {
156156 await changeConversationNameApi ( conversationId , name ) ;
157157
158- setConversations ( ( c : any [ ] ) =>
158+ setConversations ( ( c ) =>
159159 c . map ( ( conversation ) => {
160160 if ( conversation . id === conversationId ) {
161161 return {
@@ -175,7 +175,7 @@ export const ChatRoom = ({
175175 if ( conversationId == null ) {
176176 return ;
177177 }
178- setEditingName ( conversations . find ( ( c : any ) => c . id === conversationId ) ?. name ?? "" ) ;
178+ setEditingName ( conversations . find ( ( c ) => c . id === conversationId ) ?. name ?? "" ) ;
179179 setEditing ( conversationId ) ;
180180 return ;
181181 }
@@ -208,7 +208,7 @@ export const ChatRoom = ({
208208 if ( ! data ) {
209209 return ;
210210 }
211- setConversations ( conversations . filter ( ( conversation : any ) => conversation . id !== conversationId ) ) ;
211+ setConversations ( conversations . filter ( ( conversation ) => conversation . id !== conversationId ) ) ;
212212 }
213213
214214 async function deleteAllConversations ( ) {
@@ -242,7 +242,7 @@ export const ChatRoom = ({
242242 // TODO(CGQAQ): custom name of user
243243 // name: "User",
244244 } ,
245- ] as any ;
245+ ] as Chat [ ] ;
246246
247247 setChatHistory ( [ ...updatedHistory ] ) ;
248248
@@ -312,7 +312,7 @@ export const ChatRoom = ({
312312 New chat
313313 </ div >
314314 < div className = "overflow-y-auto overflow-container" >
315- { conversations . map ( ( conversation : any ) => (
315+ { conversations . map ( ( conversation ) => (
316316 < div
317317 key = { conversation . id }
318318 className = { `${
@@ -399,7 +399,7 @@ export const ChatRoom = ({
399399 ref = { chatsWrapper }
400400 className = "flex flex-col gap-4 w-full px-4 max-h-[80%] overflow-y-auto mt-11 scroll-smooth"
401401 >
402- { chatHistory . map ( ( chat : any , index : number ) => {
402+ { chatHistory . map ( ( chat , index ) => {
403403 return (
404404 < div key = { index } className = "flex flex-col gap-14 " >
405405 { chat . role === "user" ? (
0 commit comments