Uses a constant for PAGE_SIZE #2089

Merged
jessopb merged 2 commits from pageSize into master 2018-11-05 16:22:47 +01:00
7 changed files with 117 additions and 113 deletions

View file

@ -49,7 +49,7 @@
"formik": "^0.10.4", "formik": "^0.10.4",
"hast-util-sanitize": "^1.1.2", "hast-util-sanitize": "^1.1.2",
"keytar": "^4.2.1", "keytar": "^4.2.1",
"lbry-redux": "lbryio/lbry-redux#dd26422a86a37b5a492dc0702269ad6fc04ecdd7", "lbry-redux": "lbryio/lbry-redux#aa10240bc1e90dff299821e31a88edcb4c5fd295",
"lbryinc": "lbryio/lbryinc#7a458ea13ceceffa0191e73139f94e5c953f22b1", "lbryinc": "lbryio/lbryinc#7a458ea13ceceffa0191e73139f94e5c953f22b1",
"localforage": "^1.7.1", "localforage": "^1.7.1",
"mammoth": "^1.4.6", "mammoth": "^1.4.6",

View file

@ -2,3 +2,4 @@ export const MINIMUM_PUBLISH_BID = 0.00000001;
export const CHANNEL_ANONYMOUS = 'anonymous'; export const CHANNEL_ANONYMOUS = 'anonymous';
export const CHANNEL_NEW = 'new'; export const CHANNEL_NEW = 'new';
export const PAGE_SIZE = 20;

View file

@ -1,15 +1,16 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { doFetchClaimsByChannel, doFetchClaimCountByChannel } from 'redux/actions/content'; import { doFetchClaimsByChannel, doFetchClaimCountByChannel } from 'redux/actions/content';
import { PAGE_SIZE } from 'constants/claim';
import { import {
makeSelectClaimForUri, makeSelectClaimForUri,
makeSelectClaimsInChannelForCurrentPage, makeSelectClaimsInChannelForCurrentPage,
makeSelectFetchingChannelClaims, makeSelectFetchingChannelClaims,
makeSelectCurrentParam, makeSelectCurrentParam,
makeSelectClaimIsMine, makeSelectClaimIsMine,
makeSelectTotalPagesForChannel,
selectCurrentParams, selectCurrentParams,
} from 'lbry-redux'; } from 'lbry-redux';
import { doNavigate } from 'redux/actions/navigation'; import { doNavigate } from 'redux/actions/navigation';
import { makeSelectTotalPagesForChannel } from 'redux/selectors/content';
import ChannelPage from './view'; import ChannelPage from './view';
const select = (state, props) => ({ const select = (state, props) => ({
@ -18,7 +19,7 @@ const select = (state, props) => ({
fetching: makeSelectFetchingChannelClaims(props.uri)(state), fetching: makeSelectFetchingChannelClaims(props.uri)(state),
page: makeSelectCurrentParam('page')(state), page: makeSelectCurrentParam('page')(state),
params: selectCurrentParams(state), params: selectCurrentParams(state),
totalPages: makeSelectTotalPagesForChannel(props.uri)(state), totalPages: makeSelectTotalPagesForChannel(props.uri, PAGE_SIZE)(state),
channelIsMine: makeSelectClaimIsMine(props.uri)(state), channelIsMine: makeSelectClaimIsMine(props.uri)(state),
}); });

View file

@ -1,5 +1,6 @@
// @flow // @flow
import * as NOTIFICATION_TYPES from 'constants/subscriptions'; import * as NOTIFICATION_TYPES from 'constants/subscriptions';
import { PAGE_SIZE } from 'constants/claim';
import { ipcRenderer } from 'electron'; import { ipcRenderer } from 'electron';
import { doAlertError } from 'redux/actions/app'; import { doAlertError } from 'redux/actions/app';
import { doNavigate } from 'redux/actions/navigation'; import { doNavigate } from 'redux/actions/navigation';
@ -293,38 +294,40 @@ export function doFetchClaimsByChannel(uri, page, pageSize) {
data: { uri, page }, data: { uri, page },
}); });
Lbry.claim_list_by_channel({ uri, page: page || 1, page_size: pageSize || 20 }).then(result => { Lbry.claim_list_by_channel({ uri, page: page || 1, page_size: pageSize || PAGE_SIZE }).then(
const claimResult = result[uri] || {}; result => {
const { claims_in_channel: claimsInChannel, returned_page: returnedPage } = claimResult; const claimResult = result[uri] || {};
const { claims_in_channel: claimsInChannel, returned_page: returnedPage } = claimResult;
if (claimsInChannel && claimsInChannel.length) { if (claimsInChannel && claimsInChannel.length) {
const latest = claimsInChannel[0]; const latest = claimsInChannel[0];
dispatch( dispatch(
setSubscriptionLatest( setSubscriptionLatest(
{ {
channelName: latest.channel_name, channelName: latest.channel_name,
uri: buildURI( uri: buildURI(
{ {
contentName: latest.channel_name, contentName: latest.channel_name,
claimId: latest.value.publisherSignature.certificateId, claimId: latest.value.publisherSignature.certificateId,
}, },
false false
), ),
}, },
buildURI({ contentName: latest.name, claimId: latest.claim_id }, false) buildURI({ contentName: latest.name, claimId: latest.claim_id }, false)
) )
); );
}
dispatch({
type: ACTIONS.FETCH_CHANNEL_CLAIMS_COMPLETED,
data: {
uri,
claims: claimsInChannel || [],
page: returnedPage || undefined,
},
});
} }
);
dispatch({
type: ACTIONS.FETCH_CHANNEL_CLAIMS_COMPLETED,
data: {
uri,
claims: claimsInChannel || [],
page: returnedPage || undefined,
},
});
});
}; };
} }

