mirror of
https://github.com/urbit/shrub.git
synced 2024-12-01 14:42:02 +03:00
chat-js: fix race condition in new-dm flow
Creating a new DM might redirect the user to the chat before it is actually created. Fixed by waiting for confirmation before redirecting. Fixes #2792
This commit is contained in:
parent
3196179fbd
commit
ae0e5025ad
@ -11,13 +11,10 @@ export class NewDmScreen extends Component {
|
||||
super(props);
|
||||
this.state = {
|
||||
ship: null,
|
||||
idError: false,
|
||||
inviteError: false,
|
||||
allowHistory: true,
|
||||
station: null,
|
||||
awaiting: false
|
||||
};
|
||||
|
||||
this.setInvite = this.setInvite.bind(this);
|
||||
this.onClickCreate = this.onClickCreate.bind(this);
|
||||
}
|
||||
|
||||
@ -26,8 +23,6 @@ export class NewDmScreen extends Component {
|
||||
if (props.autoCreate && urbitOb.isValidPatp(props.autoCreate)) {
|
||||
this.setState(
|
||||
{
|
||||
error: false,
|
||||
success: true,
|
||||
ship: props.autoCreate.slice(1),
|
||||
awaiting: true
|
||||
},
|
||||
@ -40,20 +35,14 @@ export class NewDmScreen extends Component {
|
||||
const { props, state } = this;
|
||||
|
||||
if (prevProps !== props) {
|
||||
let station = `/~${window.ship}/${state.idName}`;
|
||||
if (station in props.inbox) {
|
||||
props.history.push("/~chat/room" + station);
|
||||
const { station } = this.state;
|
||||
if (station && station in props.inbox) {
|
||||
this.setState({ awaiting: false });
|
||||
props.history.push(`/~chat/room${station}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setInvite(value) {
|
||||
this.setState({
|
||||
groups: [],
|
||||
ship: value.ships[0]
|
||||
});
|
||||
}
|
||||
|
||||
onClickCreate() {
|
||||
const { props, state } = this;
|
||||
|
||||
@ -73,15 +62,11 @@ export class NewDmScreen extends Component {
|
||||
|
||||
this.setState(
|
||||
{
|
||||
error: false,
|
||||
success: true,
|
||||
group: [],
|
||||
ship: [],
|
||||
awaiting: true
|
||||
station
|
||||
},
|
||||
() => {
|
||||
let groupPath = station;
|
||||
let submit = props.api.chatView.create(
|
||||
props.api.chatView.create(
|
||||
`~${window.ship} <-> ~${state.ship}`,
|
||||
"",
|
||||
station,
|
||||
@ -90,10 +75,6 @@ export class NewDmScreen extends Component {
|
||||
state.ship !== window.ship ? [`~${state.ship}`] : [],
|
||||
true
|
||||
);
|
||||
submit.then(() => {
|
||||
this.setState({ awaiting: false });
|
||||
props.history.push(`/~chat/room${station}`);
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user