lml-main
Version:
This is now a mono repository published into many standalone packages.
42 lines • 1.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const Actions = require("../../common/actions");
exports.initiaTrayState = {
selectedTrayId: null,
};
exports.trayReducer = (state = exports.initiaTrayState, action) => {
switch (action.type) {
case Actions.SET_SELECTED_TRAY: {
return setSelectedTray(state, action);
}
case Actions.SELECT_TRAY_TO_LEFT: {
return selectTrayToLeft(state, action);
}
case Actions.SELECT_TRAY_TO_RIGHT: {
return selectTrayToRight(state, action);
}
default: {
return state;
}
}
};
const trayIds = ['jobs', 'couriers', 'map'];
const setSelectedTray = (state, action) => {
const selectedTrayId = action.selectedTrayId;
return Object.assign({}, state, { selectedTrayId });
};
const selectTrayToLeft = (state, action) => {
let selectedTrayId = state.selectedTrayId;
let index = (trayIds.indexOf(selectedTrayId) === -1) ? 0 : trayIds.indexOf(selectedTrayId) - 1;
index = (index < 0) ? trayIds.length - 1 : index;
selectedTrayId = trayIds[index];
return Object.assign({}, state, { selectedTrayId });
};
const selectTrayToRight = (state, action) => {
let selectedTrayId = state.selectedTrayId;
let index = (trayIds.indexOf(selectedTrayId) === -1) ? 0 : trayIds.indexOf(selectedTrayId) + 1;
index = (index > trayIds.length - 1) ? 0 : index;
selectedTrayId = trayIds[index];
return Object.assign({}, state, { selectedTrayId });
};
//# sourceMappingURL=tray.js.map