View file

@ -8,6 +8,7 @@ import type {
ViewMode, ViewMode,
UnreadSubscription, UnreadSubscription,
} from 'types/subscription'; } from 'types/subscription';
import { PAGE_SIZE } from 'constants/claim';
import * as ACTIONS from 'constants/action_types'; import * as ACTIONS from 'constants/action_types';
import * as SETTINGS from 'constants/settings'; import * as SETTINGS from 'constants/settings';
import * as NOTIFICATION_TYPES from 'constants/subscriptions'; import * as NOTIFICATION_TYPES from 'constants/subscriptions';
@ -223,87 +224,92 @@ export const doCheckSubscription = (subscriptionUri: string, shouldNotify?: bool
); );
} }
Lbry.claim_list_by_channel({ uri: subscriptionUri, page: 1 }).then(claimListByChannel => { // We may be duplicating calls here. Can this logic be baked into doFetchClaimsByChannel?
const claimResult = claimListByChannel[subscriptionUri] || {}; Lbry.claim_list_by_channel({ uri: subscriptionUri, page: 1, page_size: PAGE_SIZE }).then(
const { claims_in_channel: claimsInChannel } = claimResult; claimListByChannel => {
const claimResult = claimListByChannel[subscriptionUri] || {};
const { claims_in_channel: claimsInChannel } = claimResult;
// may happen if subscribed to an abandoned channel or an empty channel // may happen if subscribed to an abandoned channel or an empty channel
if (!claimsInChannel || !claimsInChannel.length) { if (!claimsInChannel || !claimsInChannel.length) {
return; return;
} }
// Determine if the latest subscription currently saved is actually the latest subscription // Determine if the latest subscription currently saved is actually the latest subscription
const latestIndex = claimsInChannel.findIndex( const latestIndex = claimsInChannel.findIndex(
claim => `${claim.name}#${claim.claim_id}` === savedSubscription.latest claim => `${claim.name}#${claim.claim_id}` === savedSubscription.latest
); );
// If latest is -1, it is a newly subscribed channel or there have been 10+ claims published since last viewed // If latest is -1, it is a newly subscribed channel or there have been 10+ claims published since last viewed
const latestIndexToNotify = latestIndex === -1 ? 10 : latestIndex; const latestIndexToNotify = latestIndex === -1 ? 10 : latestIndex;
// If latest is 0, nothing has changed // If latest is 0, nothing has changed
// Do not download/notify about new content, it would download/notify 10 claims per channel // Do not download/notify about new content, it would download/notify 10 claims per channel
if (latestIndex !== 0 && savedSubscription.latest) { if (latestIndex !== 0 && savedSubscription.latest) {
let downloadCount = 0; let downloadCount = 0;
const newUnread = []; const newUnread = [];
claimsInChannel.slice(0, latestIndexToNotify).forEach(claim => { claimsInChannel.slice(0, latestIndexToNotify).forEach(claim => {
const uri = buildURI({ contentName: claim.name, claimId: claim.claim_id }, true); const uri = buildURI({ contentName: claim.name, claimId: claim.claim_id }, true);
const shouldDownload = const shouldDownload =
shouldAutoDownload && shouldAutoDownload &&
Boolean(downloadCount < SUBSCRIPTION_DOWNLOAD_LIMIT && !claim.value.stream.metadata.fee); Boolean(
downloadCount < SUBSCRIPTION_DOWNLOAD_LIMIT && !claim.value.stream.metadata.fee
);
// Add the new content to the list of "un-read" subscriptions // Add the new content to the list of "un-read" subscriptions
if (shouldNotify) { if (shouldNotify) {
newUnread.push(uri); newUnread.push(uri);
} }
if (shouldDownload) { if (shouldDownload) {
downloadCount += 1; downloadCount += 1;
dispatch(doPurchaseUri(uri, { cost: 0 }, true)); dispatch(doPurchaseUri(uri, { cost: 0 }, true));
} }
}); });
dispatch(
doUpdateUnreadSubscriptions(
subscriptionUri,
newUnread,
downloadCount > 0 ? NOTIFICATION_TYPES.DOWNLOADING : NOTIFICATION_TYPES.NOTIFY_ONLY
)
);
}
// Set the latest piece of content for a channel
// This allows the app to know if there has been new content since it was last set
dispatch( dispatch(
doUpdateUnreadSubscriptions( setSubscriptionLatest(
subscriptionUri, {
newUnread, channelName: claimsInChannel[0].channel_name,
downloadCount > 0 ? NOTIFICATION_TYPES.DOWNLOADING : NOTIFICATION_TYPES.NOTIFY_ONLY uri: buildURI(
{
channelName: claimsInChannel[0].channel_name,
claimId: claimsInChannel[0].claim_id,
},
false
),
},
buildURI(
{ contentName: claimsInChannel[0].name, claimId: claimsInChannel[0].claim_id },
false
)
) )
); );
}
// Set the latest piece of content for a channel // calling FETCH_CHANNEL_CLAIMS_COMPLETED after not calling STARTED
// This allows the app to know if there has been new content since it was last set // means it will delete a non-existant fetchingChannelClaims[uri]
dispatch( dispatch({
setSubscriptionLatest( type: ACTIONS.FETCH_CHANNEL_CLAIMS_COMPLETED,
{ data: {
channelName: claimsInChannel[0].channel_name, uri: subscriptionUri,
uri: buildURI( claims: claimsInChannel || [],
{ page: 1,
channelName: claimsInChannel[0].channel_name,
claimId: claimsInChannel[0].claim_id,
},
false
),
}, },
buildURI( });
{ contentName: claimsInChannel[0].name, claimId: claimsInChannel[0].claim_id }, }
false );
)
)
);
// calling FETCH_CHANNEL_CLAIMS_COMPLETED after not calling STARTED
// means it will delete a non-existant fetchingChannelClaims[uri]
dispatch({
type: ACTIONS.FETCH_CHANNEL_CLAIMS_COMPLETED,
data: {
uri: subscriptionUri,
claims: claimsInChannel || [],
page: 1,
},
});
});
}; };
export const doChannelSubscribe = (subscription: Subscription) => ( export const doChannelSubscribe = (subscription: Subscription) => (

View file

@ -14,12 +14,6 @@ export const selectChannelClaimCounts = createSelector(
export const makeSelectTotalItemsForChannel = uri => export const makeSelectTotalItemsForChannel = uri =>
createSelector(selectChannelClaimCounts, byUri => byUri && byUri[uri]); createSelector(selectChannelClaimCounts, byUri => byUri && byUri[uri]);
export const makeSelectTotalPagesForChannel = uri =>
createSelector(
selectChannelClaimCounts,
byUri => byUri && byUri[uri] && Math.ceil(byUri[uri] / 10)
);
export const selectRewardContentClaimIds = createSelector( export const selectRewardContentClaimIds = createSelector(
selectState, selectState,
state => state.rewardedContentClaimIds state => state.rewardedContentClaimIds
@ -52,9 +46,8 @@ export const makeSelectHistoryForPage = page =>
if (claimAtUri) { if (claimAtUri) {
return { lastViewed, uri, ...claimAtUri }; return { lastViewed, uri, ...claimAtUri };
} else {
return historyItem;
} }
return historyItem;
}); });
}); });

