Skip to content

topics: Fix failure to load from offline state. #2326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);