UNPKG

@randy.tarampi/jsx

Version:

Some common JSX components for www.randytarampi.ca

36 lines 1.32 kB
import { POST_ENTITIES } from "@randy.tarampi/js"; import PropTypes from "prop-types"; import { connect } from "react-redux"; import { setControlStateCreator, setGoogleMapCenterCreator } from "../actions"; import { buildPostMarkerId, PostMarkerComponent } from "../components/postMarker"; import selectors from "../data/selectors"; export var connectPostMarker = connect((state, ownProps) => { var { post } = ownProps; var postMarkerId = buildPostMarkerId(post); var controlState = selectors.getControlStateForId(state, postMarkerId); return { isVisible: controlState ? controlState.get("visible") : false }; }, (dispatch, ownProps) => { var { getGoogleMap, mapId, post } = ownProps; var postMarkerId = buildPostMarkerId(post); return { setMapCenter: newCenter => dispatch(setGoogleMapCenterCreator(getGoogleMap, mapId, newCenter)), onVisibilityToggle: shouldBeVisible => dispatch(setControlStateCreator(postMarkerId, { visible: !!shouldBeVisible })) }; }); export var ConnectedPostMarker = connectPostMarker(PostMarkerComponent); ConnectedPostMarker.propTypes = { getGoogleMap: PropTypes.func.isRequired, post: PropTypes.oneOfType(POST_ENTITIES.map(PropTypes.instanceOf)).isRequired, mapId: PropTypes.string.isRequired }; export default ConnectedPostMarker;