import React from "react"; import { connect } from "react-redux"; import { DisabledChevronLeftSvg, DisabledChevronRightSvg, LightChevronLeftSvg, LightChevronRightSvg, } from "@dndbeyond/character-components/es"; import { Link } from "~/components/Link"; import { appEnvSelectors } from "../../../Shared/selectors"; import { navigationConfig } from "../../config"; import { builderSelectors } from "../../selectors"; import { BuilderAppState } from "../../typings"; import { NavigationUtils } from "../../utils"; interface PrevProps { disabled: boolean; } class TodoNavigationPrev extends React.PureComponent { static defaultProps = { disabled: false, }; render() { const { disabled } = this.props; let conClassNames: Array = [ "builder-navigation-large-action", "builder-navigation-large-action-prev", ]; if (disabled) { conClassNames.push("builder-navigation-large-action-disabled"); conClassNames.push("builder-navigation-large-action-prev-disabled"); } return (
{disabled ? : }
Prev
); } } interface NextProps { disabled: boolean; } class TodoNavigationNext extends React.PureComponent { static defaultProps = { disabled: false, }; render() { const { disabled } = this.props; let conClassNames: Array = [ "builder-navigation-large-action", "builder-navigation-large-action-next", ]; if (disabled) { conClassNames.push("builder-navigation-large-action-disabled"); conClassNames.push("builder-navigation-large-action-next-disabled"); } return (
Next
{disabled ? : }
); } } interface Props { prevRouteDef: any; nextRouteDef: any; builderMethod: string | null; isMobile: boolean; characterId: number | null; } class TodoNavigation extends React.PureComponent { handleNavClick = (): void => { window.scrollTo(0, 0); }; renderNonMobileUi = (): React.ReactNode => { const { prevRouteDef, nextRouteDef, characterId } = this.props; return (
{prevRouteDef !== null ? ( ) : (
)} {nextRouteDef !== null ? ( ) : (
)}
); }; renderMobileUi = (): React.ReactNode => { const { prevRouteDef, nextRouteDef, characterId } = this.props; return (
{prevRouteDef !== null ? ( < Prev ) : (
< Prev
)} {nextRouteDef !== null ? ( Next > ) : (
Next >
)}
); }; render() { const { isMobile, builderMethod } = this.props; if (builderMethod === null) { return null; } return isMobile ? this.renderMobileUi() : this.renderNonMobileUi(); } } function mapStateToProps(state: BuilderAppState, ownProps): Props { const currentPath = ownProps.pathname; const characterId = ownProps.characterId; const currentRouteDef = navigationConfig.getCurrentRouteDef(currentPath); let prevRouteDef, nextRouteDef; if (currentRouteDef === null) { prevRouteDef = null; nextRouteDef = null; } else { prevRouteDef = NavigationUtils.getAvailablePrevRoute( currentRouteDef, state ); nextRouteDef = NavigationUtils.getAvailableNextRoute( currentRouteDef, state ); } return { prevRouteDef, nextRouteDef, builderMethod: builderSelectors.getBuilderMethod(state), isMobile: appEnvSelectors.getIsMobile(state), characterId, }; } export default connect(mapStateToProps)(TodoNavigation);