From aa935c1c07a0e02cb4c994c2f20bd278b34f2bda Mon Sep 17 00:00:00 2001 From: Jeremy Kauffman Date: Mon, 15 May 2017 12:34:33 -0400 Subject: [PATCH] more refactors, fixes --- ui/js/actions/content.js | 43 +++++++++++++++++--------- ui/js/actions/file_info.js | 7 ----- ui/js/component/app/index.js | 4 +++ ui/js/component/app/view.jsx | 7 ++++- ui/js/component/fileActions/index.js | 1 - ui/js/component/fileActions/view.jsx | 9 ++++-- ui/js/component/fileCard/index.js | 2 ++ ui/js/component/fileCard/view.jsx | 16 ++++++++-- ui/js/component/fileList/view.jsx | 4 ++- ui/js/component/filePrice/index.js | 3 +- ui/js/component/video/view.jsx | 13 +++++--- ui/js/jsonrpc.js | 2 ++ ui/js/lbry.js | 17 +++++----- ui/js/page/fileListDownloaded/view.jsx | 12 ++++--- ui/js/page/fileListPublished/view.jsx | 13 +++++--- ui/js/reducers/file_info.js | 5 --- ui/js/selectors/app.js | 7 +---- ui/js/selectors/content.js | 4 +-- ui/scss/_gui.scss | 8 +++++ 19 files changed, 113 insertions(+), 64 deletions(-) diff --git a/ui/js/actions/content.js b/ui/js/actions/content.js index 43fbfab9b..74f0f3f74 100644 --- a/ui/js/actions/content.js +++ b/ui/js/actions/content.js @@ -10,6 +10,9 @@ import { selectFileInfoForUri, selectDownloadingByUri, } from 'selectors/file_info' +import { + selectResolvingUris +} from 'selectors/content' import { selectCostInfoForUri, } from 'selectors/cost_info' @@ -22,26 +25,38 @@ import { export function doResolveUri(uri) { return function(dispatch, getState) { - dispatch({ - type: types.RESOLVE_URI_STARTED, - data: { uri } - }) - lbry.resolve({ uri }).then((resolutionInfo) => { - const { - claim, - certificate, - } = resolutionInfo ? resolutionInfo : { claim : null, certificate: null } + const state = getState() + const alreadyResolving = selectResolvingUris(state).indexOf(uri) !== -1 + if (!alreadyResolving) { dispatch({ - type: types.RESOLVE_URI_COMPLETED, - data: { - uri, + type: types.RESOLVE_URI_STARTED, + data: { uri } + }) + + lbry.resolve({ uri }).then((resolutionInfo) => { + const { claim, certificate, - } + } = resolutionInfo ? resolutionInfo : { claim : null, certificate: null } + + dispatch({ + type: types.RESOLVE_URI_COMPLETED, + data: { + uri, + claim, + certificate, + } + }) }) - }) + } + } +} + +export function doCancelResolveUri(uri) { + return function(dispatch, getState) { + lbry.cancelResolve({ uri }) } } diff --git a/ui/js/actions/file_info.js b/ui/js/actions/file_info.js index 87f962471..f7d2b08f3 100644 --- a/ui/js/actions/file_info.js +++ b/ui/js/actions/file_info.js @@ -21,13 +21,6 @@ export function doFetchFileInfo(uri) { const outpoint = claim ? `${claim.txid}:${claim.nout}` : null const alreadyFetching = !!selectLoadingByUri(state)[uri] - if (!outpoint) { - console.log(claim); - console.log(outpoint); - console.log(selectClaimsByUri(state)) - throw new Error("Unable to get outpoint from claim for URI " + uri); - } - if (!alreadyFetching) { dispatch({ type: types.FETCH_FILE_INFO_STARTED, diff --git a/ui/js/component/app/index.js b/ui/js/component/app/index.js index a7ce7ce70..dcb94bd0f 100644 --- a/ui/js/component/app/index.js +++ b/ui/js/component/app/index.js @@ -7,6 +7,9 @@ import { import { doCheckUpgradeAvailable, } from 'actions/app' +import { + doUpdateBalance, +} from 'actions/wallet' import App from './view' const select = (state) => ({ @@ -15,6 +18,7 @@ const select = (state) => ({ const perform = (dispatch) => ({ checkUpgradeAvailable: () => dispatch(doCheckUpgradeAvailable()), + updateBalance: (balance) => dispatch(doUpdateBalance(balance)) }) export default connect(select, perform)(App) diff --git a/ui/js/component/app/view.jsx b/ui/js/component/app/view.jsx index 5e47c81f7..1c7ff4eb4 100644 --- a/ui/js/component/app/view.jsx +++ b/ui/js/component/app/view.jsx @@ -4,7 +4,8 @@ import Header from 'component/header'; import ErrorModal from 'component/errorModal' import DownloadingModal from 'component/downloadingModal' import UpgradeModal from 'component/upgradeModal' -import {Line} from 'rc-progress'; +import lbry from 'lbry' +import {Line} from 'rc-progress' class App extends React.Component { componentWillMount() { @@ -15,6 +16,10 @@ class App extends React.Component { if (!this.props.upgradeSkipped) { this.props.checkUpgradeAvailable() } + + lbry.balanceSubscribe((balance) => { + this.props.updateBalance(balance) + }) } render() { diff --git a/ui/js/component/fileActions/index.js b/ui/js/component/fileActions/index.js index 87b4cb330..c238f36b8 100644 --- a/ui/js/component/fileActions/index.js +++ b/ui/js/component/fileActions/index.js @@ -3,7 +3,6 @@ import { connect, } from 'react-redux' import { - selectHasSignature, selectPlatform, } from 'selectors/app' import { diff --git a/ui/js/component/fileActions/view.jsx b/ui/js/component/fileActions/view.jsx index 468e89329..ec2b93587 100644 --- a/ui/js/component/fileActions/view.jsx +++ b/ui/js/component/fileActions/view.jsx @@ -72,11 +72,14 @@ class FileActions extends React.Component { let content - if (fileInfo === undefined || isAvailable === undefined) { + console.log('file actions render') + console.log(this.props) + + if (!fileInfo && isAvailable === undefined) { content = - } else if (!isAvailable && !this.state.forceShowActions) { + } else if (!fileInfo && !isAvailable && !this.state.forceShowActions) { content =
Content unavailable.
@@ -119,7 +122,7 @@ class FileActions extends React.Component { : '' } - Are you sure you'd like to buy {title} for credits? + This will purchase {title} for credits. diff --git a/ui/js/component/fileCard/index.js b/ui/js/component/fileCard/index.js index 643434406..e3e11057e 100644 --- a/ui/js/component/fileCard/index.js +++ b/ui/js/component/fileCard/index.js @@ -7,6 +7,7 @@ import { } from 'actions/app' import { doResolveUri, + doCancelResolveUri, } from 'actions/content' import { selectObscureNsfw, @@ -44,6 +45,7 @@ const makeSelect = () => { const perform = (dispatch) => ({ navigate: (path, params) => dispatch(doNavigate(path, params)), resolveUri: (uri) => dispatch(doResolveUri(uri)), + cancelResolveUri: (uri) => dispatch(doCancelResolveUri(uri)) }) export default connect(makeSelect, perform)(FileCard) diff --git a/ui/js/component/fileCard/view.jsx b/ui/js/component/fileCard/view.jsx index e97f17f92..371a955e6 100644 --- a/ui/js/component/fileCard/view.jsx +++ b/ui/js/component/fileCard/view.jsx @@ -8,18 +8,30 @@ import UriIndicator from 'component/uriIndicator'; class FileCard extends React.Component { componentDidMount() { + this.resolve(this.props) + } + + componentWillReceiveProps(nextProps) { + this.resolve(nextProps) + } + + resolve(props) { const { isResolvingUri, resolveUri, claim, uri, - } = this.props + } = props - if(!isResolvingUri && !claim && uri) { + if(!isResolvingUri && claim === undefined && uri) { resolveUri(uri) } } + componentWillUnmount() { + this.props.cancelResolveUri(this.props.uri) + } + handleMouseOver() { this.setState({ hovered: true, diff --git a/ui/js/component/fileList/view.jsx b/ui/js/component/fileList/view.jsx index ebd94c0ee..6130a5ffb 100644 --- a/ui/js/component/fileList/view.jsx +++ b/ui/js/component/fileList/view.jsx @@ -58,6 +58,7 @@ class FileList extends React.Component { render() { const { handleSortChanged, + fetching, fileInfos, hidePrices, } = this.props @@ -74,7 +75,8 @@ class FileList extends React.Component { content.push() }) return ( -
+
+ { fetching && } Sort by { ' ' } diff --git a/ui/js/component/filePrice/index.js b/ui/js/component/filePrice/index.js index b2271e493..62b917b76 100644 --- a/ui/js/component/filePrice/index.js +++ b/ui/js/component/filePrice/index.js @@ -20,7 +20,8 @@ const makeSelect = () => { } const perform = (dispatch) => ({ - fetchCostInfo: (uri) => dispatch(doFetchCostInfoForUri(uri)) + fetchCostInfo: (uri) => dispatch(doFetchCostInfoForUri(uri)), + cancelFetchCostInfo: (uri) => dispatch(doCancelFetchCostInfoForUri(uri)) }) export default connect(makeSelect, perform)(FilePrice) diff --git a/ui/js/component/video/view.jsx b/ui/js/component/video/view.jsx index 1dea58524..447d87d15 100644 --- a/ui/js/component/video/view.jsx +++ b/ui/js/component/video/view.jsx @@ -38,7 +38,7 @@ class VideoPlayButton extends React.Component { return (
- Are you sure you'd like to buy {this.props.metadata.title} for credits? + This will purchase {title} for credits. @@ -98,6 +98,11 @@ class Video extends React.Component { isPlaying = false, } = this.state + const isReadyToPlay = fileInfo && fileInfo.written_bytes > 0 + + console.log('video render') + console.log(this.props) + let loadStatusMessage = '' if (isLoading) { @@ -107,9 +112,9 @@ class Video extends React.Component { } return ( -
{ +
{ isPlaying ? - (!fileInfo.isReadyToPlay ? + (!isReadyToPlay ? this is the world's worst loading screen and we shipped our software with it anyway...

{loadStatusMessage}
: ) :
diff --git a/ui/js/jsonrpc.js b/ui/js/jsonrpc.js index 654931bb5..378e850a2 100644 --- a/ui/js/jsonrpc.js +++ b/ui/js/jsonrpc.js @@ -68,6 +68,8 @@ jsonrpc.call = function (connectionString, method, params, callback, errorCallba })); sessionStorage.setItem('JSONRPCCounter', counter + 1); + + return xhr }; export default jsonrpc; diff --git a/ui/js/lbry.js b/ui/js/lbry.js index b3772b395..8a8a16bf7 100644 --- a/ui/js/lbry.js +++ b/ui/js/lbry.js @@ -95,7 +95,7 @@ let lbry = { }; lbry.call = function (method, params, callback, errorCallback, connectFailedCallback) { - jsonrpc.call(lbry.daemonConnectionString, method, params, callback, errorCallback, connectFailedCallback); + return jsonrpc.call(lbry.daemonConnectionString, method, params, callback, errorCallback, connectFailedCallback); } //core @@ -177,11 +177,6 @@ lbry.setDaemonSetting = function(setting, value, callback) { lbry.call('set_settings', setSettingsArgs, callback) } - -lbry.getBalance = function(callback) { - lbry.call("wallet_balance", {}, callback); -} - lbry.sendToAddress = function(amount, address, callback, errorCallback) { lbry.call("send_amount_to_address", { "amount" : amount, "address": address }, callback, errorCallback); } @@ -641,6 +636,7 @@ lbry.claim_list_mine = function(params={}) { const claimCacheKey = 'resolve_claim_cache'; lbry._claimCache = getSession(claimCacheKey, {}); +lbry._resolveXhrs = {} lbry.resolve = function(params={}) { return new Promise((resolve, reject) => { if (!params.uri) { @@ -649,7 +645,7 @@ lbry.resolve = function(params={}) { if (params.uri && lbry._claimCache[params.uri] !== undefined) { resolve(lbry._claimCache[params.uri]); } else { - lbry.call('resolve', params, function(data) { + lbry._resolveXhrs[params.uri] = lbry.call('resolve', params, function(data) { if (data !== undefined) { lbry._claimCache[params.uri] = data; } @@ -660,6 +656,13 @@ lbry.resolve = function(params={}) { }); } +lbry.cancelResolve = function(params={}) { + const xhr = lbry._resolveXhrs[params.uri] + if (xhr && xhr.readyState > 0 && xhr.readyState < 4) { + xhr.abort() + } +} + // Adds caching. lbry._settingsPromise = null; lbry.settings_get = function(params={}) { diff --git a/ui/js/page/fileListDownloaded/view.jsx b/ui/js/page/fileListDownloaded/view.jsx index 8006828dd..2c041a267 100644 --- a/ui/js/page/fileListDownloaded/view.jsx +++ b/ui/js/page/fileListDownloaded/view.jsx @@ -23,12 +23,14 @@ class FileListDownloaded extends React.Component { } = this.props let content - if (fetching) { - content = - } else if (!downloadedContent.length) { - content = You haven't downloaded anything from LBRY yet. Go navigate('/discover')} label="search for your first download" />! + if (downloadedContent && downloadedContent.length > 0) { + content = } else { - content = + if (fetching) { + content = + } else { + content = You haven't downloaded anything from LBRY yet. Go navigate('/discover')} label="search for your first download" />! + } } return ( diff --git a/ui/js/page/fileListPublished/view.jsx b/ui/js/page/fileListPublished/view.jsx index 704a76cff..365aa061c 100644 --- a/ui/js/page/fileListPublished/view.jsx +++ b/ui/js/page/fileListPublished/view.jsx @@ -44,12 +44,15 @@ class FileListPublished extends React.Component { } = this.props let content - if (fetching) { - content = - } else if (!publishedContent.length) { - content = You haven't downloaded anything from LBRY yet. Go navigate('/discover')} label="search for your first download" />! + + if (publishedContent && publishedContent.length > 0) { + content = } else { - content = + if (fetching) { + content = + } else { + content = You haven't downloaded anything from LBRY yet. Go navigate('/discover')} label="search for your first download" />! + } } return ( diff --git a/ui/js/reducers/file_info.js b/ui/js/reducers/file_info.js index d0e69e148..951b0f213 100644 --- a/ui/js/reducers/file_info.js +++ b/ui/js/reducers/file_info.js @@ -27,11 +27,6 @@ reducers[types.FETCH_FILE_INFO_COMPLETED] = function(state, action) { const newByUri = Object.assign({}, state.byUri) const newFetching = Object.assign({}, state.fetching) - if (fileInfo) { - fileInfo.isReadyToPlay = fileInfo.written_bytes > 0 - fileInfo.isDownloaded = fileInfo.completed && fileInfo.written_bytes > 0; - } - newByUri[uri] = fileInfo || null delete newFetching[uri] diff --git a/ui/js/selectors/app.js b/ui/js/selectors/app.js index 94a595357..f0af3b5a1 100644 --- a/ui/js/selectors/app.js +++ b/ui/js/selectors/app.js @@ -191,9 +191,4 @@ export const selectDaemonReady = createSelector( export const selectObscureNsfw = createSelector( _selectState, (state) => !!state.obscureNsfw -) - -export const selectHasSignature = createSelector( - _selectState, - (state) => !!state.hasSignature -) +) \ No newline at end of file diff --git a/ui/js/selectors/content.js b/ui/js/selectors/content.js index 03fda8112..22476b229 100644 --- a/ui/js/selectors/content.js +++ b/ui/js/selectors/content.js @@ -42,7 +42,7 @@ export const selectPublishedContent = createSelector( (state) => state.publishedContent || {} ) -const selectResolvingUris = createSelector( +export const selectResolvingUris = createSelector( _selectState, (state) => state.resolvingUris || [] ) @@ -56,4 +56,4 @@ export const makeSelectIsResolvingForUri = () => { selectResolvingUri, (resolving) => resolving ) -} +} \ No newline at end of file diff --git a/ui/scss/_gui.scss b/ui/scss/_gui.scss index 3d85f4b22..f4ededba0 100644 --- a/ui/scss/_gui.scss +++ b/ui/scss/_gui.scss @@ -143,6 +143,14 @@ p font-style: italic; } +/*should be redone/moved*/ +.file-list__header { + .busy-indicator { + float: left; + margin-top: 12px; + } +} + .sort-section { display: block; margin-bottom: $spacing-vertical * 2/3;