2
2
import React , { PureComponent } from 'react' ;
3
3
import { FlatList , StyleSheet } from 'react-native' ;
4
4
5
- import type { TopicDetails } from '../types' ;
5
+ import type { Actions , Stream , TopicDetails } from '../types' ;
6
+ import connectWithActions from '../connectWithActions' ;
7
+ import { getStreamEditInitialValues } from '../subscriptions/subscriptionSelectors' ;
8
+ import { topicNarrow } from '../utils/narrow' ;
9
+ import { getTopicsInScreen } from '../selectors' ;
6
10
import TopicItem from '../streams/TopicItem' ;
7
11
import { LoadingIndicator , SectionSeparatorBetween , SearchEmptyState } from '../common' ;
8
12
@@ -14,22 +18,33 @@ const styles = StyleSheet.create({
14
18
} ) ;
15
19
16
20
type Props = {
17
- topics : ?( TopicDetails [ ] ) ,
18
- onPress : ( stream : string , topic : string ) => void ,
21
+ actions : Actions ,
22
+ stream : Stream ,
23
+ topics : TopicDetails [ ] ,
19
24
} ;
20
25
21
- export default class TopicList extends PureComponent < Props > {
26
+ class TopicList extends PureComponent < Props > {
22
27
props : Props ;
23
28
29
+ componentDidMount ( ) {
30
+ const { actions, stream } = this . props ;
31
+ actions . fetchTopics ( stream . stream_id ) ;
32
+ }
33
+
24
34
static defaultProps = {
25
35
showDescriptions : false ,
26
36
showSwitch : false ,
27
37
selected : false ,
28
38
streams : [ ] ,
29
39
} ;
30
40
41
+ handlePress = ( streamObj : string , topic : string ) => {
42
+ const { actions, stream } = this . props ;
43
+ actions . doNarrow ( topicNarrow ( stream . name , topic ) ) ;
44
+ } ;
45
+
31
46
render ( ) {
32
- const { topics, onPress } = this . props ;
47
+ const { topics } = this . props ;
33
48
34
49
if ( ! topics ) {
35
50
return < LoadingIndicator size = { 40 } /> ;
@@ -45,10 +60,15 @@ export default class TopicList extends PureComponent<Props> {
45
60
data = { topics }
46
61
keyExtractor = { item => item . name }
47
62
renderItem = { ( { item } ) => (
48
- < TopicItem name = { item . name } isMuted = { false } unreadCount = { 0 } onPress = { onPress } />
63
+ < TopicItem name = { item . name } isMuted = { false } unreadCount = { 0 } onPress = { this . handlePress } />
49
64
) }
50
65
SectionSeparatorComponent = { SectionSeparatorBetween }
51
66
/>
52
67
) ;
53
68
}
54
69
}
70
+
71
+ export default connectWithActions ( state => ( {
72
+ stream : getStreamEditInitialValues ( state ) ,
73
+ topics : getTopicsInScreen ( state ) ,
74
+ } ) ) ( TopicList ) ;
0 commit comments