Skip to content

Commit e069bf1

Browse files
committed
topics: Fix failure to load from offline state.
This fix first checks for the online status in TopicListScreen, and if found to be online, renders TopicList, which houses all the Redux logic and the call to Selectors that were originally in TopicListScreen. Fixes zulip#2310
1 parent 95676a3 commit e069bf1

File tree

3 files changed

+33
-29
lines changed

3 files changed

+33
-29
lines changed

src/streams/TopicItem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type Props = {
3232
isMuted: boolean,
3333
isSelected: boolean,
3434
unreadCount: number,
35-
onPress: (topic: string, stream: string) => void,
35+
onPress: (stream: string, topic: string) => void,
3636
};
3737

3838
export default class StreamItem extends PureComponent<Props> {

src/topics/TopicList.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
import React, { PureComponent } from 'react';
33
import { FlatList, StyleSheet } from 'react-native';
44

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';
610
import TopicItem from '../streams/TopicItem';
711
import { LoadingIndicator, SectionSeparatorBetween, SearchEmptyState } from '../common';
812

@@ -14,22 +18,33 @@ const styles = StyleSheet.create({
1418
});
1519

1620
type Props = {
17-
topics: ?(TopicDetails[]),
18-
onPress: (stream: string, topic: string) => void,
21+
actions: Actions,
22+
stream: Stream,
23+
topics: TopicDetails[],
1924
};
2025

21-
export default class TopicList extends PureComponent<Props> {
26+
class TopicList extends PureComponent<Props> {
2227
props: Props;
2328

29+
componentDidMount() {
30+
const { actions, stream } = this.props;
31+
actions.fetchTopics(stream.stream_id);
32+
}
33+
2434
static defaultProps = {
2535
showDescriptions: false,
2636
showSwitch: false,
2737
selected: false,
2838
streams: [],
2939
};
3040

41+
handlePress = (streamObj: string, topic: string) => {
42+
const { actions, stream } = this.props;
43+
actions.doNarrow(topicNarrow(stream.name, topic));
44+
};
45+
3146
render() {
32-
const { topics, onPress } = this.props;
47+
const { topics } = this.props;
3348

3449
if (!topics) {
3550
return <LoadingIndicator size={40} />;
@@ -45,10 +60,15 @@ export default class TopicList extends PureComponent<Props> {
4560
data={topics}
4661
keyExtractor={item => item.name}
4762
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} />
4964
)}
5065
SectionSeparatorComponent={SectionSeparatorBetween}
5166
/>
5267
);
5368
}
5469
}
70+
71+
export default connectWithActions(state => ({
72+
stream: getStreamEditInitialValues(state),
73+
topics: getTopicsInScreen(state),
74+
}))(TopicList);

src/topics/TopicListScreen.js

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,29 @@
11
/* @flow */
22
import React, { PureComponent } from 'react';
33

4-
import type { Actions, Stream, TopicDetails } from '../types';
54
import connectWithActions from '../connectWithActions';
6-
import { Screen } from '../common';
7-
import { topicNarrow } from '../utils/narrow';
8-
import { getTopicsInScreen } from '../selectors';
9-
import { getStreamEditInitialValues } from '../subscriptions/subscriptionSelectors';
5+
import { LoadingIndicator, Screen } from '../common';
6+
import { getSession } from '../selectors';
107
import TopicList from './TopicList';
118

129
type Props = {
13-
actions: Actions,
14-
stream: Stream,
15-
topics: TopicDetails[],
10+
isOnline: boolean,
1611
};
1712

1813
class TopicListScreen extends PureComponent<Props> {
1914
props: Props;
2015

21-
componentDidMount() {
22-
const { actions, stream } = this.props;
23-
actions.fetchTopics(stream.stream_id);
24-
}
25-
26-
handlePress = (streamObj: string, topic: string) => {
27-
const { actions, stream } = this.props;
28-
actions.doNarrow(topicNarrow(stream.name, topic));
29-
};
30-
3116
render() {
32-
const { topics } = this.props;
17+
const { isOnline } = this.props;
3318

3419
return (
3520
<Screen title="Topics" padding>
36-
<TopicList topics={topics} onPress={this.handlePress} />
21+
{isOnline ? <TopicList /> : <LoadingIndicator size={40} />}
3722
</Screen>
3823
);
3924
}
4025
}
4126

4227
export default connectWithActions(state => ({
43-
stream: getStreamEditInitialValues(state),
44-
topics: getTopicsInScreen(state),
28+
isOnline: getSession(state).isOnline,
4529
}))(TopicListScreen);

0 commit comments

Comments
 (0)