|
|
@ -48,6 +48,8 @@ export const asyncInitialState = { |
|
|
|
loading: false, |
|
|
|
loading: false, |
|
|
|
/* if there was an error fetching items */ |
|
|
|
/* if there was an error fetching items */ |
|
|
|
requestError: false, |
|
|
|
requestError: false, |
|
|
|
|
|
|
|
/* if response has no items */ |
|
|
|
|
|
|
|
emptyResponse: false, |
|
|
|
/* if it is loading the first page */ |
|
|
|
/* if it is loading the first page */ |
|
|
|
loadingFirstPage: true, |
|
|
|
loadingFirstPage: true, |
|
|
|
/* link to the next page */ |
|
|
|
/* link to the next page */ |
|
|
@ -90,6 +92,7 @@ export function asyncReducer (state = asyncInitialState, action) { |
|
|
|
|
|
|
|
|
|
|
|
return Object.assign({}, state, { |
|
|
|
return Object.assign({}, state, { |
|
|
|
requestError: false, |
|
|
|
requestError: false, |
|
|
|
|
|
|
|
emptyResponse: action.items.length === 0, |
|
|
|
items: action.items, |
|
|
|
items: action.items, |
|
|
|
nextPagePath: action.nextPagePath, |
|
|
|
nextPagePath: action.nextPagePath, |
|
|
|
prevPagePath: prevPagePath |
|
|
|
prevPagePath: prevPagePath |
|
|
@ -169,6 +172,10 @@ export const elements = { |
|
|
|
}, |
|
|
|
}, |
|
|
|
'[data-async-listing] [data-next-page-button]': { |
|
|
|
'[data-async-listing] [data-next-page-button]': { |
|
|
|
render ($el, state) { |
|
|
|
render ($el, state) { |
|
|
|
|
|
|
|
if (state.emptyResponse) { |
|
|
|
|
|
|
|
return $el.hide() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (state.requestError || !state.nextPagePath || state.loading) { |
|
|
|
if (state.requestError || !state.nextPagePath || state.loading) { |
|
|
|
return $el.attr('disabled', 'disabled') |
|
|
|
return $el.attr('disabled', 'disabled') |
|
|
|
} |
|
|
|
} |
|
|
@ -179,6 +186,10 @@ export const elements = { |
|
|
|
}, |
|
|
|
}, |
|
|
|
'[data-async-listing] [data-prev-page-button]': { |
|
|
|
'[data-async-listing] [data-prev-page-button]': { |
|
|
|
render ($el, state) { |
|
|
|
render ($el, state) { |
|
|
|
|
|
|
|
if (state.emptyResponse) { |
|
|
|
|
|
|
|
return $el.hide() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (state.requestError || !state.prevPagePath || state.loading) { |
|
|
|
if (state.requestError || !state.prevPagePath || state.loading) { |
|
|
|
return $el.attr('disabled', 'disabled') |
|
|
|
return $el.attr('disabled', 'disabled') |
|
|
|
} |
|
|
|
} |
|
|
@ -189,6 +200,10 @@ export const elements = { |
|
|
|
}, |
|
|
|
}, |
|
|
|
'[data-async-listing] [data-page-number]': { |
|
|
|
'[data-async-listing] [data-page-number]': { |
|
|
|
render ($el, state) { |
|
|
|
render ($el, state) { |
|
|
|
|
|
|
|
if (state.emptyResponse) { |
|
|
|
|
|
|
|
return $el.hide() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (state.pagesStack.length === 0) { |
|
|
|
if (state.pagesStack.length === 0) { |
|
|
|
return $el.text('Page 1') |
|
|
|
return $el.text('Page 1') |
|
|
|
} |
|
|
|
} |
|
|
|