-
Notifications
You must be signed in to change notification settings - Fork 63
/
user.js
52 lines (42 loc) · 925 Bytes
/
user.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
'use strict';
import { AlertIOS } from 'react-native';
import * as TYPES from './types';
// fake user data
let testUser = {
'name': 'juju',
'age': '24',
'avatar': 'https://avatars1.githubusercontent.com/u/1439939?v=3&s=460'
};
// for skip user
let skipUser = {
'name': 'guest',
'age': 20,
'avatar': 'https://avatars1.githubusercontent.com/u/1439939?v=3&s=460',
};
// login
export function logIn(opt){
return (dispatch) => {
dispatch({'type': TYPES.LOGGED_DOING});
let inner_get = fetch('http://www.baidu.com')
.then((res)=>{
dispatch({'type': TYPES.LOGGED_IN, user: testUser});
}).catch((e)=>{
console.log(e);
AlertIOS.alert(e.message);
dispatch({'type': TYPES.LOGGED_ERROR, error: e});
});
}
}
// skip login
export function skipLogin(){
return {
'type': TYPES.LOGGED_IN,
'user': skipUser,
}
}
// logout
export function logOut(){
return {
'type': TYPES.LOGGED_OUT
}
}