-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathsidecar.jsx
69 lines (59 loc) · 2.05 KB
/
sidecar.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import React from 'react';
import Link from '../link/link';
import './sidecar-style';
export default React.createClass({
getInitialState() {
return {open: false};
},
initChat() {
this.chat = new window.gitter.Chat({
room: 'angular-fullstack/generator-angular-fullstack',
activationElement: '.js-gitter-toggle-chat-button',
preload: true
});
// console.log(this.chat);
document.addEventListener('gitter-sidecar-instance-started', chat => {
// console.log('loaded', chat);
this.chat = chat;
});
document.querySelector('.gitter-chat-embed').addEventListener('gitter-chat-toggle', e => {
this.state.open = e.detail.state;
// console.log(e.detail.state ? 'Chat Opened' : 'Chat Closed');
});
},
componentDidMount() {
// console.log('did mount');
if(window.gitter && typeof window.gitter.Chat === 'function') {
// console.log('already loaded');
this.initChat();
} else {
// console.log('waiting');
document.addEventListener('gitter-sidecar-ready', () => {
// console.log('ready');
this.initChat();
});
}
},
openChat() {
this.state.open = true;
this.chat.toggleChat(true);
},
render() {
return (
<aside className="sidecar">
<Link className="sidecar__link sidecar__link--github" to="//github.com/angular-fullstack/generator-angular-fullstack">
<span className="sidecar__label">Fork the Repo</span>
<i className="sidecar__icon icon-github" />
</Link>
<a className="sidecar__link sidecar__link--gitter js-gitter-toggle-chat-button" onClick={ this.openChat }>
<span className="sidecar__label">Find Help</span>
<i className="sidecar__icon icon-gitter" />
</a>
<Link className="sidecar__link sidecar__link--so" to="//stackoverflow.com/questions/tagged/generator-angular-fullstack">
<span className="sidecar__label">Stack Overflow</span>
<i className="sidecar__icon icon-stack-overflow" />
</Link>
</aside>
);
}
});