From a31e064c3eeafec1a304ebb6b5f8fab6a0db4d11 Mon Sep 17 00:00:00 2001 From: Jeremy Kauffman Date: Thu, 24 Aug 2017 17:12:23 -0400 Subject: [PATCH] fix pagination of channels --- app/package.json | 2 +- ui/js/actions/content.js | 26 ++++++++++++++++++++++---- ui/js/constants/action_types.js | 4 ++++ ui/js/page/channel/index.js | 6 +++++- ui/js/page/channel/view.jsx | 11 ++++++++--- ui/js/reducers/content.js | 20 ++++++++++++++++---- 6 files changed, 56 insertions(+), 13 deletions(-) diff --git a/app/package.json b/app/package.json index 59f2fc098..7739fd667 100644 --- a/app/package.json +++ b/app/package.json @@ -20,7 +20,7 @@ "electron-rebuild": "^1.5.11" }, "lbrySettings": { - "lbrynetDaemonVersion": "0.15.0", + "lbrynetDaemonVersion": "0.15.1", "lbrynetDaemonUrlTemplate": "https://github.com/lbryio/lbry/releases/download/vDAEMONVER/lbrynet-daemon-vDAEMONVER-OSNAME.zip" }, "license": "MIT" diff --git a/ui/js/actions/content.js b/ui/js/actions/content.js index 144375b6e..919eccac5 100644 --- a/ui/js/actions/content.js +++ b/ui/js/actions/content.js @@ -365,9 +365,6 @@ export function doFetchClaimsByChannel(uri, page) { lbry.claim_list_by_channel({ uri, page }).then(result => { const claimResult = result[uri], claims = claimResult ? claimResult.claims_in_channel : [], - totalPages = claimResult - ? claimResult.claims_in_channel_pages - : undefined, currentPage = claimResult ? claimResult.returned_page : undefined; dispatch({ @@ -375,7 +372,6 @@ export function doFetchClaimsByChannel(uri, page) { data: { uri, claims, - totalPages, page: currentPage, }, }); @@ -383,6 +379,28 @@ export function doFetchClaimsByChannel(uri, page) { }; } +export function doFetchClaimCountByChannel(uri) { + return function(dispatch, getState) { + dispatch({ + type: types.FETCH_CHANNEL_CLAIM_COUNT_STARTED, + data: { uri }, + }); + + lbry.claim_list_by_channel({ uri }).then(result => { + const claimResult = result[uri], + totalClaims = claimResult ? claimResult.claims_in_channel : 0; + + dispatch({ + type: types.FETCH_CHANNEL_CLAIM_COUNT_COMPLETED, + data: { + uri, + totalClaims, + }, + }); + }); + }; +} + export function doFetchClaimListMine() { return function(dispatch, getState) { dispatch({ diff --git a/ui/js/constants/action_types.js b/ui/js/constants/action_types.js index 7b2a7456d..1e914d659 100644 --- a/ui/js/constants/action_types.js +++ b/ui/js/constants/action_types.js @@ -45,6 +45,10 @@ export const RESOLVE_URI_COMPLETED = "RESOLVE_URI_COMPLETED"; export const RESOLVE_URI_CANCELED = "RESOLVE_URI_CANCELED"; export const FETCH_CHANNEL_CLAIMS_STARTED = "FETCH_CHANNEL_CLAIMS_STARTED"; export const FETCH_CHANNEL_CLAIMS_COMPLETED = "FETCH_CHANNEL_CLAIMS_COMPLETED"; +export const FETCH_CHANNEL_CLAIM_COUNT_STARTED = + "FETCH_CHANNEL_CLAIM_COUNT_STARTED"; +export const FETCH_CHANNEL_CLAIM_COUNT_COMPLETED = + "FETCH_CHANNEL_CLAIM_COUNT_COMPLETED"; export const FETCH_CLAIM_LIST_MINE_STARTED = "FETCH_CLAIM_LIST_MINE_STARTED"; export const FETCH_CLAIM_LIST_MINE_COMPLETED = "FETCH_CLAIM_LIST_MINE_COMPLETED"; diff --git a/ui/js/page/channel/index.js b/ui/js/page/channel/index.js index bce739e1e..dfd75d5fe 100644 --- a/ui/js/page/channel/index.js +++ b/ui/js/page/channel/index.js @@ -1,6 +1,9 @@ import React from "react"; import { connect } from "react-redux"; -import { doFetchClaimsByChannel } from "actions/content"; +import { + doFetchClaimsByChannel, + doFetchClaimCountByChannel, +} from "actions/content"; import { makeSelectClaimForUri, makeSelectClaimsInChannelForCurrentPage, @@ -30,6 +33,7 @@ const makeSelect = () => { const perform = dispatch => ({ fetchClaims: (uri, page) => dispatch(doFetchClaimsByChannel(uri, page)), + fetchClaimCount: uri => dispatch(doFetchClaimCountByChannel(uri)), navigate: (path, params) => dispatch(doNavigate(path, params)), }); diff --git a/ui/js/page/channel/view.jsx b/ui/js/page/channel/view.jsx index 798d38379..1d17fe8b5 100644 --- a/ui/js/page/channel/view.jsx +++ b/ui/js/page/channel/view.jsx @@ -7,17 +7,22 @@ import ReactPaginate from "react-paginate"; class ChannelPage extends React.PureComponent { componentDidMount() { - const { uri, params, fetchClaims } = this.props; + const { uri, params, fetchClaims, fetchClaimCount } = this.props; fetchClaims(uri, params.page || 1); + fetchClaimCount(uri); } componentWillReceiveProps(nextProps) { - const { params, fetching, fetchClaims } = this.props; + const { params, fetching, fetchClaims, fetchClaimCount } = this.props; const nextParams = nextProps.params; - if (fetching !== nextParams.page && params.page !== nextParams.page) + if (fetching !== nextParams.page && params.page !== nextParams.page) { fetchClaims(nextProps.uri, nextParams.page); + } + if (nextProps.uri != this.props.uri) { + fetchClaimCount(uri); + } } changePage(pageNumber) { diff --git a/ui/js/reducers/content.js b/ui/js/reducers/content.js index 62784fd0f..9d8c5867e 100644 --- a/ui/js/reducers/content.js +++ b/ui/js/reducers/content.js @@ -3,6 +3,7 @@ import * as types from "constants/action_types"; const reducers = {}; const defaultState = { rewardedContentClaimIds: [], + channelPages: {}, }; reducers[types.FETCH_FEATURED_CONTENT_STARTED] = function(state, action) { @@ -57,11 +58,22 @@ reducers[types.RESOLVE_URI_CANCELED] = reducers[ }); }; -reducers[types.FETCH_CHANNEL_CLAIMS_COMPLETED] = function(state, action) { - const channelPages = Object.assign({}, state.channelPages); - const { uri, totalPages } = action.data; +// reducers[types.FETCH_CHANNEL_CLAIMS_COMPLETED] = function(state, action) { +// const channelPages = Object.assign({}, state.channelPages); +// const { uri, claims } = action.data; +// +// channelPages[uri] = totalPages; +// +// return Object.assign({}, state, { +// channelPages, +// }); +// }; - channelPages[uri] = totalPages; +reducers[types.FETCH_CHANNEL_CLAIM_COUNT_COMPLETED] = function(state, action) { + const channelPages = Object.assign({}, state.channelPages); + const { uri, totalClaims } = action.data; + + channelPages[uri] = totalClaims / 10; return Object.assign({}, state, { channelPages,