components/app: make switchBuffer state changes atomic

Instead of calling App.setBufferState inside the App.setState
callback invoked when the update is done, call State.updateBuffer.
This commit is contained in:
Simon Ser 2022-02-11 15:48:56 +01:00
parent 4cb3abfa72
commit e91b044134

View file

@ -402,19 +402,20 @@ export default class App extends Component {
if (!buf) { if (!buf) {
return; return;
} }
return { activeBuffer: buf.id };
let prevReadReceipt = this.getReceipt(buf.name, ReceiptType.READ);
// TODO: only mark as read if user scrolled at the bottom
let update = State.updateBuffer(state, buf.id, {
unread: Unread.NONE,
prevReadReceipt,
});
return { ...update, activeBuffer: buf.id };
}, () => { }, () => {
if (!buf) { if (!buf) {
return; return;
} }
let prevReadReceipt = this.getReceipt(buf.name, ReceiptType.READ);
// TODO: only mark as read if user scrolled at the bottom
this.setBufferState(buf.id, {
unread: Unread.NONE,
prevReadReceipt,
});
if (this.buffer.current) { if (this.buffer.current) {
this.buffer.current.focus(); this.buffer.current.focus();
} }