View file

@ -5663,16 +5663,16 @@ lazy-val@^1.0.3:
version "1.0.3" version "1.0.3"
resolved "https://registry.yarnpkg.com/lazy-val/-/lazy-val-1.0.3.tgz#bb97b200ef00801d94c317e29dc6ed39e31c5edc" resolved "https://registry.yarnpkg.com/lazy-val/-/lazy-val-1.0.3.tgz#bb97b200ef00801d94c317e29dc6ed39e31c5edc"
lbry-redux@lbryio/lbry-redux#0e13dd1972e3b40821fee2f9f06e1a0631913aa9: lbry-redux@lbryio/lbry-redux#2375860d6269d0369418879c2531b1d48c4e47f2:
version "0.0.1" version "0.0.1"
resolved "https://codeload.github.com/lbryio/lbry-redux/tar.gz/0e13dd1972e3b40821fee2f9f06e1a0631913aa9" resolved "https://codeload.github.com/lbryio/lbry-redux/tar.gz/2375860d6269d0369418879c2531b1d48c4e47f2"
dependencies: dependencies:
proxy-polyfill "0.1.6" proxy-polyfill "0.1.6"
reselect "^3.0.0" reselect "^3.0.0"
lbry-redux@lbryio/lbry-redux#2375860d6269d0369418879c2531b1d48c4e47f2: lbry-redux@lbryio/lbry-redux#aa10240bc1e90dff299821e31a88edcb4c5fd295:
version "0.0.1" version "0.0.1"
resolved "https://codeload.github.com/lbryio/lbry-redux/tar.gz/2375860d6269d0369418879c2531b1d48c4e47f2" resolved "https://codeload.github.com/lbryio/lbry-redux/tar.gz/aa10240bc1e90dff299821e31a88edcb4c5fd295"
dependencies: dependencies:
proxy-polyfill "0.1.6" proxy-polyfill "0.1.6"
reselect "^3.0.0" reselect "^3.0.0"