From 66462144b2daad690abf607e698807e9520c3024 Mon Sep 17 00:00:00 2001 From: jessop Date: Sun, 22 Sep 2019 22:25:12 -0400 Subject: [PATCH 1/2] transaction pagination selectors --- dist/bundle.es.js | 19 +++++++++++++++++++ src/index.js | 3 +++ src/redux/selectors/wallet.js | 31 +++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index f2f4831..d52b81e 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -1283,6 +1283,8 @@ function doDismissError() { }; } +// + const selectState$1 = state => state.wallet || {}; const selectWalletState = selectState$1; @@ -1441,6 +1443,20 @@ const selectCurrentHeight = reselect.createSelector(selectState$1, state => stat const selectTransactionListFilter = reselect.createSelector(selectState$1, state => state.transactionListFilter || ''); +const selectFilteredTransactions = reselect.createSelector(selectTransactionItems, selectTransactionListFilter, (transactions, filter) => { + return transactions.filter(transaction => { + return filter === ALL || filter === transaction.type; + }); +}); + +const makeSelectFilteredTransactionsForPage = (page = 1) => reselect.createSelector(selectFilteredTransactions, filteredTransactions => { + const start = (Number(page) - 1) * Number(PAGE_SIZE); + const end = Number(page) * Number(PAGE_SIZE); + return filteredTransactions && filteredTransactions.length ? filteredTransactions.slice(start, end) : []; +}); + +const selectFilteredTransactionCount = reselect.createSelector(selectFilteredTransactions, filteredTransactions => filteredTransactions.length); + var _extends$2 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; function _objectWithoutProperties$1(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } @@ -5064,6 +5080,7 @@ exports.makeSelectFetchingChannelClaims = makeSelectFetchingChannelClaims; exports.makeSelectFileInfoForUri = makeSelectFileInfoForUri; exports.makeSelectFileNameForUri = makeSelectFileNameForUri; exports.makeSelectFilePartlyDownloaded = makeSelectFilePartlyDownloaded; +exports.makeSelectFilteredTransactionsForPage = makeSelectFilteredTransactionsForPage; exports.makeSelectFirstRecommendedFileForUri = makeSelectFirstRecommendedFileForUri; exports.makeSelectIsFollowingTag = makeSelectIsFollowingTag; exports.makeSelectIsUriResolving = makeSelectIsUriResolving; @@ -5132,6 +5149,8 @@ exports.selectFileInfosByOutpoint = selectFileInfosByOutpoint; exports.selectFileInfosDownloaded = selectFileInfosDownloaded; exports.selectFileListDownloadedSort = selectFileListDownloadedSort; exports.selectFileListPublishedSort = selectFileListPublishedSort; +exports.selectFilteredTransactionCount = selectFilteredTransactionCount; +exports.selectFilteredTransactions = selectFilteredTransactions; exports.selectFollowedTags = selectFollowedTags; exports.selectGettingNewAddress = selectGettingNewAddress; exports.selectHasTransactions = selectHasTransactions; diff --git a/src/index.js b/src/index.js index ce4c00a..22370ec 100644 --- a/src/index.js +++ b/src/index.js @@ -287,6 +287,9 @@ export { selectWalletUnlockSucceeded, selectWalletUnlockResult, selectTransactionListFilter, + selectFilteredTransactions, + makeSelectFilteredTransactionsForPage, + selectFilteredTransactionCount, } from 'redux/selectors/wallet'; export { diff --git a/src/redux/selectors/wallet.js b/src/redux/selectors/wallet.js index 4deab20..22e887d 100644 --- a/src/redux/selectors/wallet.js +++ b/src/redux/selectors/wallet.js @@ -1,5 +1,8 @@ +// @flow + import { createSelector } from 'reselect'; import * as TRANSACTIONS from 'constants/transaction_types'; +import { PAGE_SIZE } from 'constants/claim'; export const selectState = state => state.wallet || {}; @@ -214,6 +217,8 @@ export const selectTransactionItems = createSelector( } ); + + export const selectRecentTransactions = createSelector( selectTransactionItems, transactions => { @@ -288,3 +293,29 @@ export const selectTransactionListFilter = createSelector( selectState, state => state.transactionListFilter || '' ); + +export const selectFilteredTransactions = createSelector( + selectTransactionItems, + selectTransactionListFilter, + (transactions, filter) => { + return transactions.filter(transaction => { + return filter === TRANSACTIONS.ALL || filter === transaction.type; + }); + }); + +export const makeSelectFilteredTransactionsForPage = (page: number = 1): Array => + createSelector( + selectFilteredTransactions, + filteredTransactions => { + const start = (Number(page) - 1) * Number(PAGE_SIZE); + const end = (Number(page) * Number(PAGE_SIZE)); + return (filteredTransactions && filteredTransactions.length) + ? filteredTransactions.slice(start, end) + : []; + } + ); + +export const selectFilteredTransactionCount = createSelector( + selectFilteredTransactions, + filteredTransactions => filteredTransactions.length +); From f02c6b7a2719ceead03f1c45b4bbf26b2069a20e Mon Sep 17 00:00:00 2001 From: jessop Date: Wed, 25 Sep 2019 12:30:26 -0400 Subject: [PATCH 2/2] tx page size cleanup --- dist/bundle.es.js | 12 ++++++++++-- src/constants/transaction_list.js | 2 ++ src/index.js | 2 ++ src/redux/selectors/wallet.js | 4 +--- 4 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 src/constants/transaction_list.js diff --git a/dist/bundle.es.js b/dist/bundle.es.js index d52b81e..ba1f354 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -643,6 +643,13 @@ var transaction_types = /*#__PURE__*/Object.freeze({ ABANDON: ABANDON }); +// PAGE SIZE +const PAGE_SIZE$1 = 50; + +var transaction_list = /*#__PURE__*/Object.freeze({ + PAGE_SIZE: PAGE_SIZE$1 +}); + const SEARCH_TYPES = { FILE: 'file', CHANNEL: 'channel', @@ -1450,8 +1457,8 @@ const selectFilteredTransactions = reselect.createSelector(selectTransactionItem }); const makeSelectFilteredTransactionsForPage = (page = 1) => reselect.createSelector(selectFilteredTransactions, filteredTransactions => { - const start = (Number(page) - 1) * Number(PAGE_SIZE); - const end = Number(page) * Number(PAGE_SIZE); + const start = (Number(page) - 1) * Number(PAGE_SIZE$1); + const end = Number(page) * Number(PAGE_SIZE$1); return filteredTransactions && filteredTransactions.length ? filteredTransactions.slice(start, end) : []; }); @@ -4988,6 +4995,7 @@ exports.SETTINGS = settings; exports.SORT_OPTIONS = sort_options; exports.THUMBNAIL_STATUSES = thumbnail_upload_statuses; exports.TRANSACTIONS = transaction_types; +exports.TX_LIST = transaction_list; exports.batchActions = batchActions; exports.blockedReducer = blockedReducer; exports.buildURI = buildURI; diff --git a/src/constants/transaction_list.js b/src/constants/transaction_list.js new file mode 100644 index 0000000..c609b05 --- /dev/null +++ b/src/constants/transaction_list.js @@ -0,0 +1,2 @@ +// PAGE SIZE +export const PAGE_SIZE = 50; diff --git a/src/index.js b/src/index.js index 22370ec..e7f118a 100644 --- a/src/index.js +++ b/src/index.js @@ -6,6 +6,7 @@ import * as SETTINGS from 'constants/settings'; import * as SORT_OPTIONS from 'constants/sort_options'; import * as THUMBNAIL_STATUSES from 'constants/thumbnail_upload_statuses'; import * as TRANSACTIONS from 'constants/transaction_types'; +import * as TX_LIST from 'constants/transaction_list'; import { SEARCH_TYPES, SEARCH_OPTIONS } from 'constants/search'; import { DEFAULT_KNOWN_TAGS, DEFAULT_FOLLOWED_TAGS, MATURE_TAGS } from 'constants/tags'; import Lbry from 'lbry'; @@ -21,6 +22,7 @@ export { SEARCH_OPTIONS, SETTINGS, TRANSACTIONS, + TX_LIST, SORT_OPTIONS, PAGES, DEFAULT_KNOWN_TAGS, diff --git a/src/redux/selectors/wallet.js b/src/redux/selectors/wallet.js index 22e887d..05074f3 100644 --- a/src/redux/selectors/wallet.js +++ b/src/redux/selectors/wallet.js @@ -2,7 +2,7 @@ import { createSelector } from 'reselect'; import * as TRANSACTIONS from 'constants/transaction_types'; -import { PAGE_SIZE } from 'constants/claim'; +import { PAGE_SIZE } from 'constants/transaction_list'; export const selectState = state => state.wallet || {}; @@ -217,8 +217,6 @@ export const selectTransactionItems = createSelector( } ); - - export const selectRecentTransactions = createSelector( selectTransactionItems, transactions => {