import React from 'react'; import NavigationActions from 'react-navigation'; import { ActivityIndicator, FlatList, NativeModules, SectionList, ScrollView, Text, View } from 'react-native'; import { buildURI, parseURI } from 'lbry-redux'; import { uriFromFileInfo } from 'utils/helper'; import AsyncStorage from '@react-native-community/async-storage'; import moment from 'moment'; import Button from 'component/button'; import Colors from 'styles/colors'; import Constants from 'constants'; import discoverStyle from 'styles/discover'; import subscriptionsStyle from 'styles/subscriptions'; import FloatingWalletBalance from 'component/floatingWalletBalance'; import FileItem from 'component/fileItem'; import Link from 'component/link'; import SuggestedSubscriptions from 'component/suggestedSubscriptions'; import UriBar from 'component/uriBar'; class SubscriptionsPage extends React.PureComponent { state = { showingSuggestedSubs: false }; componentWillMount() { const { doFetchMySubscriptions, doFetchRecommendedSubscriptions, pushDrawerStack, } = this.props; pushDrawerStack(); doFetchMySubscriptions(); doFetchRecommendedSubscriptions(); } componentDidMount() { const { doSetViewMode, subscriptionsViewMode } = this.props; doSetViewMode(subscriptionsViewMode ? subscriptionsViewMode : Constants.SUBSCRIPTIONS_VIEW_ALL); } changeViewMode = (viewMode) => { const { setClientSetting, doSetViewMode } = this.props; setClientSetting(Constants.SETTING_SUBSCRIPTIONS_VIEW_MODE, viewMode); doSetViewMode(viewMode); } render() { const { subscribedChannels, allSubscriptions, loading, viewMode, doSetViewMode, loadingSuggested, firstRunCompleted, doCompleteFirstRun, doShowSuggestedSubs, showSuggestedSubs, unreadSubscriptions, navigation, } = this.props; const numberOfSubscriptions = subscribedChannels ? subscribedChannels.length : 0; const hasSubscriptions = numberOfSubscriptions > 0; if (!hasSubscriptions && !this.state.showingSuggestedSubs) { this.setState({ showingSuggestedSubs: true }); } return ( {(!this.state.showingSuggestedSubs && hasSubscriptions && !loading) && this.changeViewMode(Constants.SUBSCRIPTIONS_VIEW_ALL)} /> this.changeViewMode(Constants.SUBSCRIPTIONS_VIEW_LATEST_FIRST)} /> } {(!this.state.showingSuggestedSubs && hasSubscriptions && !loading) && {(viewMode === Constants.SUBSCRIPTIONS_VIEW_ALL) && ( ) } data={allSubscriptions.sort((a, b) => { return b.height - a.height; })} keyExtractor={(item, index) => uriFromFileInfo(item)} />} {(viewMode === Constants.SUBSCRIPTIONS_VIEW_LATEST_FIRST) && {unreadSubscriptions.length ? ( {unreadSubscriptions.map(({ channel, uris }) => { const { claimName } = parseURI(channel); return uris.map(uri => ( )); })} ) : ( All caught up! You might like the channels below. ) } } } {(hasSubscriptions && loading) && } {this.state.showingSuggestedSubs && {!hasSubscriptions && You are not subscribed to any channels at the moment. Here are some channels that we think you might enjoy. } {hasSubscriptions && You are currently subscribed to {numberOfSubscriptions} channel{(numberOfSubscriptions > 1) ? 's' : ''}.