From b599e5343c2aa181b5fcb2274aa066efa8b55c94 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Mon, 10 Apr 2017 04:06:15 -0400 Subject: [PATCH] Publish: wait for new channel to appear before updating list --- ui/js/page/publish.js | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/ui/js/page/publish.js b/ui/js/page/publish.js index 61773fb01..f456d5f39 100644 --- a/ui/js/page/publish.js +++ b/ui/js/page/publish.js @@ -7,6 +7,16 @@ import Modal from '../component/modal.js'; var PublishPage = React.createClass({ _requiredFields: ['name', 'bid', 'meta_title', 'meta_author', 'meta_license', 'meta_description'], + _updateChannelList: function(channel) { + // Calls API to update displayed list of channels. If a channel name is provided, will select + // that channel at the same time (used immediately after creating a channel) + lbry.channel_list_mine().then((channels) => { + this.setState({ + channels: channels, + ... channel ? {channel} : {} + }); + }); + }, handleSubmit: function(event) { if (typeof event !== 'undefined') { event.preventDefault(); @@ -282,15 +292,15 @@ var PublishPage = React.createClass({ creatingChannel: true, }); - lbry.channel_new({channel_name: this.state.newChannelName, amount: parseInt(this.state.newChannelBid)}).then(() => { - this.setState({ - creatingChannel: false, - }); + const newChannelName = this.state.newChannelName; + lbry.channel_new({channel_name: newChannelName, amount: parseInt(this.state.newChannelBid)}).then(() => { + setTimeout(() => { + this.setState({ + creatingChannel: false, + }); - this.forceUpdate(); - this.setState({ - channel: name, - }); + this._updateChannelList(newChannelName); + }, 5000); }, (error) => { // TODO: add error handling this.setState({ @@ -308,11 +318,7 @@ var PublishPage = React.createClass({ } }, componentWillMount: function() { - lbry.channel_list_mine().then((channels) => { - this.setState({ - channels: channels, - }); - }); + this._updateChannelList(); }, componentDidMount: function() { document.title = "Publish";