@randy.tarampi/jsx
Version:
Some common JSX components for www.randytarampi.ca
24 lines (22 loc) • 1.07 kB
JavaScript
import { push } from "connected-react-router/immutable";
import { createAction } from "redux-actions";
import selectors from "../../data/selectors";
export var SWIPEABLE_TAB_CHANGE_INDEX = "SWIPEABLE_TAB_CHANGE_INDEX";
export var swipeableTabChangeIndexCreator = onChangeEvent => (dispatch, getState) => {
var tabIndex = onChangeEvent.currentTarget.getAttribute("href").match(/\d+/g)[0];
var passedTabIndex = Number(tabIndex); // NOTE-RT: We need the un`scoped` value here, per https://github.com/react-materialize/react-materialize/commit/f5d1e0d5b97ae4435d6a709b9fc030458fe30b9e#diff-f8f6138478fd4cda2a0f875f28829252R50.
var index = passedTabIndex % 10;
dispatch(swipeableTabChangeIndex({
index
}));
var state = getState();
var routeForIndex = selectors.getRouteForIndex(state, index);
var path = routeForIndex ? routeForIndex.path : null;
if (path) {
dispatch(push({
pathname: path.split(":")[0]
}));
}
};
export var swipeableTabChangeIndex = createAction(SWIPEABLE_TAB_CHANGE_INDEX);
export default swipeableTabChangeIndexCreator;