mirror of
https://github.com/ilyakooo0/urbit.git
synced 2025-01-05 22:03:50 +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);
|
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}`);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user