1
1
/* eslint-disable */
2
- import React , { useState } from 'react'
2
+ import React , { useState , useEffect } from 'react'
3
3
import GitHubLogin from 'react-github-login'
4
4
import { Button } from '@aragon/ui'
5
5
import './test.css'
6
- import { Octokit } from '@octokit/rest'
7
6
8
7
function APIcall ( ) {
9
8
const [ boolButtonText , setBoolButtonText ] = useState ( 'CONNECT' )
10
-
11
- const [ boolSwitch , setboolSwitch ] = useState ( false )
9
+ const [ boolButtonText_disconnect , setBoolButtonText_disconnect ] = useState (
10
+ 'DISCONNECT'
11
+ )
12
12
13
13
const onSuccess = function ( details ) {
14
14
const code = details . code
@@ -17,28 +17,58 @@ function APIcall() {
17
17
. then ( ( response ) => response . json ( ) )
18
18
. then ( ( { token } ) => localStorage . setItem ( 'ACCESS TOKEN' , token ) )
19
19
20
- if ( boolButtonText === 'CONNECT' ) {
21
- setBoolButtonText ( 'DISCONNECT' )
22
- } else {
23
- setBoolButtonText ( 'CONNECT' )
24
- }
20
+ // if (boolButtonText === 'CONNECT') {
21
+ // setBoolButtonText('DISCONNECT')
22
+ // } else {
23
+ // setBoolButtonText('CONNECT')
24
+ // }
25
+ setBoolButtonText ( 'DISCONNECT' )
26
+ }
27
+
28
+ const onSuccess_disconnect = function ( ) {
29
+ localStorage . removeItem ( 'ACCESS TOKEN' )
30
+ setBoolButtonText_disconnect ( 'CONNECT' )
31
+ }
25
32
26
- setboolSwitch ( true )
33
+ const onFailure_disconnect = function ( ) {
34
+ return null
27
35
}
28
36
29
37
const onFailure = ( response ) => console . error ( response )
30
38
31
39
return (
32
40
< div style = { { display : 'flex' , justifyContent : 'flex-end' } } >
33
41
< Button mode = 'normal' >
34
- < GitHubLogin
42
+ { localStorage . getItem ( 'ACCESS TOKEN' ) ? (
43
+ < GitHubLogin
44
+ clientId = '69bc88033c4b1bc2b4dc'
45
+ redirectUri = 'http://localhost:3000/'
46
+ onSuccess = { onSuccess_disconnect }
47
+ onFailure = { onFailure_disconnect }
48
+ buttonText = { boolButtonText_disconnect }
49
+ // buttonText='DISCONNECT'
50
+ className = 'testcss'
51
+ />
52
+ ) : (
53
+ < GitHubLogin
54
+ clientId = '69bc88033c4b1bc2b4dc'
55
+ redirectUri = 'http://localhost:3000/'
56
+ onSuccess = { onSuccess }
57
+ onFailure = { onFailure }
58
+ buttonText = { boolButtonText }
59
+ //buttonText='CONNECT'
60
+ className = 'testcss'
61
+ />
62
+ ) }
63
+
64
+ { /* <GitHubLogin
35
65
clientId='69bc88033c4b1bc2b4dc'
36
66
redirectUri='http://localhost:3000/'
37
67
onSuccess={onSuccess}
38
68
onFailure={onFailure}
39
69
buttonText={boolButtonText}
40
70
className='testcss'
41
- />
71
+ /> */ }
42
72
</ Button >
43
73
</ div >
44
74
)
0 commit comments