From 1df7e617eb5c3cf9d795541f369d08b81b8c7fd3 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Fri, 20 Mar 2020 10:26:42 +0100 Subject: [PATCH] create reposts --- android | 2 +- src/component/modalRepostView/index.js | 19 ++- src/component/modalRepostView/view.js | 179 ++++++++++++++++++++++++- src/component/modalTipView/view.js | 10 +- src/constants.js | 2 +- src/page/file/view.js | 21 +++ src/page/splash/view.js | 1 + src/styles/modalRepost.js | 85 ++++++++++++ 8 files changed, 306 insertions(+), 13 deletions(-) create mode 100644 src/styles/modalRepost.js diff --git a/android b/android index 56c375f..e9c8f94 160000 --- a/android +++ b/android @@ -1 +1 @@ -Subproject commit 56c375f344911bffe64c0564dd37d2bb8b7761f1 +Subproject commit e9c8f9432f0966240670695792257b16ceaaac32 diff --git a/src/component/modalRepostView/index.js b/src/component/modalRepostView/index.js index 434e530..12b1a45 100644 --- a/src/component/modalRepostView/index.js +++ b/src/component/modalRepostView/index.js @@ -1,15 +1,28 @@ import { connect } from 'react-redux'; -import { doSendTip, doToast, selectBalance } from 'lbry-redux'; +import { + doClearRepostError, + doFetchChannelListMine, + doRepost, + doToast, + selectBalance, + selectMyChannelClaims, + selectRepostError, + selectRepostLoading, +} from 'lbry-redux'; import ModalRepostView from './view'; const select = state => ({ balance: selectBalance(state), + channels: selectMyChannelClaims(state), + reposting: selectRepostLoading(state), + error: selectRepostError(state), }); const perform = dispatch => ({ + fetchChannelListMine: () => dispatch(doFetchChannelListMine(1, 99999, true)), notify: data => dispatch(doToast(data)), - sendTip: (amount, claimId, isSupport, successCallback, errorCallback) => - dispatch(doSendTip(amount, claimId, isSupport, successCallback, errorCallback)), + repost: options => dispatch(doRepost(options)), + clearError: () => dispatch(doClearRepostError()), }); export default connect(select, perform)(ModalRepostView); diff --git a/src/component/modalRepostView/view.js b/src/component/modalRepostView/view.js index f151a74..88333c4 100644 --- a/src/component/modalRepostView/view.js +++ b/src/component/modalRepostView/view.js @@ -1,14 +1,187 @@ import React from 'react'; import { ActivityIndicator, Alert, Text, TextInput, TouchableOpacity, View } from 'react-native'; -import { formatCredits } from 'lbry-redux'; +import { formatCredits, creditsToString } from 'lbry-redux'; import modalStyle from 'styles/modal'; -import modalTipStyle from 'styles/modalTip'; +import modalRepostStyle from 'styles/modalRepost'; +import ChannelSelector from 'component/channelSelector'; import Button from 'component/button'; import Colors from 'styles/colors'; import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api import Icon from 'react-native-vector-icons/FontAwesome5'; import Link from 'component/link'; +import { logPublish } from 'utils/helper'; export default class ModalRepostView extends React.PureComponent { - render() {} + depositAmountInput; + + state = { + repostName: null, + channelName: null, + creditsInputFocused: false, + depositAmount: '0.1', + repostStarted: false, + }; + + componentDidMount() { + const { claim, fetchChannelListMine } = this.props; + const { name } = claim; + fetchChannelListMine(); + this.setState({ repostName: name }); + this.checkChannelSelection(this.props); + } + + componentWillReceiveProps(nextProps) { + this.checkChannelSelection(nextProps); + const { notify } = this.props; + const { reposting, error } = nextProps; + if (this.state.repostStarted && !reposting && error) { + this.setState({ repostStarted: false }); + notify({ message: error, isError: true }); + } + } + + checkChannelSelection = props => { + const { channels = [] } = props; + if (!this.state.channelName && channels && channels.length > 0) { + const firstChannel = channels[0]; + this.setState({ channelName: firstChannel.name }); + } + }; + + handleChannelChange = channelName => { + const { channels = [] } = this.props; + if (channels && channels.length > 0) { + const filtered = channels.filter(c => c.name === channelName); + if (filtered.length > 0) { + const channel = filtered[0]; + this.setState({ channelName }); + } + } + }; + + handleRepost = () => { + const { claim, balance, notify, repost, onRepostSuccessful, channels = [], clearError } = this.props; + const { depositAmount, repostName, channelName } = this.state; + + if (parseInt(depositAmount, 10) > balance) { + notify({ + message: 'Insufficient credits', + isError: true, + }); + return; + } + + clearError(); + const channel = channels.filter(ch => ch.name === channelName)[0]; + this.setState({ repostStarted: true }, () => { + repost({ + name: repostName, + bid: creditsToString(depositAmount), + channel_id: channel.claim_id, + claim_id: claim.claim_id, + }).then(repostClaim => { + logPublish(repostClaim); + this.setState({ repostStarted: false }); + notify({ message: __('The content was successfully reposted!') }); + if (onRepostSuccessful) onRepostSuccessful(); + }); + }); + }; + + render() { + const { balance, channels, reposting, title, onCancelPress, onOverlayPress } = this.props; + const canRepost = !!this.state.channelName && !!this.state.repostName; + const channelsLoaded = channels && channels.length > 0; + + return ( + + + { + if (this.tipAmountInput) { + this.tipAmountInput.focus(); + } + }} + > + + {__('Repost %title%', { title })} + + + {__('Repost your favorite content to help more people discover them!')} + + + {__('Channel to post on')} + + + {__('Name')} + + + this.setState({ repostName: value })} + style={modalRepostStyle.input} + /> + + + {__('Deposit')} + + + (this.depositAmountInput = ref)} + onChangeText={value => this.setState({ tipAmount: value })} + underlineColorAndroid={Colors.NextLbryGreen} + keyboardType={'numeric'} + onFocus={() => this.setState({ creditsInputFocused: true })} + onBlur={() => this.setState({ creditsInputFocused: false })} + placeholder={'0'} + value={this.state.depositAmount} + selectTextOnFocus + style={modalRepostStyle.depositAmountInput} + /> + LBC + + {this.state.creditsInputFocused && } + {this.state.creditsInputFocused && ( + {formatCredits(parseFloat(balance), 1, true)} + )} + + + {(this.state.repostStarted || reposting || !channelsLoaded) && ( + + )} + + + + { + if (onCancelPress) onCancelPress(); + }} + /> +