Skip to content

Fix issue #531 #535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions src/components/workspace/ControlBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ interface IExternal {
symbols: string[];
}

class ControlBar extends React.PureComponent<ControlBarProps, {}> {
class ControlBar extends React.PureComponent<ControlBarProps, { value: string }> {
public static defaultProps: Partial<ControlBarProps> = {
hasChapterSelect: false,
hasSaveButton: false,
Expand All @@ -89,15 +89,15 @@ class ControlBar extends React.PureComponent<ControlBarProps, {}> {
};

private inviteInputElem: React.RefObject<HTMLInputElement>;
private joinInputElem: React.RefObject<HTMLInputElement>;
private shareInputElem: React.RefObject<HTMLInputElement>;

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();
}

Expand Down Expand Up @@ -167,15 +167,15 @@ class ControlBar extends React.PureComponent<ControlBarProps, {}> {
xmlhttp.send();
}
};
const handleStartJoining = (e: React.FormEvent<HTMLFormElement>) => {
const handleStartJoining = (event: React.FormEvent<HTMLFormElement>) => {
const xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = () => {
if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
// Successfully reached server to verify ID
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!('');
Expand All @@ -185,14 +185,9 @@ class ControlBar extends React.PureComponent<ControlBarProps, {}> {
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 ? (
<Popover popoverClassName="Popover-share" inheritDarkTheme={false}>
Expand All @@ -212,7 +207,7 @@ class ControlBar extends React.PureComponent<ControlBarProps, {}> {
{controlButton('Join', IconNames.LOG_IN)}
<>
<form onSubmit={handleStartJoining}>
<input defaultValue="" ref={this.joinInputElem} />
<input type="text" value={this.state.value} onChange={this.handleChange} />
<span className={Classes.POPOVER_DISMISS}>
{controlButton('', IconNames.KEY_ENTER, null, { type: 'submit' })}
</span>
Expand All @@ -223,9 +218,17 @@ class ControlBar extends React.PureComponent<ControlBarProps, {}> {
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)
Expand Down Expand Up @@ -315,6 +318,10 @@ class ControlBar extends React.PureComponent<ControlBarProps, {}> {
);
}

private handleChange(event: React.ChangeEvent<HTMLInputElement>) {
this.setState({ value: event.target.value });
}

private selectShareInputText() {
if (this.shareInputElem.current !== null) {
this.shareInputElem.current.focus();
Expand Down