mirror of
https://github.com/geoffsee/open-gsio.git
synced 2025-09-08 22:56:46 +00:00
Handle cases with missing id
in messages, improve index lookup logic, and refactor save handler.
This commit is contained in:

committed by
Geoff Seemueller

parent
580f361457
commit
3cf7ceb868
@@ -25,12 +25,17 @@ const MessageEditor = observer(({ message, onCancel }: MessageEditorProps) => {
|
||||
onCancel();
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
await messageEditorStore.handleSave();
|
||||
onCancel();
|
||||
};
|
||||
|
||||
|
||||
|
||||
const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {
|
||||
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
|
||||
e.preventDefault();
|
||||
messageEditorStore.handleSave();
|
||||
handleSave();
|
||||
}
|
||||
|
||||
if (e.key === "Escape") {
|
||||
@@ -66,7 +71,7 @@ const MessageEditor = observer(({ message, onCancel }: MessageEditorProps) => {
|
||||
<IconButton
|
||||
aria-label="Save edit"
|
||||
icon={<Check />}
|
||||
onClick={() => messageEditorStore.handleSave()}
|
||||
onClick={handleSave}
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
color={"accent.confirm"}
|
||||
|
@@ -26,7 +26,8 @@ export const MessageEditorStore = types
|
||||
self.editedContent = content;
|
||||
},
|
||||
setMessage(message: Instance<typeof Message>) {
|
||||
self.messageId = message.id;
|
||||
// Handle messages that might not have an id property (for testing)
|
||||
self.messageId = message.id || "";
|
||||
self.editedContent = message.content;
|
||||
},
|
||||
onCancel() {
|
||||
|
@@ -32,7 +32,7 @@ export const MessagesStore = types
|
||||
},
|
||||
editMessage(message: Instance<typeof Message>, newContent: string) {
|
||||
// Find the index of the message in the items array
|
||||
const messageIndex = self.items.indexOf(message);
|
||||
const messageIndex = self.items.map(i => i.id).indexOf(message.id);
|
||||
if (messageIndex === -1) {
|
||||
// Message not found in the items array
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user