Refactor InputMessage component and ChatStore
- Simplified the handleSendClick function in InputMessage/index.tsx to directly use input.value. - Made 'contexts' an optional field in the Message model in ChatStore.ts. - Updated the newMessage and updateLastMessage actions in ChatStore.ts to accept an IMessage object.
This commit is contained in:
parent
13a80ba67f
commit
1fe45ef5e0
@ -37,15 +37,10 @@ const InputMessage = observer((props: any) => {
|
||||
};
|
||||
|
||||
const handleSendClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
||||
if (input) {
|
||||
// Process and send the message to the extension
|
||||
const contextInfo = input.contexts.map((item: any, index: number) => {
|
||||
const { file, context } = item;
|
||||
return { file, context };
|
||||
});
|
||||
if (input.value) {
|
||||
const text = input.value;
|
||||
// Add the user's message to the chat UI
|
||||
chat.newMessage({ type: 'user', message: input, contexts: contexts ? [...contexts].map((item) => ({ ...item })) : undefined });
|
||||
chat.newMessage({ type: 'user', message: input.value, contexts: contexts ? [...contexts].map((item) => ({ ...item })) : undefined });
|
||||
// start generating
|
||||
chat.startGenerating(text);
|
||||
// Clear the input field
|
||||
|
@ -60,7 +60,7 @@ export const Message = types.model({
|
||||
hash: types.maybe(types.string),
|
||||
type: types.enumeration(['user', 'bot', 'system']),
|
||||
message: types.string,
|
||||
contexts: types.array(ChatContext),
|
||||
contexts: types.maybe(types.array(ChatContext)),
|
||||
});
|
||||
|
||||
export const ChatStore = types.model('Chat', {
|
||||
@ -135,13 +135,13 @@ export const ChatStore = types.model('Chat', {
|
||||
self.responsed = true;
|
||||
self.currentMessage = action.payload;
|
||||
},
|
||||
newMessage: (action) => {
|
||||
self.messages.push(action.payload);
|
||||
self.lastMessage = action.payload;
|
||||
newMessage: (message: IMessage) => {
|
||||
self.messages.push(message);
|
||||
self.lastMessage = message;
|
||||
},
|
||||
updateLastMessage: (action) => {
|
||||
self.messages[self.messages.length - 1] = action.payload;
|
||||
self.lastMessage = action.payload;
|
||||
updateLastMessage: (message: IMessage) => {
|
||||
self.messages[self.messages.length - 1] = message;
|
||||
self.lastMessage = message;
|
||||
},
|
||||
shiftMessage: () => {
|
||||
self.messages.splice(0, 1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user