From f97ec7b39034db3282670d7840f1990890211707 Mon Sep 17 00:00:00 2001 From: 6ea86b96 <6ea86b96@gmail.com> Date: Sun, 4 Jun 2017 18:53:26 +0700 Subject: [PATCH 1/5] Store claims by id in the state --- ui/js/reducers/claims.js | 40 +++++++++++++++++---------------------- ui/js/selectors/claims.js | 32 ++++++++++++++++++++++++------- 2 files changed, 42 insertions(+), 30 deletions(-) diff --git a/ui/js/reducers/claims.js b/ui/js/reducers/claims.js index c6c5801d4..a5f6d4d09 100644 --- a/ui/js/reducers/claims.js +++ b/ui/js/reducers/claims.js @@ -7,23 +7,19 @@ const defaultState = {}; reducers[types.RESOLVE_URI_COMPLETED] = function(state, action) { const { uri, certificate, claim } = action.data; - const newClaims = Object.assign({}, state.claimsByUri); + const byUri = Object.assign({}, state.claimsByUri); + const byId = Object.assign({}, state.byId); - newClaims[uri] = claim; - - //This needs a sanity boost... - if (certificate !== undefined && claim === undefined) { - const uriParts = lbryuri.parse(uri); - // newChannelClaims[uri] = certificate - if (claim === undefined) { - newClaims[uri] = certificate; - } + if (claim) { + byId[claim.claim_id] = claim; + byUri[uri] = claim.claim_id; } return Object.assign({}, state, { - claimsByUri: newClaims, + byId, + claimsByUri: byUri }); -}; +} reducers[types.RESOLVE_URI_CANCELED] = function(state, action) { const uri = action.data.uri; @@ -41,26 +37,24 @@ reducers[types.FETCH_CLAIM_LIST_MINE_STARTED] = function(state, action) { }; reducers[types.FETCH_CLAIM_LIST_MINE_COMPLETED] = function(state, action) { - const { claims } = action.data; + const { + claims, + } = action.data; const myClaims = new Set(state.myClaims); const byUri = Object.assign({}, state.claimsByUri); + const byId = Object.assign({}, state.byId); claims.forEach(claim => { - const uri = lbryuri.build({ - contentName: claim.name, - claimId: claim.claim_id, - claimSequence: claim.nout, - }); - myClaims.add(uri); - byUri[uri] = claim; - }); + myClaims.add(claim.claim_id); + byId[claim.claim_id] = claim; + }) return Object.assign({}, state, { isClaimListMinePending: false, myClaims: myClaims, - claimsByUri: byUri, + byId, }); -}; +} // reducers[types.FETCH_CHANNEL_CLAIMS_STARTED] = function(state, action) { // const { diff --git a/ui/js/selectors/claims.js b/ui/js/selectors/claims.js index 0a4c9b61a..567b7ef46 100644 --- a/ui/js/selectors/claims.js +++ b/ui/js/selectors/claims.js @@ -1,12 +1,30 @@ import { createSelector } from "reselect"; import lbryuri from "lbryuri"; -export const _selectState = state => state.claims || {}; +const _selectState = state => state.claims || {}; + +export const selectClaimsById = createSelector( + _selectState, + (state) => state.byId || {} +); export const selectClaimsByUri = createSelector( _selectState, - state => state.claimsByUri || {} -); + selectClaimsById, + (state, byId) => { + const byUri = state.claimsByUri || {}; + const claims = {}; + + Object.keys(byUri).forEach(uri => { + const claimId = byUri[uri]; + const claim = byId[claimId]; + + claims[uri] = claim; + }) + + return claims; + } +) export const selectAllClaimsByChannel = createSelector( _selectState, @@ -74,14 +92,14 @@ export const selectMyClaims = createSelector( export const selectMyClaimsOutpoints = createSelector( selectMyClaims, - selectClaimsByUri, - (claimIds, byUri) => { + selectClaimsById, + (claimIds, byId) => { const outpoints = []; claimIds.forEach(claimId => { - const claim = byUri[claimId]; + const claim = byId[claimId]; if (claim) outpoints.push(`${claim.txid}:${claim.nout}`); - }); + }) return outpoints; } -- 2.45.2 From c023a41a2873053985a306c819caf049ef75d2d8 Mon Sep 17 00:00:00 2001 From: 6ea86b96 <6ea86b96@gmail.com> Date: Mon, 5 Jun 2017 15:37:37 +0700 Subject: [PATCH 2/5] Stop cost info getting into an infinite loop --- ui/js/actions/cost_info.js | 16 +--------------- ui/js/component/filePrice/index.js | 9 +++++++-- ui/js/component/filePrice/view.jsx | 10 ++++++++-- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/ui/js/actions/cost_info.js b/ui/js/actions/cost_info.js index e8485deff..9f7506b5f 100644 --- a/ui/js/actions/cost_info.js +++ b/ui/js/actions/cost_info.js @@ -10,23 +10,9 @@ export function doFetchCostInfoForUri(uri) { return function(dispatch, getState) { const state = getState(), claim = selectClaimsByUri(state)[uri], - isResolving = selectResolvingUris(state).indexOf(uri) !== -1, isGenerous = selectSettingsIsGenerous(state); - if (claim === null) { - //claim doesn't exist, nothing to fetch a cost for - return; - } - - if (!claim) { - setTimeout(() => { - dispatch(doFetchCostInfoForUri(uri)); - }, 1000); - if (!isResolving) { - dispatch(doResolveUri(uri)); - } - return; - } + if (!claim) return null function begin() { dispatch({ diff --git a/ui/js/component/filePrice/index.js b/ui/js/component/filePrice/index.js index d97249e3f..aa8f692aa 100644 --- a/ui/js/component/filePrice/index.js +++ b/ui/js/component/filePrice/index.js @@ -4,16 +4,21 @@ import { doFetchCostInfoForUri } from "actions/cost_info"; import { makeSelectCostInfoForUri, makeSelectFetchingCostInfoForUri, -} from "selectors/cost_info"; -import FilePrice from "./view"; +} from 'selectors/cost_info' +import { + makeSelectClaimForUri, +} from 'selectors/claims' +import FilePrice from './view' const makeSelect = () => { const selectCostInfoForUri = makeSelectCostInfoForUri(); const selectFetchingCostInfoForUri = makeSelectFetchingCostInfoForUri(); + const selectClaim = makeSelectClaimForUri(); const select = (state, props) => ({ costInfo: selectCostInfoForUri(state, props), fetching: selectFetchingCostInfoForUri(state, props), + claim: selectClaim(state, props), }); return select; diff --git a/ui/js/component/filePrice/view.jsx b/ui/js/component/filePrice/view.jsx index 4bbb163dc..a807db071 100644 --- a/ui/js/component/filePrice/view.jsx +++ b/ui/js/component/filePrice/view.jsx @@ -11,9 +11,15 @@ class FilePrice extends React.Component { } fetchCost(props) { - const { costInfo, fetchCostInfo, uri, fetching } = props; + const { + costInfo, + fetchCostInfo, + uri, + fetching, + claim, + } = props; - if (costInfo === undefined && !fetching) { + if (costInfo === undefined && !fetching && claim) { fetchCostInfo(uri); } } -- 2.45.2 From 72137f51d2ac31b4e5a08dc676f5c7bed32f6cc2 Mon Sep 17 00:00:00 2001 From: 6ea86b96 <6ea86b96@gmail.com> Date: Mon, 5 Jun 2017 15:48:06 +0700 Subject: [PATCH 3/5] Fix resolving uris in file tile --- ui/js/component/fileTile/view.jsx | 12 ++++++++---- ui/js/reducers/claims.js | 2 ++ ui/js/selectors/claims.js | 12 ++++++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/ui/js/component/fileTile/view.jsx b/ui/js/component/fileTile/view.jsx index d76d75ec2..34b1476dd 100644 --- a/ui/js/component/fileTile/view.jsx +++ b/ui/js/component/fileTile/view.jsx @@ -19,11 +19,15 @@ class FileTile extends React.Component { } componentDidMount() { - const { isResolvingUri, resolveUri, claim, uri } = this.props; + this.resolve(this.props); + } - if (!isResolvingUri && !claim && uri) { - resolveUri(uri); - } + componentWillReceiveProps(nextProps) { + this.resolve(nextProps); + } + + resolve({ isResolvingUri, claim, uri, resolveUri }) { + if (!isResolvingUri && claim === undefined && uri) resolveUri(uri); } handleMouseOver() { diff --git a/ui/js/reducers/claims.js b/ui/js/reducers/claims.js index a5f6d4d09..80f79b22f 100644 --- a/ui/js/reducers/claims.js +++ b/ui/js/reducers/claims.js @@ -13,6 +13,8 @@ reducers[types.RESOLVE_URI_COMPLETED] = function(state, action) { if (claim) { byId[claim.claim_id] = claim; byUri[uri] = claim.claim_id; + } else { + byUri[uri] = null; } return Object.assign({}, state, { diff --git a/ui/js/selectors/claims.js b/ui/js/selectors/claims.js index 567b7ef46..11e3b1e86 100644 --- a/ui/js/selectors/claims.js +++ b/ui/js/selectors/claims.js @@ -17,9 +17,17 @@ export const selectClaimsByUri = createSelector( Object.keys(byUri).forEach(uri => { const claimId = byUri[uri]; - const claim = byId[claimId]; - claims[uri] = claim; + // NOTE returning a null claim allows us to differentiate between an + // undefined (never fetched claim) and one which just doesn't exist. Not + // the cleanest solution but couldn't think of anything better right now + if (claimId === null) { + claims[uri] = null; + } else { + const claim = byId[claimId]; + + claims[uri] = claim; + } }) return claims; -- 2.45.2 From 732c9c3bd3755de5588ddb25c48bd1822b91d620 Mon Sep 17 00:00:00 2001 From: 6ea86b96 <6ea86b96@gmail.com> Date: Tue, 6 Jun 2017 11:44:23 +0700 Subject: [PATCH 4/5] Make channel pages work again --- ui/js/reducers/claims.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ui/js/reducers/claims.js b/ui/js/reducers/claims.js index 80f79b22f..d3cde592e 100644 --- a/ui/js/reducers/claims.js +++ b/ui/js/reducers/claims.js @@ -13,6 +13,9 @@ reducers[types.RESOLVE_URI_COMPLETED] = function(state, action) { if (claim) { byId[claim.claim_id] = claim; byUri[uri] = claim.claim_id; + } else if (claim === undefined && certificate !== undefined) { + byId[certificate.claim_id] = certificate; + byUri[uri] = certificate.claim_id; } else { byUri[uri] = null; } -- 2.45.2 From 626167995acd4b953c371936e863822becf11d45 Mon Sep 17 00:00:00 2001 From: 6ea86b96 <6ea86b96@gmail.com> Date: Wed, 7 Jun 2017 09:12:40 +0700 Subject: [PATCH 5/5] Ignore .vimrc --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 17a8ad330..022473023 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ dist .#* build/daemon.zip +.vimrc -- 2.45.2