Fix chat react state getting overwritten. Closes #1529
This commit is contained in:
@@ -169,10 +169,14 @@ export default class Chat extends Component {
|
|||||||
const chatUserNames = allChatUserNames.filter(
|
const chatUserNames = allChatUserNames.filter(
|
||||||
(name) => name != username
|
(name) => name != username
|
||||||
);
|
);
|
||||||
this.setState({
|
this.setState((previousState, currentProps) => {
|
||||||
messages: data.concat(this.state.messages),
|
return {
|
||||||
chatUserNames,
|
...previousState,
|
||||||
|
messages: data.concat(previousState.messages),
|
||||||
|
chatUserNames,
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
this.scrollToBottom();
|
this.scrollToBottom();
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@@ -208,8 +212,8 @@ export default class Chat extends Component {
|
|||||||
if (messageType === SOCKET_MESSAGE_TYPES.CONNECTED_USER_INFO) {
|
if (messageType === SOCKET_MESSAGE_TYPES.CONNECTED_USER_INFO) {
|
||||||
const modStatusUpdate = checkIsModerator(message);
|
const modStatusUpdate = checkIsModerator(message);
|
||||||
if (modStatusUpdate !== this.state.isModerator) {
|
if (modStatusUpdate !== this.state.isModerator) {
|
||||||
this.setState({
|
this.setState((previousState, currentProps) => {
|
||||||
isModerator: modStatusUpdate,
|
return { ...previousState, isModerator: modStatusUpdate };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -252,8 +256,8 @@ export default class Chat extends Component {
|
|||||||
Math.max(updatedMessageList.length - 300, 0)
|
Math.max(updatedMessageList.length - 300, 0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
this.setState({
|
this.setState((previousState, currentProps) => {
|
||||||
messages: updatedMessageList,
|
return { ...previousState, messages: updatedMessageList };
|
||||||
});
|
});
|
||||||
} else if (
|
} else if (
|
||||||
renderableChatStyleMessages.includes(messageType) &&
|
renderableChatStyleMessages.includes(messageType) &&
|
||||||
@@ -270,7 +274,10 @@ export default class Chat extends Component {
|
|||||||
);
|
);
|
||||||
newState.chatUserNames = [...updatedChatUserNames];
|
newState.chatUserNames = [...updatedChatUserNames];
|
||||||
}
|
}
|
||||||
this.setState(newState);
|
|
||||||
|
this.setState((previousState, currentProps) => {
|
||||||
|
return { ...previousState, newState };
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// if window is blurred and we get a new message, add 1 to title
|
// if window is blurred and we get a new message, add 1 to title
|
||||||
|
|||||||
Reference in New Issue
Block a user