// @flow import React from 'react'; import { ActivityIndicator, Alert, Dimensions, Image, NativeModules, ScrollView, Text, TouchableOpacity, View, } from 'react-native'; import { TabView, SceneMap } from 'react-native-tab-view'; import { normalizeURI } from 'lbry-redux'; import { navigateBack, getOrderBy } from 'utils/helper'; import ChannelIconItem from 'component/channelIconItem'; import ClaimList from 'component/claimList'; import Colors from 'styles/colors'; import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api import Button from 'component/button'; import EmptyStateView from 'component/emptyStateView'; import Icon from 'react-native-vector-icons/FontAwesome5'; import Link from 'component/link'; import ModalPicker from 'component/modalPicker'; import PageHeader from 'component/pageHeader'; import SubscribeButton from 'component/subscribeButton'; import SubscribeNotificationButton from 'component/subscribeNotificationButton'; import UriBar from 'component/uriBar'; import channelIconStyle from 'styles/channelIcon'; import channelPageStyle from 'styles/channelPage'; import discoverStyle from 'styles/discover'; class ChannelPage extends React.PureComponent { state = { autoStyle: null, showSortPicker: false, showTimePicker: false, orderBy: Constants.DEFAULT_ORDER_BY, activeTab: Constants.CONTENT_TAB, }; componentWillMount() { this.setState({ autoStyle: ChannelIconItem.AUTO_THUMB_STYLES[Math.floor(Math.random() * ChannelIconItem.AUTO_THUMB_STYLES.length)], }); } componentDidMount() { const { fetchChannelListMine } = this.props; NativeModules.Firebase.setCurrentScreen('Channel'); fetchChannelListMine(); } handleSortByItemSelected = item => { const { setSortByItem } = this.props; setSortByItem(item); this.setState({ orderBy: getOrderBy(item), showSortPicker: false }); }; handleTimeItemSelected = item => { const { setTimeItem } = this.props; setTimeItem(item); this.setState({ showTimePicker: false }); }; listHeader = () => { const { sortByItem, timeItem } = this.props; return ( this.setState({ showSortPicker: true })}> {sortByItem.label.split(' ')[0]} {Constants.SORT_BY_TOP === sortByItem.name && ( this.setState({ showTimePicker: true })}> {timeItem.label} )} ); }; renderContent = () => { const { claim, navigation, timeItem } = this.props; let channelId; if (claim) { channelId = claim.claim_id; } return ( {channelId && ( )} ); }; 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 && ( )} {(websiteUrl || email || description) && ( {websiteUrl && websiteUrl.trim().length > 0 && ( Website )} {email && email.trim().length > 0 && ( Email )} {description && description.trim().length > 0 && ( {description} )} )} ); }; onEditPressed = () => { const { claim, navigation } = this.props; if (claim) { const { permanent_url: permanentUrl } = claim; navigation.navigate({ routeName: Constants.DRAWER_ROUTE_CHANNEL_CREATOR, params: { editChannelUrl: permanentUrl }, }); } }; onDeletePressed = () => { const { abandonClaim, claim, navigation } = this.props; if (claim) { const { txid, nout } = claim; // show confirm alert Alert.alert( __('Delete channel'), __('Are you sure you want to delete this channel?'), [ { text: __('No') }, { text: __('Yes'), onPress: () => { abandonClaim(txid, nout); navigation.navigate({ routeName: Constants.DRAWER_ROUTE_CHANNEL_CREATOR }); }, }, ], { cancelable: true } ); } }; render() { const { channels, claim, navigation, uri, drawerStack, popDrawerStack, sortByItem, timeItem } = this.props; const { name, permanent_url: permanentUrl } = claim; const { autoStyle, showSortPicker, showTimePicker } = this.state; const ownedChannel = channels ? channels.map(channel => channel.permanent_url).includes(permanentUrl) : false; let thumbnailUrl, coverUrl, title, fullUri, displayName = null, substrIndex = 0; if (claim) { if (claim.value) { title = claim.value.title; if (claim.value.cover) { coverUrl = claim.value.cover.url; } if (claim.value.thumbnail) { thumbnailUrl = claim.value.thumbnail.url; } } displayName = title || claim.name; substrIndex = displayName.startsWith('@') ? 1 : 0; fullUri = normalizeURI(`${claim.name}#${claim.claim_id}`); } return ( 0 ? { uri: coverUrl } : require('../../assets/default_channel_cover.png') } /> {title && title.trim().length > 0 ? title : name} {thumbnailUrl && ( )} {(!thumbnailUrl || thumbnailUrl.trim().length === 0) && ( {displayName.substring(substrIndex, substrIndex + 1).toUpperCase()} )} {ownedChannel && (