Merge branch 'lf/chat-new-dm-race' (#2823)

* origin/lf/chat-new-dm-race:
  chat-js: fix race condition in new-dm flow

Signed-off-by: Matilde Park <matilde@tlon.io>
This commit is contained in:
Matilde Park 2020-05-04 20:48:50 -04:00
commit 8c3e2cff92

View File

@ -11,13 +11,10 @@ export class NewDmScreen extends Component {
super(props); super(props);
this.state = { this.state = {
ship: null, ship: null,
idError: false, station: null,
inviteError: false,
allowHistory: true,
awaiting: false awaiting: false
}; };
this.setInvite = this.setInvite.bind(this);
this.onClickCreate = this.onClickCreate.bind(this); this.onClickCreate = this.onClickCreate.bind(this);
} }
@ -26,8 +23,6 @@ export class NewDmScreen extends Component {
if (props.autoCreate && urbitOb.isValidPatp(props.autoCreate)) { if (props.autoCreate && urbitOb.isValidPatp(props.autoCreate)) {
this.setState( this.setState(
{ {
error: false,
success: true,
ship: props.autoCreate.slice(1), ship: props.autoCreate.slice(1),
awaiting: true awaiting: true
}, },
@ -40,20 +35,14 @@ export class NewDmScreen extends Component {
const { props, state } = this; const { props, state } = this;
if (prevProps !== props) { if (prevProps !== props) {
let station = `/~${window.ship}/${state.idName}`; const { station } = this.state;
if (station in props.inbox) { if (station && station in props.inbox) {
props.history.push("/~chat/room" + station); this.setState({ awaiting: false });
props.history.push(`/~chat/room${station}`);
} }
} }
} }
setInvite(value) {
this.setState({
groups: [],
ship: value.ships[0]
});
}
onClickCreate() { onClickCreate() {
const { props, state } = this; const { props, state } = this;
@ -73,15 +62,11 @@ export class NewDmScreen extends Component {
this.setState( this.setState(
{ {
error: false, station
success: true,
group: [],
ship: [],
awaiting: true
}, },
() => { () => {
let groupPath = station; let groupPath = station;
let submit = props.api.chatView.create( props.api.chatView.create(
`~${window.ship} <-> ~${state.ship}`, `~${window.ship} <-> ~${state.ship}`,
"", "",
station, station,
@ -90,10 +75,6 @@ export class NewDmScreen extends Component {
state.ship !== window.ship ? [`~${state.ship}`] : [], state.ship !== window.ship ? [`~${state.ship}`] : [],
true true
); );
submit.then(() => {
this.setState({ awaiting: false });
props.history.push(`/~chat/room${station}`);
});
} }
); );
} }