import React from "react"; import { connect } from "react-redux"; import SwipeableViews from "react-swipeable-views"; import { FeatureFlagContext } from "@dndbeyond/character-components/es"; import { characterSelectors, CharacterStatusSlug, featureFlagInfoSelectors, FormatUtils, } from "@dndbeyond/character-rules-engine/es"; import { Link } from "~/components/Link"; import { PremadeCharacterEditStatus } from "~/components/PremadeCharacterEditStatus"; import { appEnvSelectors } from "../../../Shared/selectors"; import { MobileMessengerUtils } from "../../../Shared/utils"; import { navigationConfig } from "../../config"; import { builderEnvSelectors, builderSelectors } from "../../selectors"; import { BuilderAppState } from "../../typings"; import HelpTextManager from "../HelpTextManager"; interface Props { characterId: number | null; builderMethod: string | null; sections: Array; firstAvailableSectionRoutes: any; isCharacterSheetReady: boolean; characterSheetUrl: string; activeSectionIdx: number; isMobile: boolean; characterStatus: CharacterStatusSlug | null; isReadonly: boolean; } class NavigationSections extends React.PureComponent { handleSheetShowClick = () => { const { characterId } = this.props; if (characterId !== null) { MobileMessengerUtils.sendMessage( MobileMessengerUtils.createShowCharacterSheetMessage(characterId) ); } }; renderNonMobileUi = (): React.ReactNode => { const { characterId, sections, firstAvailableSectionRoutes, isCharacterSheetReady, characterSheetUrl, } = this.props; let classNames: Array = ["builder-sections-sheet"]; if (isCharacterSheetReady) { classNames.push("builder-sections-sheet-ready"); } else { classNames.push("builder-sections-sheet-disabled"); } return (
{isCharacterSheetReady ? ( ) : (
)}
{sections.map((section) => { const firstRoute = firstAvailableSectionRoutes[section.key]; let clsNames: Array = [ "builder-sections-link", `builder-sections-${FormatUtils.slugify(section.key)}`, ]; if (section.active) { clsNames.push("builder-sections-link-active"); } return (
{(featureFlags) => section.getLabel(featureFlags)}
); })}
); }; renderMobileUi = (): React.ReactNode => { const { characterId, sections, firstAvailableSectionRoutes, activeSectionIdx, isCharacterSheetReady, characterSheetUrl, } = this.props; const scrollbarStyles: React.CSSProperties = { padding: "0 37.5%", }; let classNames = ["builder-sections-sheet"]; if (isCharacterSheetReady) { classNames.push("builder-sections-sheet-ready"); } else { classNames.push("builder-sections-sheet-disabled"); } return (
{isCharacterSheetReady ? ( ) : (
)}
{sections.map((section) => { const firstRoute = firstAvailableSectionRoutes[section.key]; let clsNames: Array = [ "builder-sections-link", `builder-sections-${FormatUtils.slugify(section.key)}`, ]; if (section.active) { clsNames.push("builder-sections-link-active"); } return (
{(featureFlags) => section.getLabel(featureFlags)}
); })}
); }; render() { const { builderMethod, isMobile, characterStatus, isReadonly } = this.props; if (builderMethod === null) { return null; } return isMobile ? ( <> {this.renderMobileUi()} ) : ( <> {this.renderNonMobileUi()} ); } } function mapStateToProps(state: BuilderAppState, ownProps) { const currentPath = ownProps.pathname; const sections = navigationConfig.getNavigationSections( builderSelectors.getBuilderMethod(state), navigationConfig.getCurrentRouteDef(currentPath), featureFlagInfoSelectors.getFeatureFlagInfo(state) ); let activeSectionIdx: number = 0; sections.forEach((section, idx) => { if (section.active) { activeSectionIdx = idx; } }); return { sections, firstAvailableSectionRoutes: builderSelectors.getFirstAvailableSectionRoutes(state), isCharacterSheetReady: builderSelectors.checkIsCharacterSheetReady(state), characterSheetUrl: builderEnvSelectors.getCharacterSheetUrl(state), builderMethod: builderSelectors.getBuilderMethod(state), activeSectionIdx, isMobile: appEnvSelectors.getIsMobile(state), characterStatus: characterSelectors.getStatusSlug(state), isReadonly: appEnvSelectors.getIsReadonly(state), }; } export default connect(mapStateToProps)(NavigationSections);