Skip to content

Commit 3c405b9

Browse files
authored
Merge pull request #58 from funnyzak/feature/interestnode
2 parents 9efb974 + 6b0c5e8 commit 3c405b9

File tree

12 files changed

+196
-68
lines changed

12 files changed

+196
-68
lines changed

src/actions/CacheAction.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import { v2exLib } from '@src/v2ex'
88
import {
99
APP_CACHE_ADD_MEMBER,
1010
APP_CACHE_ADD_NODE,
11+
APP_CACHE_MEMBER_FOLLOWING,
12+
APP_CACHE_MEMBER_INTEREST_NODES,
1113
APP_CACHE_RESET,
1214
APP_CACHE_RESET_MEMBERS,
13-
APP_CACHE_RESET_NODES
15+
APP_CACHE_RESET_NODES,
16+
V2exObject
1417
} from '../types'
1518

1619
export const cacheMember = (userid: string | number) => async (dispatch: AppDispatch) => {
@@ -37,6 +40,16 @@ export const cacheNode = (nodeid: string | number) => async (dispatch: AppDispat
3740
}
3841
}
3942

43+
export const cacheMemberFollowing = (members: V2exObject.Member[] | undefined) => ({
44+
type: APP_CACHE_MEMBER_FOLLOWING,
45+
payload: members
46+
})
47+
48+
export const cacheMemberInterestNodes = (nodes: V2exObject.Node[] | undefined) => ({
49+
type: APP_CACHE_MEMBER_INTEREST_NODES,
50+
payload: nodes
51+
})
52+
4053
export const resetCache = (type: 'all' | 'nodes' | 'members') => ({
4154
type: type === 'nodes' ? APP_CACHE_RESET_NODES : type === 'members' ? APP_CACHE_RESET_MEMBERS : APP_CACHE_RESET
4255
})

src/actions/MemberActions.ts

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,42 @@
22
* Created by leon<[email protected]> on 22/2/22.
33
*/
44
import AsyncStorage from '@react-native-async-storage/async-storage'
5+
import { MEMBER_TOKEN_KEY } from '@src/config/constants'
6+
import { logError } from '@src/helper/logger'
7+
import NavigationService from '@src/navigation/NavigationService'
8+
import { RootState } from '@src/store'
9+
import { v2exLib } from '@src/v2ex'
510
import { Dispatch } from 'redux'
611
import {
7-
MEMBER_PROFILE,
812
APP_AUTH,
9-
APP_AUTH_LOADING,
10-
APP_LOGOUT,
1113
APP_AUTH_ERROR,
14+
APP_AUTH_LOADING,
1215
APP_AUTH_SUCCESS,
13-
V2exObject,
14-
MEMBER_TOPICS,
16+
APP_LOGOUT,
1517
MEMBER_INSEREST_NODE,
16-
MEMBER_UNINTEREST_NODE
18+
MEMBER_PROFILE,
19+
MEMBER_SATE_SETTING,
20+
MEMBER_TOPICS,
21+
MEMBER_UNINTEREST_NODE,
22+
V2exObject
1723
} from '../types'
18-
import { v2exLib } from '@src/v2ex'
19-
import { logError } from '@src/helper/logger'
20-
import NavigationService from '@src/navigation/NavigationService'
21-
import { MEMBER_TOKEN_KEY } from '@src/config/constants'
24+
import { cacheMemberInterestNodes } from './CacheAction'
2225

