Skip to content

Commit a391057

Browse files
committed
fix clear button
1 parent d326714 commit a391057

File tree

3 files changed

+97
-58
lines changed

3 files changed

+97
-58
lines changed

App.tsx

+30-24
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
View,
55
Text,
66
Button,
7-
Image,
87
ActivityIndicator,
98
StatusBar,
109
} from 'react-native'
@@ -77,7 +76,7 @@ export default class AppContainer extends React.Component<{}, State> {
7776
message: undefined,
7877
}
7978

80-
modal: any
79+
modal = React.createRef<LinkedInModal>()
8180

8281
constructor(props: any) {
8382
super(props)
@@ -86,7 +85,7 @@ export default class AppContainer extends React.Component<{}, State> {
8685

8786
getUser = async (data: LinkedInToken) => {
8887
const { access_token, authentication_code } = data
89-
if (access_token) {
88+
if (!authentication_code) {
9089
this.setState({ refreshing: true })
9190

9291
const response = await fetch('https://api.linkedin.com/v2/me', {
@@ -116,35 +115,42 @@ export default class AppContainer extends React.Component<{}, State> {
116115
) : null
117116
}
118117

118+
signOut = () => {
119+
this.setState({ refreshing: true })
120+
this.modal.current
121+
.logoutAsync()
122+
.then(() =>
123+
this.setState({ localizedFirstName: undefined, refreshing: false }),
124+
)
125+
}
126+
119127
render() {
120128
const { refreshing, localizedFirstName } = this.state
121129
return (
122130
<View style={styles.container}>
123-
{!refreshing && (
124-
<View style={styles.linkedInContainer}>
125-
<LinkedInModal
126-
ref={ref => {
127-
this.modal = ref
128-
}}
129-
clientID={CLIENT_ID}
130-
clientSecret={CLIENT_SECRET}
131-
shouldGetAccessToken={false}
132-
redirectUri="https://xaviercarpentier.com"
133-
onSuccess={this.getUser}
134-
/>
135-
<Button
136-
title="Open from external"
137-
onPress={() => this.modal.open()}
138-
/>
139-
</View>
140-
)}
131+
<View style={styles.linkedInContainer}>
132+
<LinkedInModal
133+
ref={this.modal}
134+
clientID={CLIENT_ID}
135+
clientSecret={CLIENT_SECRET}
136+
redirectUri="https://xaviercarpentier.com"
137+
onSuccess={this.getUser}
138+
/>
139+
<Button
140+
title="Open from external"
141+
onPress={() => this.modal.current.open()}
142+
/>
143+
</View>
141144

142145
{refreshing && <ActivityIndicator size="large" />}
143146

144147
{localizedFirstName && (
145-
<View style={styles.userContainer}>
146-
{this.renderItem('Last name', localizedFirstName)}
147-
</View>
148+
<>
149+
<View style={styles.userContainer}>
150+
{this.renderItem('Last name', localizedFirstName)}
151+
</View>
152+
<Button title="Log Out" onPress={this.signOut} />
153+
</>
148154
)}
149155
</View>
150156
)

0 commit comments

Comments
 (0)