|
1 | | -import { useNode } from '@src/hooks/useNode' |
| 1 | +/** |
| 2 | + * Created by leon<[email protected]> on 22/04/30. |
| 3 | + */ |
| 4 | +import { interestNode, unInterestNode } from '@src/actions' |
2 | 5 | import { NodeDetailScreenProps as ScreenProps } from '@src/navigation/routes' |
| 6 | +import { RootState } from '@src/store' |
3 | 7 | import { SylCommon, useTheme } from '@src/theme' |
4 | | -import React, { useEffect } from 'react' |
| 8 | +import { V2exObject } from '@src/types' |
| 9 | +import React, { useEffect, useMemo, useState } from 'react' |
5 | 10 | import { View } from 'react-native' |
6 | 11 | import { connect } from 'react-redux' |
7 | 12 | import { NodeInfoCard, NodeTopicTabList } from '../components' |
| 13 | +import { LikeNodeHeaderButton } from '../components/button' |
8 | 14 |
|
9 | | -const NodeDetail = ({ route, navigation }: ScreenProps) => { |
| 15 | +const NodeDetail = ({ |
| 16 | + interestNodes, |
| 17 | + route, |
| 18 | + navigation |
| 19 | +}: ScreenProps & { |
| 20 | + interestNodes: V2exObject.Node[] |
| 21 | +}) => { |
10 | 22 | const { theme } = useTheme() |
| 23 | + const nodeName = useMemo(() => route.params.nodeName, [route]) |
| 24 | + const [info, setInfo] = useState<V2exObject.Node | undefined>(undefined) |
| 25 | + |
| 26 | + const HeaderRight = () => () => { |
| 27 | + return !info ? undefined : <LikeNodeHeaderButton node={info} /> |
| 28 | + } |
| 29 | + |
11 | 30 | useEffect(() => { |
12 | 31 | navigation.setOptions({ |
13 | | - title: route.params.nodeTitle |
| 32 | + title: route.params.nodeTitle, |
| 33 | + headerRight: HeaderRight() |
14 | 34 | }) |
15 | | - }, []) |
| 35 | + }, [interestNodes, info]) |
16 | 36 |
|
17 | 37 | return ( |
18 | 38 | <View style={SylCommon.Layout.fill}> |
19 | | - <NodeInfoCard nodeid={route.params.nodeName} /> |
20 | | - <NodeTopicTabList nodename={route.params.nodeName} containerStyle={[{ marginTop: theme.spacing.small }]} /> |
| 39 | + <NodeInfoCard nodeid={nodeName} loadedCallback={setInfo} /> |
| 40 | + <NodeTopicTabList nodename={nodeName} containerStyle={[{ marginTop: theme.spacing.small }]} /> |
21 | 41 | </View> |
22 | 42 | ) |
23 | 43 | } |
24 | 44 |
|
25 | | -export default connect()(NodeDetail) |
| 45 | +const mapStateToProps = ({ member: { interestNodes } }: RootState) => { |
| 46 | + return { interestNodes } |
| 47 | +} |
| 48 | + |
| 49 | +export default connect(mapStateToProps, {})(NodeDetail) |
0 commit comments