2019-07-26 17:12:28 +01:00
|
|
|
import React from 'react';
|
2019-08-20 09:03:33 +01:00
|
|
|
import { ActivityIndicator, Alert, FlatList, NativeModules, Text, TouchableOpacity, View } from 'react-native';
|
2019-07-26 17:12:28 +01:00
|
|
|
import Button from 'component/button';
|
|
|
|
import Colors from 'styles/colors';
|
|
|
|
import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api
|
|
|
|
import FileListItem from 'component/fileListItem';
|
|
|
|
import FloatingWalletBalance from 'component/floatingWalletBalance';
|
|
|
|
import UriBar from 'component/uriBar';
|
|
|
|
import publishStyle from 'styles/publish';
|
2019-08-16 18:26:13 +01:00
|
|
|
import { __, navigateToUri } from 'utils/helper';
|
2019-07-26 17:12:28 +01:00
|
|
|
|
|
|
|
class PublishesPage extends React.PureComponent {
|
2019-08-16 18:26:13 +01:00
|
|
|
state = {
|
|
|
|
selectionMode: false,
|
|
|
|
selectedUris: [],
|
|
|
|
selectedClaimsMap: {},
|
|
|
|
};
|
|
|
|
|
2019-07-26 17:12:28 +01:00
|
|
|
didFocusListener;
|
|
|
|
|
|
|
|
componentWillMount() {
|
|
|
|
const { navigation } = this.props;
|
2019-08-10 07:55:12 +01:00
|
|
|
// this.didFocusListener = navigation.addListener('didFocus', this.onComponentFocused);
|
2019-07-26 17:12:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
if (this.didFocusListener) {
|
|
|
|
this.didFocusListener.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-10 07:55:12 +01:00
|
|
|
componentDidMount() {
|
|
|
|
this.onComponentFocused();
|
|
|
|
}
|
|
|
|
|
2019-07-26 17:12:28 +01:00
|
|
|
onComponentFocused = () => {
|
2019-08-11 00:06:10 +01:00
|
|
|
const { checkPendingPublishes, fetchMyClaims, pushDrawerStack, setPlayerVisible } = this.props;
|
2019-07-26 17:12:28 +01:00
|
|
|
pushDrawerStack();
|
|
|
|
setPlayerVisible();
|
2019-08-20 09:03:33 +01:00
|
|
|
NativeModules.Firebase.setCurrentScreen('Publishes');
|
|
|
|
|
2019-08-11 00:06:10 +01:00
|
|
|
fetchMyClaims();
|
2019-07-26 17:12:28 +01:00
|
|
|
checkPendingPublishes();
|
|
|
|
};
|
|
|
|
|
2019-08-16 18:26:13 +01:00
|
|
|
addOrRemoveItem = (uri, claim) => {
|
|
|
|
const { selectedClaimsMap } = this.state;
|
|
|
|
let selectedUris = [...this.state.selectedUris];
|
|
|
|
|
|
|
|
if (selectedUris.includes(uri)) {
|
|
|
|
delete selectedClaimsMap[uri];
|
|
|
|
selectedUris.splice(selectedUris.indexOf(uri), 1);
|
|
|
|
} else {
|
|
|
|
selectedClaimsMap[uri] = claim;
|
|
|
|
selectedUris.push(uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({ selectionMode: selectedUris.length > 0, selectedUris, selectedClaimsMap });
|
|
|
|
};
|
|
|
|
|
|
|
|
handleSelectItem = (uri, claim) => {
|
|
|
|
this.addOrRemoveItem(uri, claim);
|
|
|
|
};
|
|
|
|
|
|
|
|
handleItemLongPress = (uri, claim) => {
|
|
|
|
this.addOrRemoveItem(uri, claim);
|
|
|
|
};
|
|
|
|
|
|
|
|
onExitSelectionMode = () => {
|
|
|
|
this.setState({ selectionMode: false, selectedUris: [], selectedClaimsMap: {} });
|
|
|
|
};
|
|
|
|
|
|
|
|
onDeleteActionPressed = () => {
|
|
|
|
const { abandonClaim } = this.props;
|
|
|
|
const { selectedClaimsMap } = this.state;
|
|
|
|
|
|
|
|
// show confirm alert
|
2019-08-20 09:19:42 +01:00
|
|
|
Alert.alert(
|
|
|
|
__('Unpublish'),
|
|
|
|
__('Are you sure you want to unpublish the selected content?'),
|
|
|
|
[
|
|
|
|
{ text: __('No') },
|
|
|
|
{
|
|
|
|
text: __('Yes'),
|
|
|
|
onPress: () => {
|
|
|
|
const uris = Object.keys(selectedClaimsMap);
|
|
|
|
uris.forEach(uri => {
|
|
|
|
const { txid, nout } = selectedClaimsMap[uri];
|
|
|
|
abandonClaim(txid, nout);
|
|
|
|
});
|
|
|
|
this.onExitSelectionMode();
|
|
|
|
},
|
2019-08-16 18:26:13 +01:00
|
|
|
},
|
2019-08-20 09:19:42 +01:00
|
|
|
],
|
|
|
|
{ cancelable: true }
|
|
|
|
);
|
2019-08-16 18:26:13 +01:00
|
|
|
};
|
|
|
|
|
2019-07-26 17:12:28 +01:00
|
|
|
render() {
|
|
|
|
const { fetching, navigation, uris } = this.props;
|
2019-08-16 18:26:13 +01:00
|
|
|
const { selectionMode, selectedUris } = this.state;
|
2019-07-26 17:12:28 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<View style={publishStyle.container}>
|
2019-08-16 18:26:13 +01:00
|
|
|
<UriBar
|
|
|
|
navigation={navigation}
|
|
|
|
selectionMode={selectionMode}
|
|
|
|
selectedItemCount={selectedUris.length}
|
|
|
|
onExitSelectionMode={this.onExitSelectionMode}
|
|
|
|
onDeleteActionPressed={this.onDeleteActionPressed}
|
|
|
|
/>
|
2019-07-26 17:12:28 +01:00
|
|
|
{fetching && (
|
|
|
|
<View style={publishStyle.centered}>
|
2019-08-20 09:19:42 +01:00
|
|
|
<ActivityIndicator size={'large'} color={Colors.NextLbryGreen} />
|
2019-07-26 17:12:28 +01:00
|
|
|
</View>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{!fetching && (!uris || uris.length === 0) && (
|
|
|
|
<View style={publishStyle.noPublishes}>
|
|
|
|
<Text style={publishStyle.noPublishText}>
|
|
|
|
{__('It looks like you have not published anything to LBRY yet.')}
|
|
|
|
</Text>
|
|
|
|
<Button
|
|
|
|
style={publishStyle.publishNowButton}
|
|
|
|
text={__('Publish something new')}
|
|
|
|
onPress={() => navigation.navigate({ routeName: Constants.DRAWER_ROUTE_PUBLISH })}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{uris && uris.length > 0 && (
|
|
|
|
<FlatList
|
|
|
|
style={publishStyle.publishesList}
|
|
|
|
contentContainerStyle={publishStyle.publishesScrollPadding}
|
2019-08-16 18:26:13 +01:00
|
|
|
extraData={this.state}
|
2019-07-26 17:12:28 +01:00
|
|
|
initialNumToRender={8}
|
|
|
|
maxToRenderPerBatch={24}
|
|
|
|
removeClippedSubviews
|
|
|
|
renderItem={({ item }) => (
|
2019-08-16 18:26:13 +01:00
|
|
|
<FileListItem
|
|
|
|
hideChannel
|
|
|
|
key={item}
|
|
|
|
uri={item}
|
|
|
|
style={publishStyle.listItem}
|
|
|
|
selected={selectedUris.includes(item)}
|
|
|
|
onPress={claim => {
|
|
|
|
if (selectionMode) {
|
|
|
|
this.handleSelectItem(item, claim);
|
|
|
|
} else {
|
|
|
|
// TODO: when shortUrl is available for my claims, navigate to that URL instead
|
|
|
|
navigateToUri(navigation, item);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
onLongPress={claim => this.handleItemLongPress(item, claim)}
|
|
|
|
navigation={navigation}
|
|
|
|
/>
|
2019-07-26 17:12:28 +01:00
|
|
|
)}
|
|
|
|
data={uris}
|
|
|
|
keyExtractor={(item, index) => item}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<FloatingWalletBalance navigation={navigation} />
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default PublishesPage;
|