From 62405ce5d0e13e31e370c0074e8f6ab8d9e0a878 Mon Sep 17 00:00:00 2001 From: Matilde Park Date: Thu, 16 Jul 2020 13:44:11 -0400 Subject: [PATCH] groups: autojoin checks for group first --- .../src/apps/groups/components/join.js | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/pkg/interface/src/apps/groups/components/join.js b/pkg/interface/src/apps/groups/components/join.js index 6473ae141..a9a2e4992 100644 --- a/pkg/interface/src/apps/groups/components/join.js +++ b/pkg/interface/src/apps/groups/components/join.js @@ -18,21 +18,31 @@ export class JoinScreen extends Component { } componentDidMount() { - // direct join from incoming URL - if ((this.props.ship) && (this.props.name)) { - const incomingGroup = `${this.props.ship}/${this.props.name}`; + this.componentDidUpdate(); + } + + componentDidUpdate(prevProps) { + const { props, state } = this; + // autojoin by URL, waits for group information + if ((props.ship && props.name) && + (prevProps && (prevProps.groups !== props.groups))) { + console.log('autojoining'); + const incomingGroup = `${props.ship}/${props.name}`; + // push to group if already exists + if (`/ship/${incomingGroup}` in props.groups) { + this.props.history.push(`/~groups/ship/${incomingGroup}`); + return; + } this.setState({ group: incomingGroup }, () => { this.onClickJoin(); }); } - } - - componentDidUpdate() { - if (this.props.groups) { - if (this.state.awaiting) { - const group = `/ship/${this.state.group}`; - if (group in this.props.groups) { - this.props.history.push(`/~groups${group}`); + // once we've joined, push to group page + if (props.groups) { + if (state.awaiting) { + const group = `/ship/${state.group}`; + if (group in props.groups) { + props.history.push(`/~groups${group}`); } } } @@ -41,6 +51,7 @@ export class JoinScreen extends Component { onClickJoin() { const { props, state } = this; + console.log('i am joining'); const { group } = state; const [ship, name] = group.split('/');