// @flow
import React from 'react';
import { ActivityIndicator, Dimensions, Image, ScrollView, Text, TouchableOpacity, View } from 'react-native';
import { TabView, SceneMap } from 'react-native-tab-view';
import { navigateBack } from 'utils/helper';
import Colors from 'styles/colors';
import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api
import Button from 'component/button';
import Link from 'component/link';
import FileList from 'component/fileList';
import PageHeader from 'component/pageHeader';
import SubscribeButton from 'component/subscribeButton';
import SubscribeNotificationButton from 'component/subscribeNotificationButton';
import UriBar from 'component/uriBar';
import channelPageStyle from 'styles/channelPage';
class ChannelPage extends React.PureComponent {
state = {
page: 1,
showPageButtons: false,
activeTab: Constants.CONTENT_TAB,
};
componentDidMount() {
const { uri, page, claimsInChannel, fetchClaims, fetchClaimCount } = this.props;
if (!claimsInChannel || !claimsInChannel.length) {
fetchClaims(uri, page || this.state.page);
}
}
handlePreviousPage = () => {
const { uri, fetchClaims } = this.props;
if (this.state.page > 1) {
this.setState({ page: this.state.page - 1, showPageButtons: false }, () => {
fetchClaims(uri, this.state.page);
});
}
};
handleNextPage = () => {
const { uri, fetchClaims, totalPages } = this.props;
if (this.state.page < totalPages) {
this.setState({ page: this.state.page + 1, showPageButtons: false }, () => {
fetchClaims(uri, this.state.page);
});
}
};
renderContent = () => {
const { fetching, claimsInChannel, totalPages, navigation } = this.props;
let contentList;
if (fetching) {
contentList = (
Fetching content...
);
} else {
contentList =
claimsInChannel && claimsInChannel.length ? (
this.setState({ showPageButtons: true })}
/>
) : (
No content found.
);
}
let pageButtons;
if (totalPages > 1 && this.state.showPageButtons) {
pageButtons = (
{this.state.page > 1 && (
)}
{this.state.page < totalPages && (
)}
);
}
return (
{contentList}
{pageButtons}
);
};
renderAbout = () => {
const { claim } = this.props;
if (!claim) {
return (
No information to display.
);
}
const { cover, description, thumbnail, email, website_url: websiteUrl, title } = claim.value;
return (
{!websiteUrl && !email && !description && (
Nothing here yet. Please check back later.
)}
{(websiteUrl || email || description) && (
{websiteUrl && websiteUrl.trim().length > 0 && (
Website
)}
{email && email.trim().length > 0 && (
Email
)}
{description && description.trim().length > 0 && (
{description}
)}
)}
);
};
render() {
const { fetching, claimsInChannel, claim, navigation, totalPages, uri, drawerStack, popDrawerStack } = this.props;
const { name, permanent_url: permanentUrl } = claim;
let thumbnailUrl, coverUrl, title;
if (claim && claim.value) {
title = claim.value.title;
if (claim.value.cover) {
coverUrl = claim.value.cover.url;
}
if (claim.value.thumbnail) {
thumbnailUrl = claim.value.thumbnail.url;
}
}
return (
0
? { uri: coverUrl }
: require('../../assets/default_channel_cover.png')
}
/>
{title && title.trim().length > 0 ? title : name}
0
? { uri: thumbnailUrl }
: require('../../assets/default_avatar.jpg')
}
/>
this.setState({ activeTab: Constants.CONTENT_TAB })}
>
CONTENT
{Constants.CONTENT_TAB === this.state.activeTab && }
this.setState({ activeTab: Constants.ABOUT_TAB })}
>
ABOUT
{Constants.ABOUT_TAB === this.state.activeTab && }
{Constants.CONTENT_TAB === this.state.activeTab && this.renderContent()}
{Constants.ABOUT_TAB === this.state.activeTab && this.renderAbout()}
);
}
}
export default ChannelPage;