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();
|
onCancel();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleSave = async () => {
|
||||||
|
await messageEditorStore.handleSave();
|
||||||
|
onCancel();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {
|
const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {
|
||||||
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
|
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
messageEditorStore.handleSave();
|
handleSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.key === "Escape") {
|
if (e.key === "Escape") {
|
||||||
@@ -66,7 +71,7 @@ const MessageEditor = observer(({ message, onCancel }: MessageEditorProps) => {
|
|||||||
<IconButton
|
<IconButton
|
||||||
aria-label="Save edit"
|
aria-label="Save edit"
|
||||||
icon={<Check />}
|
icon={<Check />}
|
||||||
onClick={() => messageEditorStore.handleSave()}
|
onClick={handleSave}
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
color={"accent.confirm"}
|
color={"accent.confirm"}
|
||||||
|
@@ -26,7 +26,8 @@ export const MessageEditorStore = types
|
|||||||
self.editedContent = content;
|
self.editedContent = content;
|
||||||
},
|
},
|
||||||
setMessage(message: Instance<typeof Message>) {
|
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;
|
self.editedContent = message.content;
|
||||||
},
|
},
|
||||||
onCancel() {
|
onCancel() {
|
||||||
|
@@ -32,7 +32,7 @@ export const MessagesStore = types
|
|||||||
},
|
},
|
||||||
editMessage(message: Instance<typeof Message>, newContent: string) {
|
editMessage(message: Instance<typeof Message>, newContent: string) {
|
||||||
// Find the index of the message in the items array
|
// 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) {
|
if (messageIndex === -1) {
|
||||||
// Message not found in the items array
|
// Message not found in the items array
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user