23-
export const myProfile = () => async (dispatch: Dispatch) => {
26+
export const myProfile = () => async (dispatch: Dispatch, getState: () => RootState) => {
2427
const _member = await v2exLib.member.myProfile()
2528

2629
dispatch({
2730
type: MEMBER_PROFILE,
2831
payload: _member
2932
})
33+
34+
dispatch({
35+
type: MEMBER_SATE_SETTING,
36+
payload: {
37+
interestNodes: getState().cache.membersInterestNodes[_member.id],
38+
followPeoples: getState().cache.membersFollowing[_member.id]
39+
}
40+
})
3041
}
3142

3243
export const getToken = () => async (dispatch: Dispatch) => {
@@ -41,15 +52,21 @@ export const setMyTopics = (topics: V2exObject.Topic[]) => ({
4152
payload: topics
4253
})
4354

44-
export const interestNode = (node: V2exObject.Node) => ({
45-
type: MEMBER_INSEREST_NODE,
46-
payload: node
47-
})
55+
export const interestNode = (node: V2exObject.Node) => async (dispatch: Dispatch, getState: () => RootState) => {
56+
dispatch({
57+
type: MEMBER_INSEREST_NODE,
58+
payload: node
59+
})
60+
dispatch(cacheMemberInterestNodes(getState().member.interestNodes))
61+
}
4862

49-
export const unInterestNode = (node: V2exObject.Node) => ({
50-
type: MEMBER_UNINTEREST_NODE,
51-
payload: node
52-
})
63+
export const unInterestNode = (node: V2exObject.Node) => async (dispatch: Dispatch, getState: () => RootState) => {
64+
dispatch({
65+
type: MEMBER_UNINTEREST_NODE,
66+
payload: node
67+
})
68+
dispatch(cacheMemberInterestNodes(getState().member.interestNodes))
69+
}
5370

5471
export const setCurrentToken = (token?: V2exObject.MToken) => ({
5572
type: APP_AUTH,
@@ -60,14 +77,14 @@ export const loginByToken = (token: string) => async (dispatch: Dispatch) => {
6077
try {
6178
dispatch({ type: APP_AUTH_LOADING })
6279
const token_info = await v2exLib.member.token(token)
63-
loginByTokenSuccess(dispatch, token_info)
80+
dispatch(loginByTokenSuccess(token_info) as any)
6481
} catch (e: any) {
6582
logError(e)
6683
loginByTokenFail(dispatch, e.message)
6784
}
6885
}
6986

70-
const loginByTokenSuccess = async (dispatch: Dispatch, token: V2exObject.MToken) => {
87+
const loginByTokenSuccess = (token: V2exObject.MToken) => async (dispatch: Dispatch, getState: () => RootState) => {
7188
await AsyncStorage.setItem(MEMBER_TOKEN_KEY, token.token)
7289

7390
v2exLib.setToken(token.token)

src/actions/RestActions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import { MEMBER_TOKEN_KEY } from '@src/config/constants'
88
import { APP_INIT, APP_SITE_STAT, APP_INIT_ERROR, APP_SITE_INFO, APP_ALL_NODE_INFO, IState } from '../types'
99
import { logError } from '@src/helper/logger'
1010
import DeviceInfo from 'react-native-device-info'
11+
import { RootState } from '@src/store'
1112

1213
export const initV2ex = () => {
1314
v2exLib.setOptions(v2exOptions)
1415

15-
return async (dispatch: Dispatch, _getState: () => IState.AppState) => {
16+
return async (dispatch: Dispatch, _getState: () => RootState) => {
1617
try {
1718
v2exLib.init()
1819

src/actions/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const MEMBER_READ_TOPIC = 'read_topic'
2323
export const MEMBER_TOPICS = 'member_topics'
2424
export const MEMBER_INSEREST_NODE = 'member_interest_node'
2525
export const MEMBER_UNINTEREST_NODE = 'member_uninterest_node'
26+
export const MEMBER_SATE_SETTING = 'member_state_setting'
2627

2728
export const FEEDBACKING = 'feedbacking'
2829
export const FEEDBACK_DONE = 'feedback_done'
@@ -45,14 +46,19 @@ export const APP_NODE_LOAD_ERROR = 'v2ex_node_error'
4546

4647
export const APP_CACHE_ADD_MEMBER = 'v2ex_cache_add_member'
4748
export const APP_CACHE_ADD_NODE = 'v2ex_cache_add_node'
49+
export const APP_CACHE_MEMBER_INTEREST_NODES = 'v2ex_cache_member_interest_nodes'
50+
export const APP_CACHE_MEMBER_FOLLOWING = 'v2ex_cache_member_following'
4851
export const APP_CACHE_RESET_MEMBERS = 'v2ex_cache_reset_member'
4952
export const APP_CACHE_RESET_NODES = 'v2ex_cache_reset_node'
5053
export const APP_CACHE_RESET = 'v2ex_cache_reset'
5154

5255
export const ActionTypes = {
5356
MEMBER_INSEREST_NODE,
57+
APP_CACHE_MEMBER_INTEREST_NODES,
5458
MEMBER_UNINTEREST_NODE,
59+
APP_CACHE_MEMBER_FOLLOWING,
5560
MEMBER_TOPICS,
61+
MEMBER_SATE_SETTING,
5662
APP_CACHE_RESET,
5763
APP_CACHE_RESET_MEMBERS,
5864
APP_CACHE_RESET_NODES,

src/i18n/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
"noTopics": "No Topics.",
157157
"noReplies": "No Replies.",
158158
"noNodes": "No Nodes.",
159+
"noInterestNodes": "No interest node yet.",
159160
"noData": "No Data.",
160161
"noUser": "No User.",
161162
"noNode": "No Node.",

src/i18n/locales/zh.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
"noTopics": "还没有任何主题.",
157157
"noReplies": "还没有任何回复.",
158158
"noNodes": "还没有任何节点.",
159+
"noInterestNodes": "还没有收藏节点.",
159160
"noData": "没有数据",
160161
"noUser": "用户不存在",
161162
"noNode": "节点不存在",

src/reducers/CacheReducer.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,29 @@ import {
22
Action,
33
APP_CACHE_ADD_MEMBER,
44
APP_CACHE_ADD_NODE,
5+
APP_CACHE_MEMBER_FOLLOWING,
6+
APP_CACHE_MEMBER_INTEREST_NODES,
57
APP_CACHE_RESET,
68
APP_CACHE_RESET_MEMBERS,
79
APP_CACHE_RESET_NODES,
8-
IState
10+
APP_LOGOUT,
11+
IState,
12+
MEMBER_PROFILE
913
} from '../types'
1014

1115
const INITIAL_STATE: IState.CacheState = {
1216
members: [],
13-
nodes: []
17+
nodes: [],
18+
membersFollowing: { 0: undefined },
19+
membersInterestNodes: { 0: undefined }
1420
}
1521

1622
export default (state: IState.CacheState = INITIAL_STATE, action: Action): IState.CacheState => {
1723
switch (action.type) {
24+
case MEMBER_PROFILE:
25+
return { ...state, currentSessionMember: action.payload }
26+
case APP_LOGOUT:
27+
return { ...state, currentSessionMember: undefined }
1828
case APP_CACHE_ADD_MEMBER:
1929
const members = state.members
2030
.filter((v) => v.info.id !== action.payload.id)
@@ -25,6 +35,12 @@ export default (state: IState.CacheState = INITIAL_STATE, action: Action): IStat
2535
.filter((v) => v.info.name !== action.payload.name)
2636
.concat([{ pullTime: new Date().getTime(), info: action.payload }])
2737
return { ...state, nodes }
38+
case APP_CACHE_MEMBER_INTEREST_NODES:
39+
state.membersInterestNodes[state.currentSessionMember?.id ?? 0] = action.payload
40+
return { ...state }
41+
case APP_CACHE_MEMBER_FOLLOWING:
42+
state.membersFollowing[state.currentSessionMember?.id ?? 0] = action.payload
43+
return { ...state }
2844
case APP_CACHE_RESET_MEMBERS:
2945
return { ...state, members: [] }
3046
case APP_CACHE_RESET_NODES:

src/reducers/MemberReducer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
MEMBER_READ_TOPIC,
99
MEMBER_TOPICS,
1010
MEMBER_INSEREST_NODE,
11-
MEMBER_UNINTEREST_NODE
11+
MEMBER_UNINTEREST_NODE,
12+
MEMBER_SATE_SETTING
1213
} from '../types'
1314
const INITIAL_STATE: IState.MemberState = {
1415
refreshing: false,
@@ -29,6 +30,8 @@ export default (state: IState.MemberState = INITIAL_STATE, action: Action): ISta
2930
...state,
3031
interestNodes: state.interestNodes.filter((v) => v.id !== action.payload.id)
3132
}
33+
case MEMBER_SATE_SETTING:
34+
return { ...state, ...action.payload }
3235
case MEMBER_TOPICS:
3336
return { ...state, topics: action.payload }
3437
case APP_AUTH:

src/screens/components/button/header/LikeNode.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ const LikeNodeHeaderButton = ({
4242
NavigationService.navigate(ROUTES.SignIn)
4343
} else {
4444
if (isInterest) {
45-
dispatch(unInterestNode(node))
45+
dispatch(unInterestNode(node) as any)
4646
} else {
47-
dispatch(interestNode(node))
47+
dispatch(interestNode(node) as any)
4848
}
4949
}
5050
}

src/screens/login/SignIn.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ const styles = {
163163
flex: 1,
164164
width: theme.dimens.defaultButtonWidth,
165165
backgroundColor: theme.colors.transparent,
166-
paddingTop: theme.dimens.WINDOW_HEIGHT / 5,
166+
paddingTop: theme.dimens.WINDOW_HEIGHT / 3,
167167
alignSelf: 'center',
168168
flexDirection: 'column',
169169
justifyContent: 'flex-start',
@@ -199,7 +199,7 @@ const styles = {
199199
}),
200200
footer: (theme: ITheme): ViewStyle => ({
201201
width: '80%',
202-
marginBottom: theme.spacing.medium,
202+
marginBottom: theme.spacing.large,
203203
flexDirection: 'row',
204204
alignItems: 'center',
205205
justifyContent: 'center',

0 commit comments

Comments
 (0)