@@ -17,8 +17,8 @@ interface ChatState {
17
17
sideView ?: { title : string ; elements : IMessageElement [ ] } ;
18
18
chatProfile ?: string ;
19
19
chatSettingsInputs : any [ ] ;
20
- chatSettingsDefaultValue : any ;
21
- chatSettingsValue : any ;
20
+ chatSettingsDefaultValue : Record < any , any > ;
21
+ chatSettingsValue : Record < any , any > ;
22
22
23
23
setIsAiSpeaking : ( isAiSpeaking : boolean ) => void ;
24
24
setAudioConnection : ( audioConnection : 'connecting' | 'on' | 'off' ) => void ;
@@ -42,7 +42,7 @@ interface ChatState {
42
42
) => void ;
43
43
setChatProfile : ( chatProfile : string ) => void ;
44
44
setChatSettingsInputs : ( chatSettingsInputs : any [ ] ) => void ;
45
- setChatSettingsValue : ( chatSettingsValue : any ) => void ;
45
+ setChatSettingsValue : ( chatSettingsValue : Record < any , any > ) => void ;
46
46
resetChatSettingsInputs : ( ) => void ;
47
47
resetChatSettingsValue : ( ) => void ;
48
48
}
@@ -55,8 +55,8 @@ export const useChatStore = create<ChatState>((set, get) => ({
55
55
wavRecorder : new WavRecorder ( ) ,
56
56
commands : [ ] ,
57
57
chatSettingsInputs : [ ] ,
58
- chatSettingsValue : [ ] ,
59
- chatSettingsDefaultValue : [ ] ,
58
+ chatSettingsValue : { } ,
59
+ chatSettingsDefaultValue : { } ,
60
60
61
61
setIsAiSpeaking : ( isAiSpeaking ) => {
62
62
set ( { isAiSpeaking } ) ;
@@ -87,7 +87,15 @@ export const useChatStore = create<ChatState>((set, get) => ({
87
87
} ,
88
88
89
89
setChatSettingsInputs : ( chatSettingsInputs ) => {
90
- set ( { chatSettingsInputs } ) ;
90
+ // Collect default values of all inputs
91
+ const chatSettingsDefaultValue = chatSettingsInputs . reduce (
92
+ ( form : { [ key : string ] : any } , input : any ) => (
93
+ ( form [ input . id ] = input . initial ) , form
94
+ ) ,
95
+ { }
96
+ ) ;
97
+
98
+ set ( { chatSettingsInputs, chatSettingsDefaultValue } ) ;
91
99
} ,
92
100
93
101
setChatSettingsValue : ( chatSettingsValue ) => {
@@ -109,14 +117,3 @@ export const useChatStore = create<ChatState>((set, get) => ({
109
117
set ( { chatSettingsValue } ) ;
110
118
}
111
119
} ) ) ;
112
-
113
- // useChatStore.subscribe((state, prevState) => {
114
- // const chatSettingsDefaultValue = state.chatSettingsInputs.reduce(
115
- // (form: { [key: string]: any }, input: any) => (
116
- // (form[input.id] = input.initial), form
117
- // ),
118
- // {}
119
- // );
120
- //
121
- // useChatStore.setState({chatSettingsDefaultValue });
122
- // })
0 commit comments