Skip to content

Commit

Permalink
topics: Fix failure to load from offline state.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
codebu5ter committed Apr 16, 2018
1 parent 95676a3 commit e069bf1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/streams/TopicItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Props = {
isMuted: boolean,
isSelected: boolean,
unreadCount: number,
onPress: (topic: string, stream: string) => void,
onPress: (stream: string, topic: string) => void,
};

export default class StreamItem extends PureComponent<Props> {
Expand Down
32 changes: 26 additions & 6 deletions src/topics/TopicList.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
import React, { PureComponent } from 'react';
import { FlatList, StyleSheet } from 'react-native';

import type { TopicDetails } from '../types';
import type { Actions, Stream, TopicDetails } from '../types';
import connectWithActions from '../connectWithActions';
import { getStreamEditInitialValues } from '../subscriptions/subscriptionSelectors';
import { topicNarrow } from '../utils/narrow';
import { getTopicsInScreen } from '../selectors';
import TopicItem from '../streams/TopicItem';
import { LoadingIndicator, SectionSeparatorBetween, SearchEmptyState } from '../common';

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

type Props = {
topics: ?(TopicDetails[]),
onPress: (stream: string, topic: string) => void,
actions: Actions,
stream: Stream,
topics: TopicDetails[],
};

export default class TopicList extends PureComponent<Props> {
class TopicList extends PureComponent<Props> {
props: Props;

componentDidMount() {
const { actions, stream } = this.props;
actions.fetchTopics(stream.stream_id);
}

static defaultProps = {
showDescriptions: false,
showSwitch: false,
selected: false,
streams: [],
};

handlePress = (streamObj: string, topic: string) => {
const { actions, stream } = this.props;
actions.doNarrow(topicNarrow(stream.name, topic));
};

render() {
const { topics, onPress } = this.props;
const { topics } = this.props;

if (!topics) {
return <LoadingIndicator size={40} />;
Expand All @@ -45,10 +60,15 @@ export default class TopicList extends PureComponent<Props> {
data={topics}
keyExtractor={item => item.name}
renderItem={({ item }) => (
<TopicItem name={item.name} isMuted={false} unreadCount={0} onPress={onPress} />
<TopicItem name={item.name} isMuted={false} unreadCount={0} onPress={this.handlePress} />
)}
SectionSeparatorComponent={SectionSeparatorBetween}
/>
);
}
}

export default connectWithActions(state => ({
stream: getStreamEditInitialValues(state),
topics: getTopicsInScreen(state),
}))(TopicList);
28 changes: 6 additions & 22 deletions src/topics/TopicListScreen.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,29 @@
/* @flow */
import React, { PureComponent } from 'react';

import type { Actions, Stream, TopicDetails } from '../types';
import connectWithActions from '../connectWithActions';
import { Screen } from '../common';
import { topicNarrow } from '../utils/narrow';
import { getTopicsInScreen } from '../selectors';
import { getStreamEditInitialValues } from '../subscriptions/subscriptionSelectors';
import { LoadingIndicator, Screen } from '../common';
import { getSession } from '../selectors';
import TopicList from './TopicList';

type Props = {
actions: Actions,
stream: Stream,
topics: TopicDetails[],
isOnline: boolean,
};

class TopicListScreen extends PureComponent<Props> {
props: Props;

componentDidMount() {
const { actions, stream } = this.props;
actions.fetchTopics(stream.stream_id);
}

handlePress = (streamObj: string, topic: string) => {
const { actions, stream } = this.props;
actions.doNarrow(topicNarrow(stream.name, topic));
};

render() {
const { topics } = this.props;
const { isOnline } = this.props;

return (
<Screen title="Topics" padding>
<TopicList topics={topics} onPress={this.handlePress} />
{isOnline ? <TopicList /> : <LoadingIndicator size={40} />}
</Screen>
);
}
}

export default connectWithActions(state => ({
stream: getStreamEditInitialValues(state),
topics: getTopicsInScreen(state),
isOnline: getSession(state).isOnline,
}))(TopicListScreen);

0 comments on commit e069bf1

Please sign in to comment.