import clsx from "clsx"; import React, { FC } from "react"; import { connect } from "react-redux"; import SwipeableViews from "react-swipeable-views"; import { characterSelectors, CharacterStatusSlug, CharacterTheme, FormatUtils, rulesEngineSelectors, } from "@dndbeyond/character-rules-engine/es"; import CharacterSheetSvg from "@dndbeyond/fontawesome-cache/svgs/light/address-card.svg"; import { GameLogNotificationWrapper } from "@dndbeyond/game-log-components"; import { Link } from "~/components/Link"; import { PremadeCharacterEditStatus } from "~/components/PremadeCharacterEditStatus"; import { Tooltip } from "~/components/Tooltip"; 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"; import styles from "./styles.module.css"; 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; theme: CharacterTheme; } const NavigationSections: FC = ({ characterId, isCharacterSheetReady, characterSheetUrl, theme, sections, firstAvailableSectionRoutes, activeSectionIdx, builderMethod, isMobile, characterStatus, isReadonly, }) => { const handleSheetShowClick = () => { if (characterId !== null) { MobileMessengerUtils.sendMessage( MobileMessengerUtils.createShowCharacterSheetMessage(characterId) ); } }; const renderCharacterSheetLink = () => { //trading out a Router Link for a div if not ready for accessibility const Component = isCharacterSheetReady ? Link : "div"; const CharacterSheetLink = () => ( <> ); return (
{}} isCharacterBuilder >
); }; const renderNonMobileUi = () => (
{renderCharacterSheetLink()}
{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 (
{section.getLabel()}
); })}
); const renderMobileUi = () => { const scrollbarStyles: React.CSSProperties = { padding: "0 35%", }; return (
{renderCharacterSheetLink()} {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 (
{section.getLabel()}
); })}
); }; if (builderMethod === null) { return null; } return isMobile ? ( <> {renderMobileUi()} ) : ( <> {renderNonMobileUi()} ); }; function mapStateToProps(state: BuilderAppState, ownProps) { const currentPath = ownProps.pathname; const sections = navigationConfig.getNavigationSections( builderSelectors.getBuilderMethod(state), navigationConfig.getCurrentRouteDef(currentPath) ); 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), theme: rulesEngineSelectors.getCharacterTheme(state), }; } export default connect(mapStateToProps)(NavigationSections);