import React from "react"; import lbryuri from "lbryuri"; import { FormRow } from "component/form.js"; import { BusyMessage } from "component/common"; import Link from "component/link"; class ChannelSection extends React.PureComponent { constructor(props) { super(props); this.state = { newChannelName: "@", newChannelBid: 10, addingChannel: false, }; } handleChannelChange(event) { const channel = event.target.value; if (channel === "new") this.setState({ addingChannel: true }); else { this.setState({ addingChannel: false }); this.props.handleChannelChange(event.target.value); } } handleNewChannelNameChange(event) { const newChannelName = event.target.value.startsWith("@") ? event.target.value : "@" + event.target.value; if ( newChannelName.length > 1 && !lbryuri.isValidName(newChannelName.substr(1), false) ) { this.refs.newChannelName.showError( __("LBRY channel names must contain only letters, numbers and dashes.") ); return; } else { this.refs.newChannelName.clearError(); } this.setState({ newChannelName, }); } handleNewChannelBidChange(event) { this.setState({ newChannelBid: event.target.value, }); } handleCreateChannelClick(event) { if (this.state.newChannelName.length < 5) { this.refs.newChannelName.showError( __("LBRY channel names must be at least 5 characters in length.") ); return; } this.setState({ creatingChannel: true, }); const newChannelName = this.state.newChannelName; const amount = parseFloat(this.state.newChannelBid); this.setState({ creatingChannel: true, }); const success = () => { this.setState({ creatingChannel: false, addingChannel: false, channel: newChannelName, }); this.props.handleChannelChange(newChannelName); }; const failure = err => { this.setState({ creatingChannel: false, }); this.refs.newChannelName.showError( __("Unable to create channel due to an internal error.") ); }; this.props.createChannel(newChannelName, amount).then(success, failure); } render() { const lbcInputHelp = __( "This LBC remains yours and the deposit can be undone at any time." ); const channel = this.state.addingChannel ? "new" : this.props.channel; const { fetchingChannels, channels = [] } = this.props; let channelContent = []; channelContent.push( {this.props.channels.map(({ name }) => )} ); if (fetchingChannels) { channelContent.push( ); } return (

{__("Channel Name")}

{__( "This is a username or handle that your content can be found under." )} {" "} {__("Ex. @Marvel, @TheBeatles, @BooksByJoe")}
{channelContent}
{this.state.addingChannel &&
}
); } } export default ChannelSection;