Skip to content

Commit

Permalink
fix(ui): reload existing activity history on refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfelton committed May 23, 2020
1 parent b3bf9de commit 40a4784
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const ActivityActions = ({
filters,
searchText,
changeFilter,
fetchActivityHistory,
reloadActivityHistory,
updateSearchText,
isCustomFilter,
intl,
Expand All @@ -39,19 +39,19 @@ const ActivityActions = ({
mx={3}
/>

<ActivityRefresh mx={3} onClick={fetchActivityHistory} />
<ActivityRefresh mx={3} onClick={reloadActivityHistory} />
</Flex>
</Flex>
</Card>
)

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,
}
Expand Down
4 changes: 2 additions & 2 deletions renderer/containers/Activity/ActivityActions.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { connect } from 'react-redux'
import {
changeFilter,
fetchActivityHistory,
reloadActivityHistory,
updateSearchText,
activitySelectors,
} from 'reducers/activity'
import ActivityActions from 'components/Activity/ActivityActions'

const mapDispatchToProps = {
changeFilter,
fetchActivityHistory,
reloadActivityHistory,
updateSearchText,
}

Expand Down
51 changes: 42 additions & 9 deletions renderer/reducers/activity/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -204,14 +205,21 @@ export const hideActivityModal = () => dispatch => {
/**
* 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<void>} Thunk
*/
export const loadNextPage = () => async (dispatch, getState) => {
export const loadNextPage = (pageSize = config.activity.pageSize, reload = false) => async (
dispatch,
getState
) => {
const thisPaginator = getPaginator()
if (hasNextPage(getState())) {
const { items, hasNextPage: paginatorHasNextPage } = await thisPaginator(
config.activity.pageSize
)
if (hasNextPage(getState()) || reload) {
const { items, hasNextPage: paginatorHasNextPage } = await thisPaginator(pageSize)

if (!reload) {
loadedPages += 1
}

const getItemType = item => {
if (item.destAddresses) {
Expand All @@ -231,6 +239,15 @@ export const loadNextPage = () => async (dispatch, getState) => {
}
}

/**
* resetActivity - Reset user activity history.
*
* @returns {() => void} Thunk
*/
export const resetActivity = () => () => {
paginator = null
}

/**
* fetchActivityHistory - Fetch user activity history, including Balance, Payments, Invoices, Transactions etc.
*
Expand All @@ -242,20 +259,36 @@ 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 })
}
}

/**
* 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(resetActivity())
dispatch(loadNextPage(itemsToLoad, true))

dispatch({ type: FETCH_ACTIVITY_HISTORY_SUCCESS })
} catch (error) {
dispatch({ type: FETCH_ACTIVITY_HISTORY_FAILURE, error })
}
}

// ------------------------------------
Expand Down

0 comments on commit 40a4784

Please sign in to comment.