New source found from dndbeyond.com
This commit is contained in:
+13
-174
@@ -1,45 +1,27 @@
|
||||
import {
|
||||
FC,
|
||||
HTMLAttributes,
|
||||
useContext,
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import { FC, HTMLAttributes, useContext } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
|
||||
import {
|
||||
ApiAdapterUtils,
|
||||
FeatManager,
|
||||
} from "@dndbeyond/character-rules-engine";
|
||||
import { FeatManager } from "@dndbeyond/character-rules-engine";
|
||||
|
||||
import { FeatureChoice } from "~/components/FeatureChoice";
|
||||
import { BuilderChoiceTypeEnum } from "~/constants";
|
||||
import { FeatureChoices } from "~/components/FeatureChoices";
|
||||
import { useSidebar } from "~/contexts/Sidebar";
|
||||
import { useCharacterEngine } from "~/hooks/useCharacterEngine";
|
||||
import { Header } from "~/subApps/sheet/components/Sidebar/components/Header";
|
||||
import { Preview } from "~/subApps/sheet/components/Sidebar/components/Preview";
|
||||
import DataLoadingStatusEnum from "~/tools/js/Shared/constants/DataLoadingStatusEnum";
|
||||
import { ClassFeatureSnippet } from "~/tools/js/CharacterSheet/components/FeatureSnippet";
|
||||
import { CharacterFeaturesManagerContext } from "~/tools/js/Shared/managers/CharacterFeaturesManagerContext";
|
||||
import { apiCreatorSelectors } from "~/tools/js/Shared/selectors";
|
||||
import { AppLoggerUtils, PaneIdentifierUtils } from "~/tools/js/Shared/utils";
|
||||
import LoadingPlaceholder from "~/tools/js/smartComponents/LoadingPlaceholder";
|
||||
import { appEnvSelectors } from "~/tools/js/Shared/selectors";
|
||||
import { PaneIdentifierUtils } from "~/tools/js/Shared/utils";
|
||||
import {
|
||||
Action,
|
||||
CharClass,
|
||||
ClassDefinitionContract,
|
||||
ClassFeature,
|
||||
Feat,
|
||||
InfusionChoice,
|
||||
Spell,
|
||||
} from "~/types";
|
||||
|
||||
import { ClassFeatureSnippet } from "../../../../../../tools/js/CharacterSheet/components/FeatureSnippet";
|
||||
import { appEnvSelectors } from "../../../../../../tools/js/Shared/selectors";
|
||||
import { Heading } from "../../components/Heading";
|
||||
import { PaneInitFailureContent } from "../../components/PaneInitFailureContent";
|
||||
import { PaneComponentEnum, PaneIdentifiersClassFeature } from "../../types";
|
||||
import styles from "./styles.module.css";
|
||||
|
||||
interface Props extends HTMLAttributes<HTMLDivElement> {
|
||||
identifiers: PaneIdentifiersClassFeature | null;
|
||||
@@ -61,8 +43,6 @@ export const ClassFeaturePane: FC<Props> = ({ identifiers, ...props }) => {
|
||||
proficiencyBonus,
|
||||
originRef: dataOriginRefData,
|
||||
characterTheme: theme,
|
||||
choiceUtils,
|
||||
featUtils,
|
||||
helperUtils,
|
||||
} = useCharacterEngine();
|
||||
|
||||
@@ -76,23 +56,6 @@ export const ClassFeaturePane: FC<Props> = ({ identifiers, ...props }) => {
|
||||
|
||||
const isReadonly = useSelector(appEnvSelectors.getIsReadonly);
|
||||
|
||||
const loadAvailableFeats = useSelector(
|
||||
apiCreatorSelectors.makeLoadAvailableFeats
|
||||
);
|
||||
const loadAvailableSubclasses = useSelector(
|
||||
apiCreatorSelectors.makeLoadAvailableSubclasses
|
||||
);
|
||||
|
||||
const [subclassData, setSubclassData] = useState<
|
||||
Array<ClassDefinitionContract>
|
||||
>([]);
|
||||
const [featsData, setFeatsData] = useState<Array<Feat>>([]);
|
||||
const [featLoadingStatus, setFeatLoadingStatus] =
|
||||
useState<DataLoadingStatusEnum>(DataLoadingStatusEnum.NOT_INITIALIZED);
|
||||
const [subclassLoadingStatus, setSubclassLoadingStatus] =
|
||||
useState<DataLoadingStatusEnum>(DataLoadingStatusEnum.NOT_INITIALIZED);
|
||||
const currentCharClass = useRef<CharClass | null>(null);
|
||||
|
||||
const charClass = identifiers?.classMappingId
|
||||
? classes.find(
|
||||
(charClass) =>
|
||||
@@ -105,98 +68,6 @@ export const ClassFeaturePane: FC<Props> = ({ identifiers, ...props }) => {
|
||||
(feature) => identifiers?.id === classFeatureUtils.getId(feature)
|
||||
) ?? null;
|
||||
|
||||
const featureChoices = classFeature
|
||||
? classFeatureUtils.getChoices(classFeature)
|
||||
: [];
|
||||
|
||||
const hasFeatChoice = featureChoices.some(
|
||||
(choice) =>
|
||||
choiceUtils.getType(choice) === BuilderChoiceTypeEnum.FEAT_CHOICE_OPTION
|
||||
);
|
||||
|
||||
const hasSubclassChoice = featureChoices.some(
|
||||
(choice) =>
|
||||
choiceUtils.getType(choice) === BuilderChoiceTypeEnum.SUB_CLASS_OPTION
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const isSameClass = (
|
||||
c1: CharClass | null,
|
||||
c2: CharClass | null
|
||||
): boolean => {
|
||||
if (!c1 || !c2) return false;
|
||||
return classUtils.getId(c1) === classUtils.getId(c2);
|
||||
};
|
||||
|
||||
if (
|
||||
hasFeatChoice &&
|
||||
featLoadingStatus === DataLoadingStatusEnum.NOT_INITIALIZED
|
||||
) {
|
||||
setFeatLoadingStatus(DataLoadingStatusEnum.LOADING);
|
||||
|
||||
loadAvailableFeats({
|
||||
// cancelToken: new axios.CancelToken((c) => {
|
||||
// this.loadFeatsCanceler = c;
|
||||
// }),
|
||||
})
|
||||
.then((response) => {
|
||||
let featsData: Array<Feat> = [];
|
||||
|
||||
const data = ApiAdapterUtils.getResponseData(response);
|
||||
if (data !== null) {
|
||||
featsData = data.map((definition) =>
|
||||
featUtils.simulateFeat(definition)
|
||||
);
|
||||
}
|
||||
|
||||
setFeatsData(featsData);
|
||||
setFeatLoadingStatus(DataLoadingStatusEnum.LOADED);
|
||||
// this.loadFeatsCanceler = null;
|
||||
})
|
||||
.catch(AppLoggerUtils.handleAdhocApiError);
|
||||
}
|
||||
|
||||
if (
|
||||
charClass &&
|
||||
!isSameClass(charClass, currentCharClass.current) && // Only pull data if the class has changed from previous fetch
|
||||
hasSubclassChoice &&
|
||||
subclassLoadingStatus !== DataLoadingStatusEnum.LOADING // Check if its not already fetching data
|
||||
) {
|
||||
currentCharClass.current = charClass; //Update ref of fetched class
|
||||
setSubclassLoadingStatus(DataLoadingStatusEnum.LOADING);
|
||||
|
||||
loadAvailableSubclasses(classUtils.getId(charClass), {
|
||||
// cancelToken: new axios.CancelToken((c) => {
|
||||
// this.loadSubclassesCanceler = c;
|
||||
// }),
|
||||
})
|
||||
.then((response) => {
|
||||
let subclassData: Array<ClassDefinitionContract> = [];
|
||||
|
||||
const data = ApiAdapterUtils.getResponseData(response);
|
||||
if (data !== null) {
|
||||
subclassData = data;
|
||||
}
|
||||
|
||||
setSubclassData(subclassData);
|
||||
setSubclassLoadingStatus(DataLoadingStatusEnum.LOADED);
|
||||
// this.loadSubclassesCanceler = null;
|
||||
})
|
||||
.catch(AppLoggerUtils.handleAdhocApiError);
|
||||
}
|
||||
}, [
|
||||
hasFeatChoice,
|
||||
hasSubclassChoice,
|
||||
subclassLoadingStatus,
|
||||
featLoadingStatus,
|
||||
charClass,
|
||||
classUtils,
|
||||
featUtils,
|
||||
loadAvailableFeats,
|
||||
loadAvailableSubclasses,
|
||||
currentCharClass,
|
||||
]);
|
||||
|
||||
const handleInfusionChoiceShow = (infusionChoice: InfusionChoice): void => {
|
||||
const choiceKey = infusionChoiceUtils.getKey(infusionChoice);
|
||||
if (choiceKey !== null) {
|
||||
@@ -302,21 +173,6 @@ export const ClassFeaturePane: FC<Props> = ({ identifiers, ...props }) => {
|
||||
);
|
||||
};
|
||||
|
||||
const isDataLoaded = (): boolean => {
|
||||
if (hasSubclassChoice) {
|
||||
if (subclassLoadingStatus !== DataLoadingStatusEnum.LOADED) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (hasFeatChoice) {
|
||||
if (featLoadingStatus !== DataLoadingStatusEnum.LOADED) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
if (!charClass || !classFeature) {
|
||||
return <PaneInitFailureContent />;
|
||||
}
|
||||
@@ -356,30 +212,13 @@ export const ClassFeaturePane: FC<Props> = ({ identifiers, ...props }) => {
|
||||
onFeatClick={handleFeatShow}
|
||||
featuresManager={characterFeaturesManager}
|
||||
/>
|
||||
{!isReadonly && featureChoices.length > 0 && (
|
||||
<>
|
||||
<Heading className={styles.heading}>{`Option${
|
||||
featureChoices.length > 1 ? "s" : ""
|
||||
}`}</Heading>
|
||||
{isDataLoaded() ? (
|
||||
featureChoices.map((choice) => (
|
||||
<FeatureChoice
|
||||
charClass={charClass}
|
||||
choice={choice}
|
||||
feature={classFeature}
|
||||
featsData={featsData}
|
||||
subclassData={subclassData}
|
||||
className={styles.choice}
|
||||
key={choiceUtils.getId(choice)}
|
||||
onChoiceChange={handleChoiceChange}
|
||||
collapseDescription={true}
|
||||
/>
|
||||
))
|
||||
) : (
|
||||
<LoadingPlaceholder />
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
<FeatureChoices
|
||||
choices={classFeatureUtils.getChoices(classFeature)}
|
||||
charClass={charClass}
|
||||
onChoiceChange={handleChoiceChange}
|
||||
collapseDescription={true}
|
||||
showHeading={true}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user