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>) => {
|
const handleSendClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
||||||
if (input) {
|
if (input.value) {
|
||||||
// Process and send the message to the extension
|
|
||||||
const contextInfo = input.contexts.map((item: any, index: number) => {
|
|
||||||
const { file, context } = item;
|
|
||||||
return { file, context };
|
|
||||||
});
|
|
||||||
const text = input.value;
|
const text = input.value;
|
||||||
// Add the user's message to the chat UI
|
// 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
|
// start generating
|
||||||
chat.startGenerating(text);
|
chat.startGenerating(text);
|
||||||
// Clear the input field
|
// Clear the input field
|
||||||
|
@ -60,7 +60,7 @@ export const Message = types.model({
|
|||||||
hash: types.maybe(types.string),
|
hash: types.maybe(types.string),
|
||||||
type: types.enumeration(['user', 'bot', 'system']),
|
type: types.enumeration(['user', 'bot', 'system']),
|
||||||
message: types.string,
|
message: types.string,
|
||||||
contexts: types.array(ChatContext),
|
contexts: types.maybe(types.array(ChatContext)),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const ChatStore = types.model('Chat', {
|
export const ChatStore = types.model('Chat', {
|
||||||
@ -135,13 +135,13 @@ export const ChatStore = types.model('Chat', {
|
|||||||
self.responsed = true;
|
self.responsed = true;
|
||||||
self.currentMessage = action.payload;
|
self.currentMessage = action.payload;
|
||||||
},
|
},
|
||||||
newMessage: (action) => {
|
newMessage: (message: IMessage) => {
|
||||||
self.messages.push(action.payload);
|
self.messages.push(message);
|
||||||
self.lastMessage = action.payload;
|
self.lastMessage = message;
|
||||||
},
|
},
|
||||||
updateLastMessage: (action) => {
|
updateLastMessage: (message: IMessage) => {
|
||||||
self.messages[self.messages.length - 1] = action.payload;
|
self.messages[self.messages.length - 1] = message;
|
||||||
self.lastMessage = action.payload;
|
self.lastMessage = message;
|
||||||
},
|
},
|
||||||
shiftMessage: () => {
|
shiftMessage: () => {
|
||||||
self.messages.splice(0, 1);
|
self.messages.splice(0, 1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user