File tree Expand file tree Collapse file tree 7 files changed +89
-60
lines changed Expand file tree Collapse file tree 7 files changed +89
-60
lines changed Original file line number Diff line number Diff line change @@ -6,26 +6,29 @@ import Global from '../global';
6
6
import conf from '../config' ;
7
7
import { useSelector , useDispatch } from 'react-redux'
8
8
// 登录
9
- export const login = ( { config = { } , update, remember } ) => {
9
+ export const login = ( { mutationKey } ) => {
10
+ const dispatch = useDispatch ( )
10
11
const mutation = useMutation ( {
12
+ mutationKey,
11
13
mutationFn : userLogin ,
12
14
onSuccess : async data => {
13
15
if ( data ?. token && data ?. data ) {
14
16
await AsyncStorage . setItem ( 'token' , data . token ) ;
15
- if ( remember ) {
16
- await AsyncStorage . setItem ( 'cachLoginName' , formData . loginName ) ;
17
- await AsyncStorage . setItem ( 'cachPassword' , formData . password ) ;
18
- }
19
17
await AsyncStorage . setItem ( 'userData' , JSON . stringify ( data . data ) ) ;
20
- update ( { token : data . token , userData : data . data } ) ;
18
+ dispatch ( {
19
+ type : "global/update" ,
20
+ payload : {
21
+ token : data . token ,
22
+ userData : JSON . stringify ( data . data )
23
+ }
24
+ } )
21
25
if ( Global . navigation ) {
22
26
Global . navigation . replace ( 'Tab' ) ;
23
27
}
24
28
} else if ( data && data . message ) {
25
29
Alert . alert ( `Login failed - ${ data . error } ` , data . message ) ;
26
30
}
27
31
} ,
28
- ...config ,
29
32
} ) ;
30
33
return mutation ;
31
34
} ;
@@ -65,7 +68,7 @@ export const useAuthToken = () => {
65
68
dispatch ( {
66
69
type : "global/update" ,
67
70
payload : {
68
- authState : true ,
71
+ authState : true ,
69
72
token : null
70
73
}
71
74
} )
Original file line number Diff line number Diff line change @@ -11,23 +11,17 @@ import { login } from '../../hooks/users'
11
11
12
12
const SigninScreen = ( {
13
13
navigation,
14
- update,
15
14
} ) => {
16
15
const [ store , setStore ] = useState ( {
17
16
hostType : '' ,
18
- remember : false ,
19
17
formData : {
20
18
username : 'admin' ,
21
19
password : 'admin!' ,
22
20
} ,
23
21
} )
24
- const { hostType, remember , formData } = store
22
+ const { hostType, formData } = store
25
23
26
- const { mutate, isLoading } = login ( {
27
- update,
28
- formData,
29
- remember
30
- } )
24
+ const { mutate, isLoading } = login ( { mutationKey : [ 'userLogin' , formData ] } )
31
25
32
26
useEffect ( ( ) => {
33
27
if ( navigation && Global ) {
@@ -46,7 +40,7 @@ const SigninScreen = ({
46
40
}
47
41
} ;
48
42
49
- const loginIn = ( ) => mutate ?. ( { ... formData } )
43
+ const loginIn = ( ) => mutate ?. ( formData )
50
44
51
45
return (
52
46
< SafeAreaView style = { styles . block } >
@@ -104,12 +98,7 @@ const SigninScreen = ({
104
98
) ;
105
99
}
106
100
107
- export default connect (
108
- ( { } ) => ( { } ) ,
109
- ( { global } ) => ( {
110
- update : global . update
111
- } ) ,
112
- ) ( SigninScreen ) ;
101
+ export default SigninScreen
113
102
114
103
const styles = StyleSheet . create ( {
115
104
block : {
Original file line number Diff line number Diff line change 1
1
import React , { Component } from 'react' ;
2
2
import { SafeAreaView } from 'react-native' ;
3
3
4
- export default class MyScreen extends Component {
5
- render ( ) {
6
- return (
7
- < SafeAreaView > </ SafeAreaView >
8
- ) ;
9
- }
4
+ export default function MyScreen ( ) {
5
+ return (
6
+ < SafeAreaView > </ SafeAreaView >
7
+ ) ;
10
8
}
Original file line number Diff line number Diff line change @@ -131,6 +131,55 @@ git commit -m "Keep calm and commit"
131
131
└──@react-native-community/masked-view
132
132
```
133
133
134
+ ## 目录结构
135
+ ```
136
+ ├── Gemfile
137
+ ├── README.md
138
+ ├── __tests__
139
+ │ └── App-test.js
140
+ ├── _bundle
141
+ │ └── config
142
+ ├── _node-version
143
+ ├── android
144
+ │ ├── app
145
+ │ ├── build.gradle
146
+ │ ├── gradle
147
+ │ ├── gradle.properties
148
+ │ ├── gradlew
149
+ │ ├── gradlew.bat
150
+ │ └── settings.gradle
151
+ ├── app.json
152
+ ├── babel.config.js
153
+ ├── index.js
154
+ ├── ios
155
+ │ ├── HelloWorld
156
+ │ ├── HelloWorld.xcodeproj
157
+ │ ├── HelloWorld.xcworkspace
158
+ │ ├── HelloWorldTests
159
+ │ ├── Podfile
160
+ │ ├── Podfile.lock
161
+ │ ├── Pods
162
+ │ ├── _xcode.env
163
+ │ └── build
164
+ ├── jsconfig.json
165
+ ├── metro.config.js
166
+ ├── mocker
167
+ │ ├── index.js
168
+ │ └── user.mock.js
169
+ ├── package.json
170
+ └── src
171
+ ├── App.js
172
+ ├── components
173
+ ├── config.js
174
+ ├── global.js
175
+ ├── hooks
176
+ ├── models
177
+ ├── pages
178
+ ├── routes
179
+ ├── services
180
+ └── utils
181
+ ```
182
+
134
183
## Links
135
184
136
185
- [ React Native upgrade helper] ( https://react-native-community.github.io/upgrade-helper/ )
Original file line number Diff line number Diff line change @@ -6,26 +6,29 @@ import Global from '../global';
6
6
import conf from '../config' ;
7
7
import { useSelector , useDispatch } from 'react-redux'
8
8
// 登录
9
- export const login = ( { config = { } , update, remember } ) => {
9
+ export const login = ( { mutationKey } ) => {
10
+ const dispatch = useDispatch ( )
10
11
const mutation = useMutation ( {
12
+ mutationKey,
11
13
mutationFn : userLogin ,
12
14
onSuccess : async data => {
13
15
if ( data ?. token && data ?. data ) {
14
16
await AsyncStorage . setItem ( 'token' , data . token ) ;
15
- if ( remember ) {
16
- await AsyncStorage . setItem ( 'cachLoginName' , formData . loginName ) ;
17
- await AsyncStorage . setItem ( 'cachPassword' , formData . password ) ;
18
- }
19
17
await AsyncStorage . setItem ( 'userData' , JSON . stringify ( data . data ) ) ;
20
- update ( { token : data . token , userData : data . data } ) ;
18
+ dispatch ( {
19
+ type : "global/update" ,
20
+ payload : {
21
+ token : data . token ,
22
+ userData : JSON . stringify ( data . data )
23
+ }
24
+ } )
21
25
if ( Global . navigation ) {
22
26
Global . navigation . replace ( 'Tab' ) ;
23
27
}
24
28
} else if ( data && data . message ) {
25
29
Alert . alert ( `Login failed - ${ data . error } ` , data . message ) ;
26
30
}
27
31
} ,
28
- ...config ,
29
32
} ) ;
30
33
return mutation ;
31
34
} ;
@@ -65,7 +68,7 @@ export const useAuthToken = () => {
65
68
dispatch ( {
66
69
type : "global/update" ,
67
70
payload : {
68
- authState : true ,
71
+ authState : true ,
69
72
token : null
70
73
}
71
74
} )
Original file line number Diff line number Diff line change @@ -7,27 +7,21 @@ import Global from '../../global';
7
7
import Footer from '../../components/Footer' ;
8
8
import { logoLight } from '../../components/icons/signin' ;
9
9
import conf from '../../config' ;
10
- import { useLogin } from '../../hooks/users'
10
+ import { login } from '../../hooks/users'
11
11
12
12
const SigninScreen = ( {
13
13
navigation,
14
- update,
15
14
} ) => {
16
15
const [ store , setStore ] = useState ( {
17
16
hostType : '' ,
18
- remember : false ,
19
17
formData : {
20
18
username : 'admin' ,
21
19
password : 'admin!' ,
22
20
} ,
23
21
} )
24
- const { hostType, remember , formData } = store
22
+ const { hostType, formData } = store
25
23
26
- const { mutate, isLoading } = useLogin ( {
27
- update,
28
- formData,
29
- remember
30
- } )
24
+ const { mutate, isLoading } = login ( { mutationKey : [ 'userLogin' , formData ] } )
31
25
32
26
useEffect ( ( ) => {
33
27
if ( navigation && Global ) {
@@ -46,7 +40,7 @@ const SigninScreen = ({
46
40
}
47
41
} ;
48
42
49
- const loginIn = ( ) => mutate ?. ( { ... formData } )
43
+ const loginIn = ( ) => mutate ?. ( formData )
50
44
51
45
return (
52
46
< SafeAreaView style = { styles . block } >
@@ -104,12 +98,7 @@ const SigninScreen = ({
104
98
) ;
105
99
}
106
100
107
- export default connect (
108
- ( { } ) => ( { } ) ,
109
- ( { global } ) => ( {
110
- update : global . update
111
- } ) ,
112
- ) ( SigninScreen ) ;
101
+ export default SigninScreen
113
102
114
103
const styles = StyleSheet . create ( {
115
104
block : {
Original file line number Diff line number Diff line change 1
1
import React , { Component } from 'react' ;
2
- import { View , SafeAreaView } from 'react-native' ;
2
+ import { SafeAreaView } from 'react-native' ;
3
3
4
- export default class MyScreen extends Component {
5
- render ( ) {
6
- return (
7
- < SafeAreaView > </ SafeAreaView >
8
- ) ;
9
- }
4
+ export default function MyScreen ( ) {
5
+ return (
6
+ < SafeAreaView > </ SafeAreaView >
7
+ ) ;
10
8
}
You can’t perform that action at this time.
0 commit comments