2017-06-30 10:45:54 +02:00
|
|
|
import React from "react";
|
|
|
|
import lbryuri from "lbryuri";
|
2017-08-07 00:24:55 +02:00
|
|
|
import { FormRow } from "component/form.js";
|
2017-06-30 10:45:54 +02:00
|
|
|
import { BusyMessage } from "component/common";
|
2017-07-04 14:51:05 +02:00
|
|
|
import Link from "component/link";
|
2017-06-30 10:45:54 +02:00
|
|
|
|
|
|
|
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 4 characters in length.")
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
creatingChannel: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
const newChannelName = this.state.newChannelName;
|
|
|
|
const amount = parseFloat(this.state.newChannelBid);
|
|
|
|
this.setState({
|
|
|
|
creatingChannel: true,
|
|
|
|
});
|
2017-07-11 08:15:51 +02:00
|
|
|
const success = () => {
|
2017-06-30 10:45:54 +02:00
|
|
|
this.setState({
|
|
|
|
creatingChannel: false,
|
|
|
|
addingChannel: false,
|
|
|
|
channel: newChannelName,
|
|
|
|
});
|
|
|
|
this.props.handleChannelChange(newChannelName);
|
2017-07-11 08:15:51 +02:00
|
|
|
};
|
|
|
|
const failure = err => {
|
2017-06-30 10:45:54 +02:00
|
|
|
this.setState({
|
|
|
|
creatingChannel: false,
|
|
|
|
});
|
|
|
|
this.refs.newChannelName.showError(
|
|
|
|
__("Unable to create channel due to an internal error.")
|
|
|
|
);
|
2017-07-11 08:15:51 +02:00
|
|
|
};
|
2017-06-30 10:45:54 +02:00
|
|
|
this.props.createChannel(newChannelName, amount).then(success, failure);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const lbcInputHelp = __(
|
|
|
|
"This LBC remains yours and the deposit can be undone at any time."
|
|
|
|
);
|
|
|
|
|
2017-07-18 08:53:45 +02:00
|
|
|
const channel = this.state.addingChannel ? "new" : this.props.channel;
|
2017-07-04 14:51:05 +02:00
|
|
|
const { fetchingChannels, channels = [] } = this.props;
|
2017-06-30 10:45:54 +02:00
|
|
|
|
|
|
|
let channelContent = [];
|
2017-07-04 14:51:05 +02:00
|
|
|
channelContent.push(
|
|
|
|
<FormRow
|
|
|
|
key="channel"
|
|
|
|
type="select"
|
|
|
|
tabIndex="1"
|
|
|
|
onChange={this.handleChannelChange.bind(this)}
|
2017-07-18 08:53:45 +02:00
|
|
|
value={channel}
|
2017-07-04 14:51:05 +02:00
|
|
|
>
|
|
|
|
<option key="anonymous" value="anonymous">
|
|
|
|
{__("Anonymous")}
|
|
|
|
</option>
|
|
|
|
{this.props.channels.map(({ name }) =>
|
|
|
|
<option key={name} value={name}>{name}</option>
|
|
|
|
)}
|
|
|
|
<option key="new" value="new">
|
2017-07-19 02:43:07 +02:00
|
|
|
{__("New channel...")}
|
2017-07-04 14:51:05 +02:00
|
|
|
</option>
|
|
|
|
</FormRow>
|
|
|
|
);
|
|
|
|
if (fetchingChannels) {
|
2017-06-30 10:45:54 +02:00
|
|
|
channelContent.push(
|
2017-07-04 14:51:05 +02:00
|
|
|
<BusyMessage message="Updating channels" key="loading" />
|
2017-06-30 10:45:54 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<section className="card">
|
|
|
|
<div className="card__title-primary">
|
2017-07-19 02:43:07 +02:00
|
|
|
<h4>{__("Channel Name")}</h4>
|
2017-06-30 10:45:54 +02:00
|
|
|
<div className="card__subtitle">
|
2017-08-07 00:24:55 +02:00
|
|
|
{__(
|
|
|
|
"This is a username or handle that your content can be found under."
|
|
|
|
)}
|
|
|
|
{" "}
|
2017-07-19 02:43:07 +02:00
|
|
|
{__("Ex. @Marvel, @TheBeatles, @BooksByJoe")}
|
2017-06-30 10:45:54 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="card__content">
|
|
|
|
{channelContent}
|
|
|
|
</div>
|
|
|
|
{this.state.addingChannel &&
|
|
|
|
<div className="card__content">
|
|
|
|
<FormRow
|
|
|
|
label={__("Name")}
|
|
|
|
type="text"
|
2017-07-18 08:53:45 +02:00
|
|
|
onChange={this.handleNewChannelNameChange.bind(this)}
|
2017-06-30 10:45:54 +02:00
|
|
|
value={this.state.newChannelName}
|
|
|
|
/>
|
|
|
|
<FormRow
|
|
|
|
label={__("Deposit")}
|
|
|
|
postfix="LBC"
|
|
|
|
step="0.1"
|
|
|
|
min="0"
|
|
|
|
type="number"
|
|
|
|
helper={lbcInputHelp}
|
|
|
|
ref="newChannelName"
|
|
|
|
onChange={this.handleNewChannelBidChange.bind(this)}
|
|
|
|
value={this.state.newChannelBid}
|
|
|
|
/>
|
|
|
|
<div className="form-row-submit">
|
|
|
|
<Link
|
|
|
|
button="primary"
|
|
|
|
label={
|
|
|
|
!this.state.creatingChannel
|
2017-07-19 02:43:07 +02:00
|
|
|
? __("Create channel")
|
|
|
|
: __("Creating channel...")
|
2017-06-30 10:45:54 +02:00
|
|
|
}
|
|
|
|
onClick={this.handleCreateChannelClick.bind(this)}
|
|
|
|
disabled={this.state.creatingChannel}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>}
|
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ChannelSection;
|