import { spring, TransitionMotion } from "@serprex/react-motion"; import React, { useContext } from "react"; import { connect } from "react-redux"; import { ThemeStyles, DarkAbilitiesSvg, DarkActionsSvg, DarkSkillsSvg, DarkEquipmentSvg, DarkSpellsSvg, DarkProficienciesSvg, DarkDescriptionSvg, DarkNotesSvg, DarkFeaturesSvg, DarkExtrasSvg, LightAbilitiesSvg, LightActionsSvg, LightSkillsSvg, LightEquipmentSvg, LightSpellsSvg, LightProficienciesSvg, LightDescriptionSvg, LightNotesSvg, LightFeaturesSvg, LightExtrasSvg, } from "@dndbeyond/character-components/es"; import { rulesEngineSelectors, DecorationInfo, DecorationUtils, } from "@dndbeyond/character-rules-engine/es"; import { useSidebar } from "~/contexts/Sidebar"; import { SidebarInfo } from "~/contexts/Sidebar/Sidebar"; import { usePositioning } from "~/hooks/usePositioning"; import { Sidebar } from "~/subApps/sheet/components/Sidebar"; import { SidebarPositionInfo } from "~/subApps/sheet/components/Sidebar/types"; import { SheetContext } from "~/subApps/sheet/contexts/Sheet"; import { MobileSections } from "~/subApps/sheet/types"; import { appEnvSelectors } from "../../../Shared/selectors"; import { AppEnvDimensionsState } from "../../../Shared/stores/typings"; import { ComponentCarousel, ComponentCarouselItem, } from "../../components/ComponentCarousel"; import SectionPlaceholder from "../../components/SectionPlaceholder"; import { SheetAppState } from "../../typings"; import CharacterHeaderMobile from "../CharacterHeaderMobile"; import ActionsMobile from "../mobile/ActionsMobile"; import CombatMobile from "../mobile/CombatMobile"; import { DescriptionMobile } from "../mobile/DescriptionMobile"; import EquipmentMobile from "../mobile/EquipmentMobile"; import ExtrasMobile from "../mobile/ExtrasMobile"; import FeaturesMobile from "../mobile/FeaturesMobile"; import MainMobile from "../mobile/MainMobile"; import NotesMobile from "../mobile/NotesMobile"; import { ProficiencyGroupsMobile } from "../mobile/ProficiencyGroupsMobile"; import SkillsMobile from "../mobile/SkillsMobile"; import SpellsMobile from "../mobile/SpellsMobile"; interface Props { sidebarInfo: SidebarInfo; sidebarPosition: SidebarPositionInfo; envDimensions: AppEnvDimensionsState; decorationInfo: DecorationInfo; hasSpells: boolean; isReadonly: boolean; mobileActiveSectionId: MobileSections; setMobileActiveSectionId: (id: MobileSections) => void; } interface State { swipedAmount: number; } class CharacterSheetMobile extends React.PureComponent { constructor(props) { super(props); this.state = { swipedAmount: 0, }; } handleComponentChange = (id: MobileSections): void => { const { setMobileActiveSectionId } = this.props; setMobileActiveSectionId(id); window.scrollTo(0, 0); }; handleItemChange = (newKey: MobileSections, oldKey: MobileSections): void => { if (newKey !== oldKey) { window.scrollTo(0, 0); } const { setMobileActiveSectionId } = this.props; setMobileActiveSectionId(newKey); }; getPositionX = (swipedAmount: number): number => { const { sidebarInfo } = this.props; let position: number = (sidebarInfo.isVisible ? 0 : sidebarInfo.width) + swipedAmount; if (swipedAmount > 0) { return Math.min(sidebarInfo.width, position); } else { return Math.max(0, position); } }; renderSections = (activeSectionId: MobileSections): React.ReactNode => { const { envDimensions, hasSpells, isReadonly, decorationInfo } = this.props; const isDarkMode = DecorationUtils.isDarkMode(decorationInfo); return ( ); }; renderSidebar = (): React.ReactNode => { const { swipedAmount } = this.state; const { sidebarPosition } = this.props; return ( {(interpolatedStyles) => ( {interpolatedStyles.map((config) => ( this.setState({ swipedAmount }) } /> ))} )} ); }; render() { const { decorationInfo } = this.props; return ( {({ mobileActiveSectionId }) => (
{this.renderSections(mobileActiveSectionId)} {this.renderSidebar()}
)}
); } } function mapStateToProps(state: SheetAppState) { return { decorationInfo: rulesEngineSelectors.getDecorationInfo(state), hasSpells: rulesEngineSelectors.hasSpells(state), isReadonly: appEnvSelectors.getIsReadonly(state), envDimensions: appEnvSelectors.getDimensions(state), }; } const CharacterSheetMobileContainer = (props) => { const { mobileActiveSectionId, setMobileActiveSectionId } = useContext(SheetContext); const { sidebar } = useSidebar(); const { getSidebarPositioning } = usePositioning(); return ( ); }; export default connect(mapStateToProps)(CharacterSheetMobileContainer);