feat: editing of messages

This commit is contained in:
Alexander Daichendt 2025-02-12 13:28:28 +01:00
parent 4d87f86ff7
commit f27adc3360
7 changed files with 115 additions and 11 deletions

View file

@ -2,6 +2,25 @@ import { ChatAction, ChatState } from "../contexts/ChatContext";
export function chatReducer(state: ChatState, action: ChatAction): ChatState {
switch (action.type) {
case "EDIT_MESSAGE":
return {
...state,
messages: state.messages.map((message) => {
if ("type" in message && message.type === "CHAT_MESSAGE") {
if (message.payload.id === action.payload.messageId) {
return {
...message,
payload: {
...message.payload,
content: action.payload.newContent,
},
};
}
}
return message;
}),
};
case "DELETE_MESSAGE":
return {
...state,