Created
March 16, 2018 18:25
-
-
Save divyanshu013/8dc9f728889bc2888d6960056bbd8ced to your computer and use it in GitHub Desktop.
TodosContainer component for todos native auth app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
// create auth0 service first here | |
import Auth0 from 'react-native-auth0'; | |
const auth0 = new Auth0({ domain: 'divyanshu.auth0.com', clientId: '6ZR8Jgj6Gzy1onJhrO0egEbfudIBVZNP' }); | |
... | |
export default class TodosContainer extends React.Component { | |
... | |
onAllData = (todos, streamData) => { | |
const todosData = Utils.mergeTodos(todos, streamData); | |
// filter data based on "screen": [All | Active | Completed] | |
const filteredData = this.filterTodosData(todosData); | |
return ( | |
<FlatList | |
style={{ width: '100%', top: 15 }} | |
data={filteredData || []} | |
keyExtractor={item => item._id} | |
renderItem={({ item: todo }) => ( | |
<TodoItem | |
todo={todo} | |
onUpdate={this.api.update} | |
onDelete={this.api.destroy} | |
// pass via props | |
screenProps={this.props.screenProps} | |
/> | |
)} | |
/> | |
); | |
}; | |
... | |
render() { | |
const isAndroid = Platform.OS === 'android'; | |
const { accessToken, handleLogin, handleLogout } = this.props.screenProps; | |
return ( | |
<View style={{ flex: 1 }}> | |
... | |
<ScrollView> | |
<Button | |
title={accessToken ? 'Logout' : 'Login to modify'} | |
onPress={accessToken ? handleLogout : handleLogin} | |
style={{ | |
marginTop: 10, | |
marginBottom: 10 | |
}} | |
/> | |
... | |
{this.state.addingTodo ? ( | |
<View style={styles.row}> | |
<AddTodo | |
onAdd={(todo) => { | |
this.setState({ addingTodo: false }); | |
this.api.add(todo, this.props.screenProps); // pass screenProps here | |
}} | |
onCancelDelete={() => this.setState({ addingTodo: false })} | |
onBlur={() => this.setState({ addingTodo: false })} | |
/> | |
</View> | |
) : null} | |
</ScrollView> | |
<AddTodoButton onPress={() => this.setState({ addingTodo: true })} /> | |
</View> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment