Skip to content

Commit 9ca4120

Browse files
committed
Added signin with email and signout screen
1 parent 330913a commit 9ca4120

File tree

10 files changed

+496
-10
lines changed

10 files changed

+496
-10
lines changed

android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ allprojects {
2323
}
2424
}
2525
}
26+

app/components/DemoList/index.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React, { PropTypes as T } from 'react';
2+
import {connect} from 'react-redux'
3+
4+
import {
5+
View,
6+
Text
7+
} from 'react-native'
8+
9+
import appStyles from '../../styles/app';
10+
import List from '../../components/List/List'
11+
12+
export class DemoList extends React.Component {
13+
static propTypes = {
14+
routes: T.object.isRequired,
15+
routeKey: T.string.isRequired
16+
}
17+
18+
render() {
19+
const { routes, routeKey } = this.props;
20+
21+
const initialRows = Object.keys(routes).map(key => {
22+
const routeCfg = routes[key];
23+
return { title: routeCfg.route.title, key: `${routeKey}.${key}` }
24+
})
25+
return (
26+
<View style={appStyles.container}>
27+
<List
28+
initialRows={initialRows}
29+
renderRow={this._renderRow.bind(this)}
30+
onRowPress={this._onRowPress.bind(this)}
31+
/>
32+
</View>
33+
)
34+
}
35+
36+
_renderRow(rowData, sectionID, rowID, highlightRow) {
37+
console.log(rowData)
38+
return (
39+
<View style={[appStyles.row]}>
40+
<Text>{rowData.title}</Text>
41+
</View>
42+
)
43+
}
44+
45+
_onRowPress(rowData) {
46+
const rowKey = rowData.key;
47+
const {actions} = this.props;
48+
const {navigation} = actions;
49+
navigation.push(rowKey, this.props);
50+
}
51+
}
52+
53+
const mapStateToProps = (state) => ({
54+
firestack: state.firestack
55+
})
56+
export default connect(mapStateToProps)(DemoList)

app/routes.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Authentication, { Routes as AuthRoutes } from './views/Authentication';
1212
import Messaging, { Routes as MessagingRoutes } from './views/Messaging';
1313
import Presence, { Routes as PresenceRoutes } from './views/Presence'
1414
import Analytics, { Routes as AnalyticsRoutes } from './views/Analytics';
15+
import Storage, { Routes as StorageRoutes } from './views/Storage';
1516

1617
export type Route = {
1718
key: String,
@@ -54,6 +55,13 @@ export const exampleRoutes = {
5455
Component: Messaging
5556
},
5657
children: MessagingRoutes
58+
},
59+
'storage': {
60+
route: {
61+
title: 'Storage',
62+
Component: Storage
63+
},
64+
children: StorageRoutes
5765
}
5866
}
5967

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
import React from 'react'
2+
3+
import {
4+
View,
5+
Text,
6+
NativeModules
7+
} from 'react-native'
8+
9+
import env from '../../../../config/environment';
10+
11+
import { Container, Header, Title, Content, List, ListItem, InputGroup, Input, Icon, Button } from 'native-base';
12+
13+
import SignedIn from '../components/SignedIn';
14+
import appStyles from '../../../styles/app';
15+
16+
export class Email extends React.Component {
17+
18+
constructor(props) {
19+
super(props);
20+
21+
this.state = {
22+
user: null,
23+
email: '',
24+
password: ''
25+
}
26+
}
27+
28+
componentWillMount() {
29+
const {firestack} = this.props;
30+
31+
firestack.auth.listenForAuth((u) => {
32+
console.log('listenForAuth ->', u);
33+
});
34+
}
35+
36+
fillInFields() {
37+
this.setState({
38+
email: 'ari@fullstack.io',
39+
password: '123456'
40+
});
41+
}
42+
43+
loginWithEmail(evt) {
44+
const {firestack} = this.props;
45+
const { email, password } = this.state;
46+
47+
firestack.auth.signInWithEmail(email, password)
48+
.then(u => {
49+
console.log('Signed in!', u);
50+
this.setState({
51+
user: u,
52+
email: '',
53+
password: ''
54+
});
55+
})
56+
.catch(err => {
57+
console.log('An error occurred', err);
58+
});
59+
}
60+
61+
onSignout() {
62+
console.log('yay?', this.state);
63+
this.setState({
64+
user: null,
65+
email: '',
66+
password: ''
67+
});
68+
}
69+
70+
componentWillUnmount() {
71+
const {firestack} = this.props;
72+
firestack.auth.unlistenForAuth();
73+
}
74+
75+
render() {
76+
const {firestack} = this.props;
77+
const { user, email, password } = this.state;
78+
if (user) {
79+
return (
80+
<SignedIn
81+
user={user}
82+
firestack={firestack}
83+
onSignout={this.onSignout.bind(this)} />
84+
)
85+
}
86+
return (
87+
<Container>
88+
<Content>
89+
<List>
90+
<ListItem>
91+
<InputGroup>
92+
<Icon name='ios-person' />
93+
<Input
94+
placeholder='EMAIL'
95+
value={email} />
96+
</InputGroup>
97+
</ListItem>
98+
99+
<ListItem>
100+
<InputGroup>
101+
<Icon name='ios-unlock' />
102+
<Input
103+
placeholder='PASSWORD'
104+
secureTextEntry={true}
105+
value={password}
106+
/>
107+
</InputGroup>
108+
</ListItem>
109+
110+
<ListItem>
111+
<Button
112+
block
113+
info
114+
onPress={this.loginWithEmail.bind(this)}>
115+
<Text>Sign in</Text>
116+
</Button>
117+
</ListItem>
118+
119+
<ListItem>
120+
<Button
121+
block
122+
info
123+
onPress={this.fillInFields.bind(this)}>
124+
<Text>Fill forms with demo user info</Text>
125+
</Button>
126+
</ListItem>
127+
</List>
128+
</Content>
129+
</Container>
130+
)
131+
}
132+
133+
}
134+
135+
export default Email

0 commit comments

Comments
 (0)