Skip to content

Commit 5c03288

Browse files
authored
Merge pull request #49 from funnyzak/feature/mytopics
2 parents af3a4cb + 0fab5a6 commit 5c03288

File tree

5 files changed

+88
-45
lines changed

5 files changed

+88
-45
lines changed

src/i18n/locales/zh.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
"noMoreData": "没有更多数据了。",
168168
"noMoreNotifications": "没有更多通知了。",
169169
"noPostTopics": "没有发布主题。",
170-
"needToLogin": "此功能需要登陆,要不登陆下?",
170+
"needToLogin": "需要登陆,还是登陆下吧?!",
171171
"seemsErrorAndTryAgain": "貌似产生了一个错误,重试下?!",
172172
"openLinkFailAndTryAgain": "载入失败,试着默认浏览器打开?!"
173173
},

src/screens/components/common/General.tsx

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
* Created by leon<[email protected]> on 22/04/06.
33
*/
44
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs'
5-
import { Text } from '@src/components'
5+
import { Placeholder, Text } from '@src/components'
66
import { useAppSelector } from '@src/hooks'
77
import { translate } from '@src/i18n'
88
import { NavigationService, ROUTES } from '@src/navigation'
9+
import { RootState } from '@src/store'
910
import { ITheme, useTheme } from '@src/theme'
10-
import { IState } from '@src/types'
11-
import React, { ComponentType } from 'react'
11+
import React, { ComponentType, useEffect } from 'react'
1212
import {
1313
Image,
1414
ImageSourcePropType,
@@ -116,7 +116,7 @@ const HeaderButton = ({
116116

117117
const Footer = () => {
118118
const { theme } = useTheme()
119-
const app = useAppSelector((_state: IState.State) => _state.app)
119+
const app = useAppSelector((_state: RootState) => _state.app)
120120

121121
return (
122122
<TouchableOpacity
@@ -134,6 +134,37 @@ const Footer = () => {
134134
)
135135
}
136136

137+
/**
138+
* Need Login
139+
* @returns
140+
*/
141+
const NeedLogin = ({ loginAfterAction, children }: { loginAfterAction?: () => void; children?: React.ReactNode }) => {
142+
const token = useAppSelector((_state: RootState) => _state.member.token)
143+
144+
useEffect(() => {
145+
if (token) {
146+
loginAfterAction && loginAfterAction()
147+
}
148+
}, [token])
149+
150+
return (
151+
<View style={{ flex: 1 }}>
152+
{!token ? (
153+
<Placeholder
154+
displayType="text"
155+
placeholderText={translate('placeholder.needToLogin')}
156+
buttonText={translate('label.goLogin')}
157+
buttonPress={() => {
158+
NavigationService.navigate(ROUTES.SignIn)
159+
}}
160+
/>
161+
) : (
162+
children
163+
)}
164+
</View>
165+
)
166+
}
167+
137168
export interface TopTabListProps {
138169
containerStyle?: StyleProp<ViewStyle>
139170
list?: {
@@ -256,4 +287,4 @@ const styles = {
256287
}
257288
}
258289

259-
export { TextWithIconPress, TopTabList, TextGrid, BorderLine, HeaderButton, Footer }
290+
export { TextWithIconPress, NeedLogin, TopTabList, TextGrid, BorderLine, HeaderButton, Footer }

src/screens/home/HotTopics.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { FetchTopicCardList } from '../components'
88
const HotTopics = ({ route, navigation }: ScreenProps) => {
99
const { theme } = useTheme()
1010
return (
11-
<View style={[SylCommon.Layout.fill, { backgroundColor: theme.colors.background }]}>
11+
<View style={SylCommon.Layout.fill}>
1212
<FetchTopicCardList displayStyle="full" nodeName={NODE_TABS.HOT} />
1313
</View>
1414
)

src/screens/my/History.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
import { HistoryScreenProps as ScreenProps } from '@src/navigation/routes'
2+
import { RootState } from '@src/store'
3+
import { SylCommon, useTheme } from '@src/theme'
4+
import { V2exObject } from '@src/types'
15
import React from 'react'
2-
import { connect } from 'react-redux'
36
import { View } from 'react-native'
4-
5-
import { TopicCardList } from '../components'
6-
import { useTheme, SylCommon } from '@src/theme'
7-
import { IState, V2exObject } from '@src/types'
8-
import { NotFound } from '../components'
9-
import { HistoryScreenProps as ScreenProps } from '@src/navigation/routes'
7+
import { connect } from 'react-redux'
8+
import { NotFound, TopicCardList } from '../components'
109

1110
const History = ({
1211
route,
@@ -27,7 +26,7 @@ const History = ({
2726
return <View style={[SylCommon.Layout.fill, SylCommon.View.background(theme)]}>{renderContent()}</View>
2827
}
2928

30-
const mapStateToProps = ({ member }: IState.State) => {
29+
const mapStateToProps = ({ member }: RootState) => {
3130
const { readedTopics } = member
3231
return {
3332
readedTopics

src/screens/my/Topics.tsx

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,53 @@
1-
import React, { useState } from 'react'
1+
import { useToast } from '@src/components'
2+
import { MyTopicsScreenProps as ScreenProps } from '@src/navigation'
3+
import { RootState } from '@src/store'
4+
import { SylCommon, useTheme } from '@src/theme'
5+
import { V2exObject } from '@src/types'
6+
import { v2exLib } from '@src/v2ex'
7+
import React, { useCallback, useState } from 'react'
8+
import { RefreshControl, View } from 'react-native'
29
import { connect } from 'react-redux'
3-
import { View, ViewStyle, TouchableOpacity } from 'react-native'
10+
import { NeedLogin, TopicCardList } from '../components'
411

5-
import * as Actions from '@src/actions'
6-
import { translate } from '@src/i18n'
7-
import { useTheme, SylCommon } from '@src/theme'
8-
import { IState, ITheme, V2exObject } from '@src/types'
9-
import * as CompS from '../components'
10-
import { Text, Spinner, Placeholder } from '@src/components'
11-
import { MyTopicsScreenProps as ScreenProps, ROUTES } from '@src/navigation'
12-
13-
const MyTopics = ({ route, navigation, loading }: ScreenProps) => {
12+
const MyTopics = ({
13+
profile
14+
}: ScreenProps & {
15+
profile?: V2exObject.Member
16+
}) => {
1417
const { theme } = useTheme()
18+
const [refreshing, setRefreshing] = useState<boolean>(false)
19+
const [list, setList] = useState<V2exObject.Topic[] | undefined>(undefined)
20+
const { showMessage } = useToast()
21+
22+
const onRefresh = useCallback(() => {
23+
setRefreshing(true)
24+
if (!profile) return
25+
26+
v2exLib.topic
27+
.topics(profile?.username, 'username')
28+
.then((rlt: V2exObject.Topic[]) => {
29+
setRefreshing(false)
30+
setList(rlt)
31+
})
32+
.catch((err) => {
33+
showMessage(err.message)
34+
})
35+
}, [])
36+
1537
return (
16-
<View style={[SylCommon.Layout.fill, SylCommon.View.background(theme)]}>
17-
<Placeholder
18-
displayType="icon"
19-
icon={theme.assets.images.icons.placeholder.construction}
20-
placeholderText={translate(`router.${ROUTES.MyTopics}`) + translate('label.underConstruction')}
38+
<NeedLogin loginAfterAction={onRefresh}>
39+
<TopicCardList
40+
topics={list}
41+
displayStyle={'full'}
42+
refreshControl={<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />}
43+
canLoadMoreContent={false}
44+
searchIndicator={false}
45+
refreshCallback={onRefresh}
2146
/>
22-
</View>
47+
</NeedLogin>
2348
)
2449
}
2550

26-
/**
27-
* @description styles settings
28-
*/
29-
const styles = {
30-
container: (theme: ITheme): ViewStyle => ({
31-
flex: 1
32-
})
33-
}
34-
35-
const mapStateToProps = ({ ui: { login } }: { ui: IState.UIState }) => {
36-
const { error, success, loading } = login
37-
return { error, success, loading }
38-
}
51+
const mapStateToProps = ({ member: { profile } }: RootState) => ({ profile })
3952

4053
export default connect(mapStateToProps)(MyTopics)

0 commit comments

Comments
 (0)