UNPKG

@patternplate/client

Version:

Universal javascript client application for patternplate

77 lines (61 loc) 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.type = exports.default = void 0; var _reactRouterRedux = require("react-router-redux"); var _toggleNavigation = _interopRequireDefault(require("./toggle-navigation")); var _pool = require("../selectors/pool"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var _default = arrow; exports.default = _default; const type = "ARROW"; exports.type = type; const OFFSETS = { up: -1, down: 1, default: 0 }; function arrow(payload) { return (dispatch, getState) => { const state = getState(); // Is handled locally if (state.searchEnabled) { return; } switch (payload) { case "right": { if (state.navigationEnabled) { return dispatch((0, _toggleNavigation.default)()); } return; } case "left": { if (!state.navigationEnabled) { return dispatch((0, _toggleNavigation.default)()); } return; } case "up": case "down": default: { if (!state.navigationEnabled) { return; } const offset = payload in OFFSETS ? OFFSETS[payload] : OFFSETS.default; const pool = (0, _pool.flat)(state); const index = pool.findIndex(item => `${item.contentType}/${item.id}` === state.id || state.id === '/' && item.id === '/root'); const next = pool[index + offset]; if (next) { go(dispatch)(next.href); } } } }; } function go(dispatch) { return next => dispatch((0, _reactRouterRedux.push)(next)); } //# sourceMappingURL=arrow.js.map