lml-main
Version:
This is now a mono repository published into many standalone packages.
53 lines • 2.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const selectors_1 = require("../../frequencies/selectors");
exports.getAllLastKeys = (state) => state.jobs.pagination.lastKeys;
exports.getPagePointer = (state) => state.jobs.pagination.pagePointer || 0;
/**
* Let's say the page pointer has been updated to 1,
* we now need to get the last keys for page 0 and include
* them in the request for the jobs at page 1.
* This means the last keys for the current page always refers
* to the previous page's pagePointer
*
* @param state
*/
exports.getLastKeysForPage = (state) => {
const page = exports.getPagePointer(state);
// console.log('GET LAST KEYS FOR PAGE POINTER', page)
// if we're on the first page then don't add the keys to the request
if (page <= 0)
return null;
// otherwise get the last key of the previous page
return exports.getAllLastKeys(state)[page - 1] || null;
};
exports.canPageBack = (state) => state.jobs.pagination.canPageBack && exports.lastKeyIsActive(state, false);
exports.canPageForwards = (state) => state.jobs.pagination.canPageForwards && exports.lastKeyIsActive(state, true);
/**
* This check is required because we are polling for all the frequencies
* including frequencies that aren't active - therefore we need to check
* if the pagination is actually for one of the frequencies that is currently active
*
* @param state
*/
exports.lastKeyIsActive = (state, forNextPage = true) => {
let page = forNextPage
? exports.getPagePointer(state)
: exports.getPagePointer(state) - 1;
if (page < 0)
page = 0;
const lastKeys = exports.getAllLastKeys(state)[page];
// console.log('LAST KEY IS ACTIVE', lastKeys)
if (!lastKeys)
return false;
const freqs = selectors_1.getActiveShowingFrequencyIds(state);
const lastKeyLabels = Object.keys(lastKeys);
const res = freqs.reduce((acc, curr) => {
if (lastKeyLabels.indexOf(curr) !== -1)
return true;
return acc;
}, false);
// console.log('CAN PAGE', freqs, lastKeyLabels, res)
return res;
};
//# sourceMappingURL=pagination.js.map