@@ -4,88 +4,88 @@ import { getUserInfo } from './auth'
4
4
5
5
//获取标签列表.
6
6
export const getTagList = ( ) => {
7
- return {
8
- type : types . TAG_LIST ,
9
- promise : api . getTagList ( )
10
- }
7
+ return {
8
+ type : types . TAG_LIST ,
9
+ promise : api . getTagList ( )
10
+ }
11
11
}
12
12
//更改options
13
13
export const changeOptions = ( option ) => ( { type : types . CHANGE_OPTIONS , option : option } )
14
14
15
15
//切换Like
16
16
function receiveToggleLike ( json ) {
17
- return {
18
- type : types . TOGGLE_LIKE_SUCCESS ,
19
- like_count : json . count ,
20
- isLike : json . isLike
21
- }
17
+ return {
18
+ type : types . TOGGLE_LIKE_SUCCESS ,
19
+ like_count : json . count ,
20
+ isLike : json . isLike
21
+ }
22
22
}
23
23
24
24
export function toggleLike ( aid ) {
25
- return ( dispatch , getState ) => {
26
- return api . toggleLike ( aid )
27
- . then ( response => ( { json : response . data , status : response . statusText } ) )
28
- . then ( ( { json, status} ) => {
29
- if ( status !== 'OK' ) {
30
- return dispatch ( { type : types . TOGGLE_LIKE_FAILURE } )
31
- }
32
- dispatch ( getUserInfo ( ) )
33
- return dispatch ( receiveToggleLike ( json ) )
34
- } )
35
- . catch ( error => {
36
- return dispatch ( { type : types . TOGGLE_LIKE_FAILURE } )
37
- } )
38
- }
25
+ return ( dispatch , getState ) => {
26
+ return api . toggleLike ( aid )
27
+ . then ( response => ( { json : response . data , status : response . statusText } ) )
28
+ . then ( ( { json, status} ) => {
29
+ if ( status !== 'OK' ) {
30
+ return dispatch ( { type : types . TOGGLE_LIKE_FAILURE } )
31
+ }
32
+ dispatch ( getUserInfo ( ) )
33
+ return dispatch ( receiveToggleLike ( json ) )
34
+ } )
35
+ . catch ( error => {
36
+ return dispatch ( { type : types . TOGGLE_LIKE_FAILURE } )
37
+ } )
38
+ }
39
39
}
40
40
41
41
/*获取文章列表*/
42
42
export const getArticleList = ( isAdd = true ) => {
43
- return ( dispatch , getState ) => {
44
- const options = getState ( ) . options . toJS ( )
45
- return dispatch ( {
46
- type : types . ARTICLE_LIST ,
47
- itemsPerPage : options . itemsPerPage ,
48
- promise : api . getArticleList ( options ) ,
49
- isAdd : isAdd
50
- } )
51
- }
43
+ return ( dispatch , getState ) => {
44
+ const options = getState ( ) . options . toJS ( )
45
+ return dispatch ( {
46
+ type : types . ARTICLE_LIST ,
47
+ itemsPerPage : options . itemsPerPage ,
48
+ promise : api . getArticleList ( options ) ,
49
+ isAdd : isAdd
50
+ } )
51
+ }
52
52
}
53
53
//获取文章详情
54
54
export const getArticleDetail = ( id ) => {
55
- return ( dispatch , getState ) => {
56
- const auth = getState ( ) . auth . toJS ( )
57
- return api . getArticleDetaile ( id )
58
- . then ( response => ( { json : response . data , status : response . statusText } ) )
59
- . then ( ( { json, status} ) => {
60
- let isLike = false
61
- let article = json . data
62
- if ( auth . user ) {
63
- auth . user . likes . map ( item => {
64
- if ( item . toString ( ) === article . _id ) {
65
- isLike = true
66
- }
67
- } )
68
- }
69
- return dispatch ( {
70
- type : types . ARTICLE_DETAIL_SUCCESS ,
71
- articleDetail : { ...article , isLike :isLike }
72
- } )
73
- } )
74
- . catch ( error => {
75
- return dispatch ( {
76
- type : types . ARTICLE_DETAIL_FAILURE
77
- } )
78
- } )
79
- }
55
+ return ( dispatch , getState ) => {
56
+ const auth = getState ( ) . auth . toJS ( )
57
+ return api . getArticleDetaile ( id )
58
+ . then ( response => ( { json : response . data , status : response . statusText } ) )
59
+ . then ( ( { json, status} ) => {
60
+ let isLike = false
61
+ let article = json . data
62
+ if ( auth . user ) {
63
+ auth . user . likes . map ( item => {
64
+ if ( item . toString ( ) === article . _id ) {
65
+ isLike = true
66
+ }
67
+ } )
68
+ }
69
+ return dispatch ( {
70
+ type : types . ARTICLE_DETAIL_SUCCESS ,
71
+ articleDetail : { ...article , isLike :isLike }
72
+ } )
73
+ } )
74
+ . catch ( error => {
75
+ return dispatch ( {
76
+ type : types . ARTICLE_DETAIL_FAILURE
77
+ } )
78
+ } )
79
+ }
80
80
}
81
81
82
82
//获取上下一篇文章
83
83
export const getPrenext = ( id ) => {
84
- return ( dispatch , getState ) => {
85
- const options = getState ( ) . options . toJS ( )
86
- return dispatch ( {
87
- type : types . PRENEXT_ARTICLE ,
88
- promise : api . getPrenext ( id , options )
89
- } )
90
- }
84
+ return ( dispatch , getState ) => {
85
+ const options = getState ( ) . options . toJS ( )
86
+ return dispatch ( {
87
+ type : types . PRENEXT_ARTICLE ,
88
+ promise : api . getPrenext ( id , options )
89
+ } )
90
+ }
91
91
}
0 commit comments