feat: deletion of messages
This commit is contained in:
parent
97f0483f9a
commit
4d87f86ff7
9 changed files with 111 additions and 24 deletions
|
|
@ -2,6 +2,17 @@ import { ChatAction, ChatState } from "../contexts/ChatContext";
|
|||
|
||||
export function chatReducer(state: ChatState, action: ChatAction): ChatState {
|
||||
switch (action.type) {
|
||||
case "DELETE_MESSAGE":
|
||||
return {
|
||||
...state,
|
||||
messages: state.messages.filter((message) => {
|
||||
// only potentially delete chat messages, dont touch system messages
|
||||
if ("type" in message && message.type === "CHAT_MESSAGE") {
|
||||
return message.payload.id !== action.payload;
|
||||
}
|
||||
return true;
|
||||
}),
|
||||
};
|
||||
case "ADD_MESSAGE":
|
||||
return {
|
||||
...state,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue