/
Sharing.tsx
153 lines (138 loc) Β· 4.34 KB
/
Sharing.tsx
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import * as React from 'react'
import {StoredState} from '../../utils/statestore'
import * as ReactGA from 'react-ga'
import { events } from '../../utils/events'
import TrackLink from '../TrackLink/TrackLink'
const styles: any = require('./Sharing.module.styl')
interface Props {
}
interface State {
slackSent: boolean
email: string
}
interface Context {
storedState: StoredState
}
export default class Sharing extends React.Component<Props, State> {
static contextTypes = {
storedState: React.PropTypes.object.isRequired,
}
context: Context
constructor(props: Props, context: Context) {
super(props)
this.state = {
slackSent: false,
email: context.storedState.user ? context.storedState.user.email : '',
}
}
render() {
const shareTitle = 'I just learned how to develop apps with Apollo and GraphQL'
const shareUrl = encodeURIComponent(window.location.origin)
return (
<div className='db'>
<p
style={{
paddingTop: '0.92rem',
}}
>
We hope you enjoyed learning Apollo! We put a lot of work into these resources and hope it helps as many developers as possible getting started with Apollo.
You can help us by sharing it.
</p>
<div
className='flex justify-center'
style={{
paddingBottom: '2rem',
marginBottom: '2rem',
}}
>
<TrackLink
event={events.ShareWrapupTwitter}
href={`http://www.twitter.com/share?url=${shareUrl}&text=${shareTitle}`}
target='_blank'
className={styles.button}
style={{background: '#3cf'}}
>
Share on Twitter
</TrackLink>
<TrackLink
event={events.ShareWrapupTwitter}
href={`https://www.facebook.com/sharer/sharer.php?u=${shareUrl}&t=${shareTitle}`}
target='_blank'
className={`ml2 ${styles.button}`}
style={{background: '#3b5998'}}
>
Share on Facebook
</TrackLink>
</div>
<h1
className='accent'
style={{
fontWeight: 300,
paddingTop: 30,
paddingBottom: '0.92rem',
marginTop: 'calc(2.3rem - 30px)',
marginBottom: '1.6rem',
borderBottom: '1px solid rgba(0, 0, 0, 0.0980392)',
}}
>
Setup a GraphQL backend for your next project
</h1>
<p>
If you liked working with the included server and console right in your browser, check out <a href='http://graph.cool'>Graphcool</a>. It enables you to setup a GraphQL backend in minutes so you can focus on building awesome applications.
</p>
<div className='w-100'>
<img src={'http://i.imgur.com/J0zGy6N.png'} />
</div>
<p>
If you need further help with GraphQL, Apollo or Graphcool or have any other questions, come and join our Slack.
</p>
{this.state.slackSent &&
<strong>
Gotcha! Please check your emails and look for the #learnapollo channel after joining Slack.
</strong>
}
{!this.state.slackSent &&
<div
className='flex justify-center'
style={{
marginBottom: '2rem',
}}
>
<input
type='text'
value={this.state.email}
placeholder='you@gmail.com'
className={styles.mail}
onKeyDown={this.submitOnEnter}
onChange={(e: any) => this.setState({ email: e.target.value } as State)}
/>
<button className={styles.slackButton} onClick={this.submit}>
<img src={require('../../assets/images/slack_logo.png')}/>
Join Slack
</button>
</div>
}
</div>
)
}
private submitOnEnter = (e: React.KeyboardEvent<any>) => {
if (e.keyCode === 13) {
this.submit()
}
}
private submit = () => {
const { email } = this.state
ReactGA.event(events.JoinSlack)
fetch('https://slack.graph.cool/invite', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({ email }),
})
.then(() => {
this.setState({slackSent: true} as State)
})
}
}