|
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' |
2 | 9 | import { connect } from 'react-redux' |
3 | | -import { View, ViewStyle, TouchableOpacity } from 'react-native' |
| 10 | +import { NeedLogin, TopicCardList } from '../components' |
4 | 11 |
|
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 | +}) => { |
14 | 17 | 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 | + |
15 | 37 | 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} |
21 | 46 | /> |
22 | | - </View> |
| 47 | + </NeedLogin> |
23 | 48 | ) |
24 | 49 | } |
25 | 50 |
|
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 }) |
39 | 52 |
|
40 | 53 | export default connect(mapStateToProps)(MyTopics) |
0 commit comments