diff --git a/src/components/workspace/ControlBar.tsx b/src/components/workspace/ControlBar.tsx index e6637a1816..08d87ae13f 100644 --- a/src/components/workspace/ControlBar.tsx +++ b/src/components/workspace/ControlBar.tsx @@ -77,7 +77,7 @@ interface IExternal { symbols: string[]; } -class ControlBar extends React.PureComponent { +class ControlBar extends React.PureComponent { public static defaultProps: Partial = { hasChapterSelect: false, hasSaveButton: false, @@ -89,15 +89,15 @@ class ControlBar extends React.PureComponent { }; private inviteInputElem: React.RefObject; - private joinInputElem: React.RefObject; private shareInputElem: React.RefObject; constructor(props: ControlBarProps) { super(props); + this.state = { value: '' }; + this.handleChange = this.handleChange.bind(this); this.selectShareInputText = this.selectShareInputText.bind(this); this.selectInviteInputText = this.selectInviteInputText.bind(this); this.inviteInputElem = React.createRef(); - this.joinInputElem = React.createRef(); this.shareInputElem = React.createRef(); } @@ -167,7 +167,7 @@ class ControlBar extends React.PureComponent { xmlhttp.send(); } }; - const handleStartJoining = (e: React.FormEvent) => { + const handleStartJoining = (event: React.FormEvent) => { const xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = () => { if (xmlhttp.readyState === 4 && xmlhttp.status === 200) { @@ -175,7 +175,7 @@ class ControlBar extends React.PureComponent { const state = JSON.parse(xmlhttp.responseText).state; if (state === true) { // Session ID exists - this.props.handleSetEditorSessionId!(this.joinInputElem.current!.value); + this.props.handleSetEditorSessionId!(this.state!.value); } else { this.props.handleInvalidEditorSessionId!(); this.props.handleSetEditorSessionId!(''); @@ -185,14 +185,9 @@ class ControlBar extends React.PureComponent { this.props.handleSetEditorSessionId!(''); } }; - xmlhttp.open( - 'GET', - 'https://' + LINKS.SHAREDB_SERVER + 'gists/' + this.joinInputElem.current!.value, - true - ); + xmlhttp.open('GET', 'https://' + LINKS.SHAREDB_SERVER + 'gists/' + this.state!.value, true); xmlhttp.send(); - - e.preventDefault(); + event.preventDefault(); }; const inviteButton = this.props.hasCollabEditing ? ( @@ -212,7 +207,7 @@ class ControlBar extends React.PureComponent { {controlButton('Join', IconNames.LOG_IN)} <>
- + {controlButton('', IconNames.KEY_ENTER, null, { type: 'submit' })} @@ -223,9 +218,17 @@ class ControlBar extends React.PureComponent { undefined ); const leaveButton = this.props.hasCollabEditing - ? controlButton('Leave', IconNames.FEED, () => this.props.handleSetEditorSessionId!(''), { - iconColor: this.props.websocketStatus === 0 ? Colors.RED3 : Colors.GREEN3 - }) + ? controlButton( + 'Leave', + IconNames.FEED, + () => { + this.props.handleSetEditorSessionId!(''); + this.setState({ value: '' }); + }, + { + iconColor: this.props.websocketStatus === 0 ? Colors.RED3 : Colors.GREEN3 + } + ) : undefined; const chapterSelectButton = this.props.hasChapterSelect ? chapterSelect(this.props.sourceChapter, this.props.handleChapterSelect) @@ -315,6 +318,10 @@ class ControlBar extends React.PureComponent { ); } + private handleChange(event: React.ChangeEvent) { + this.setState({ value: event.target.value }); + } + private selectShareInputText() { if (this.shareInputElem.current !== null) { this.shareInputElem.current.focus();