-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathApp.js
69 lines (62 loc) · 1.82 KB
/
App.js
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 PropTypes from 'prop-types'
import Head from 'react-helmet'
import { GoogleSheetsApi } from '../../'
import DynamicSpreadsheet from './DynamicSpreadsheet'
import ApiForm from './ApiForm'
import Blob from './Blob'
const SheetsDemo = props => (
<GoogleSheetsApi clientId={props.clientId} apiKey={props.apiKey}>
{({ authorize, loading: apiLoading, signout, signedIn, error }) => (
<div>
{apiLoading ? (
<div>Loading...</div>
) : error ? (
<Blob data={error} />
) : signedIn ? (
<button onClick={signout}>Sign Out</button>
) : (
<button onClick={authorize}>Authorize</button>
)}
{signedIn && <DynamicSpreadsheet />}
</div>
)}
</GoogleSheetsApi>
)
SheetsDemo.propTypes = {
clientId: PropTypes.string.isRequired,
apiKey: PropTypes.string.isRequired,
reset: PropTypes.func.isRequired,
}
class App extends React.Component {
state = {
apiKey: 'AIzaSyDS0rsId2YdsGWAgU4xiLm8zS8gf4k9d2Y',
clientId:
'377437361891-v0ib2hve7mupdcpsibtuqr35o2h61op9.apps.googleusercontent.com',
}
handleSubmit = state => this.setState(state)
reset = () => this.setState({ apiKey: '', clientId: '' })
render() {
return (
<div>
<Head>
<title>Google Sheets React Component Demo</title>
</Head>
<h1>Google Sheets API React Component</h1>
{this.state.apiKey && (
<button onClick={this.reset}>Change developer credentials</button>
)}
{this.state.apiKey ? (
<SheetsDemo
apiKey={this.state.apiKey}
clientId={this.state.clientId}
reset={this.reset}
/>
) : (
<ApiForm onSubmit={this.handleSubmit} init={this.state} />
)}
</div>
)
}
}
export default App