From 7029ba156871ebbbfa2898237eda0d3a5a6e6f59 Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Sat, 23 May 2020 01:20:55 +0200 Subject: [PATCH] fix(ui): reload existing activity history on refresh fix #3174 --- .../ActivityActions/ActivityActions.js | 6 +-- .../containers/Activity/ActivityActions.js | 4 +- renderer/reducers/activity/reducer.js | 52 ++++++++++++++++--- 3 files changed, 49 insertions(+), 13 deletions(-) diff --git a/renderer/components/Activity/ActivityActions/ActivityActions.js b/renderer/components/Activity/ActivityActions/ActivityActions.js index f9fb2ad6b7e..4e11d30e194 100644 --- a/renderer/components/Activity/ActivityActions/ActivityActions.js +++ b/renderer/components/Activity/ActivityActions/ActivityActions.js @@ -14,7 +14,7 @@ const ActivityActions = ({ filters, searchText, changeFilter, - fetchActivityHistory, + reloadActivityHistory, updateSearchText, isCustomFilter, intl, @@ -39,7 +39,7 @@ const ActivityActions = ({ mx={3} /> - + @@ -47,11 +47,11 @@ const ActivityActions = ({ ActivityActions.propTypes = { changeFilter: PropTypes.func.isRequired, - fetchActivityHistory: PropTypes.func.isRequired, filter: PropTypes.object.isRequired, filters: PropTypes.array.isRequired, intl: intlShape.isRequired, isCustomFilter: PropTypes.bool, + reloadActivityHistory: PropTypes.func.isRequired, searchText: PropTypes.string, updateSearchText: PropTypes.func.isRequired, } diff --git a/renderer/containers/Activity/ActivityActions.js b/renderer/containers/Activity/ActivityActions.js index 289da295ebb..b555b15ec0e 100644 --- a/renderer/containers/Activity/ActivityActions.js +++ b/renderer/containers/Activity/ActivityActions.js @@ -1,7 +1,7 @@ import { connect } from 'react-redux' import { changeFilter, - fetchActivityHistory, + reloadActivityHistory, updateSearchText, activitySelectors, } from 'reducers/activity' @@ -9,7 +9,7 @@ import ActivityActions from 'components/Activity/ActivityActions' const mapDispatchToProps = { changeFilter, - fetchActivityHistory, + reloadActivityHistory, updateSearchText, } diff --git a/renderer/reducers/activity/reducer.js b/renderer/reducers/activity/reducer.js index a57031533af..512b3817b95 100644 --- a/renderer/reducers/activity/reducer.js +++ b/renderer/reducers/activity/reducer.js @@ -73,6 +73,7 @@ const initialState = { // activity paginator object. must be reset for each wallet login /** @type {Function | null} */ let paginator = null +let loadedPages = 0 /** * getPaginator - Returns current activity paginator object. This acts as a singleton @@ -201,17 +202,37 @@ export const hideActivityModal = () => dispatch => { dispatch(closeModal('ACTIVITY_MODAL')) } +/** + * resetActivity - Reset user activity history. + * + * @returns {() => void} Thunk + */ +export const resetActivity = () => () => { + paginator = null +} + /** * loadNextPage - Loads next activity page if it's available. * + * @param {number} pageSize Pagesize (defaults to config.activity.pageSize) + * @param {boolean} reload Reload existing pages * @returns {(dispatch:Function, getState:Function) => Promise} Thunk */ -export const loadNextPage = () => async (dispatch, getState) => { +export const loadNextPage = (pageSize = config.activity.pageSize, reload = false) => async ( + dispatch, + getState +) => { + if (reload) { + dispatch(resetActivity()) + } const thisPaginator = getPaginator() + if (hasNextPage(getState())) { - const { items, hasNextPage: paginatorHasNextPage } = await thisPaginator( - config.activity.pageSize - ) + const { items, hasNextPage: paginatorHasNextPage } = await thisPaginator(pageSize) + + if (!reload) { + loadedPages += 1 + } const getItemType = item => { if (item.destAddresses) { @@ -242,7 +263,10 @@ export const fetchActivityHistory = () => dispatch => { dispatch(fetchDescribeNetwork()) dispatch(fetchChannels()) dispatch(fetchBalance()) + + dispatch(resetActivity()) dispatch(loadNextPage()) + dispatch({ type: FETCH_ACTIVITY_HISTORY_SUCCESS }) } catch (error) { dispatch({ type: FETCH_ACTIVITY_HISTORY_FAILURE, error }) @@ -250,12 +274,24 @@ export const fetchActivityHistory = () => dispatch => { } /** - * resetActivity - Reset user activity history. + * reloadActivityHistory - Reload activity history, including Balance, Payments, Invoices, Transactions etc. * - * @returns {() => void} Thunk + * @returns {(dispatch:Function) => void} Thunk */ -export const resetActivity = () => () => { - paginator = null +export const reloadActivityHistory = () => dispatch => { + dispatch({ type: FETCH_ACTIVITY_HISTORY }) + try { + dispatch(fetchDescribeNetwork()) + dispatch(fetchChannels()) + dispatch(fetchBalance()) + + const itemsToLoad = loadedPages * config.activity.pageSize + dispatch(loadNextPage(itemsToLoad, true)) + + dispatch({ type: FETCH_ACTIVITY_HISTORY_SUCCESS }) + } catch (error) { + dispatch({ type: FETCH_ACTIVITY_HISTORY_FAILURE, error }) + } } // ------------------------------------