From b9666d4941d5e6c274f9401b6db9e3918e0974d2 Mon Sep 17 00:00:00 2001 From: Scott Benton Date: Tue, 16 Apr 2024 18:45:40 -0400 Subject: [PATCH] fix(build): Fixed typescript issues preventing build --- .../NewOracleSection/OracleCollection.tsx | 3 +- .../NewOracleSection/useFilterOracles.ts | 60 ++++++++++++------- .../NonLinearMeterDialogForm.tsx | 2 +- 3 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/components/features/charactersAndCampaigns/NewOracleSection/OracleCollection.tsx b/src/components/features/charactersAndCampaigns/NewOracleSection/OracleCollection.tsx index 17313c6b..d5b2103d 100644 --- a/src/components/features/charactersAndCampaigns/NewOracleSection/OracleCollection.tsx +++ b/src/components/features/charactersAndCampaigns/NewOracleSection/OracleCollection.tsx @@ -5,10 +5,11 @@ import { CollapsibleSectionHeader } from "../CollapsibleSectionHeader"; import { Collapse, List } from "@mui/material"; import { OracleSelectableRollableCollectionListItem } from "./OracleSelectableRollableCollectionListItem"; import { OracleListItem } from "./OracleListItem"; +import { CombinedCollectionType } from "./useFilterOracles"; export interface OracleCollectionProps { collectionId: string; - collections: Record; + collections: Record; oracles: Record; forceOpen?: boolean; visibleCollections: Record; diff --git a/src/components/features/charactersAndCampaigns/NewOracleSection/useFilterOracles.ts b/src/components/features/charactersAndCampaigns/NewOracleSection/useFilterOracles.ts index 19507604..8a7da42d 100644 --- a/src/components/features/charactersAndCampaigns/NewOracleSection/useFilterOracles.ts +++ b/src/components/features/charactersAndCampaigns/NewOracleSection/useFilterOracles.ts @@ -9,6 +9,17 @@ export enum CATEGORY_VISIBILITY { ALL, } +type omittedKeys = "oracle_type" | "contents"; +export interface IPinnedOracleCollection + extends Omit { + oracle_type: "pinned_oracles"; + contents: Record; +} + +export type CombinedCollectionType = + | Datasworn.OracleCollection + | IPinnedOracleCollection; + export function useFilterOracles() { const [search, setSearch] = useState(""); const oracleCollectionsWithoutPinnedOracles = useStore( @@ -21,33 +32,39 @@ export function useFilterOracles() { const pinnedOracles = useStore((store) => store.settings.pinnedOraclesIds); - const { oracleCollections, rootOracles } = useMemo(() => { + const { oracleCollections, rootOracles } = useMemo<{ + oracleCollections: Record; + rootOracles: string[]; + }>(() => { const pinnedOracleRollables: Record = {}; Object.keys(pinnedOracles).forEach((id) => { - if (pinnedOracles[id] && oracles[id]) { - pinnedOracleRollables[id] = oracles[id]; + const oracle = oracles[id]; + if (pinnedOracles[id] && oracle) { + pinnedOracleRollables[id] = oracle; } }); if (Object.keys(pinnedOracleRollables).length > 0) { const pinnedOracleId = "app/collections/oracles/pinned"; + + const collection: IPinnedOracleCollection = { + _id: pinnedOracleId, + name: "Pinned Oracles", + _source: { + title: "Pinned Oracles", + authors: [], + date: "2000-01-01", + url: "", + license: License.None, + }, + contents: pinnedOracleRollables, + oracle_type: "pinned_oracles", + }; + return { oracleCollections: { - [pinnedOracleId]: { - _id: pinnedOracleId, - name: "Pinned Oracles", - _source: { - title: "Pinned Oracles", - authors: [], - date: "2000-01-01", - url: "", - license: License.None, - }, - contents: pinnedOracleRollables, - oracle_type: "tables", - }, - + [pinnedOracleId]: collection, ...oracleCollectionsWithoutPinnedOracles, }, rootOracles: [pinnedOracleId, ...rootOraclesWithoutPinnedOracles], @@ -76,9 +93,7 @@ export function useFilterOracles() { const enhancesCollections: Record = {}; - const filterCollection = ( - collection: Datasworn.OracleCollection - ): boolean => { + const filterCollection = (collection: CombinedCollectionType): boolean => { if (collection.enhances) { enhancesCollections[collection.enhances] = [ ...(enhancesCollections[collection.enhances] ?? []), @@ -88,7 +103,10 @@ export function useFilterOracles() { const hasChildren = (collection.oracle_type === "tables" && - Object.keys(collection.collections ?? {}).length > 0) || + Object.keys( + (collection as unknown as Datasworn.OracleTablesCollection) + .collections ?? {} + ).length > 0) || Object.keys(collection.contents ?? {}).length > 0; const searchIncludesCollectionName = diff --git a/src/pages/Homebrew/HomebrewEditorPage/RulesSection/NonLinearMeters/NonLinearMeterDialogForm.tsx b/src/pages/Homebrew/HomebrewEditorPage/RulesSection/NonLinearMeters/NonLinearMeterDialogForm.tsx index 0ee237c0..19636652 100644 --- a/src/pages/Homebrew/HomebrewEditorPage/RulesSection/NonLinearMeters/NonLinearMeterDialogForm.tsx +++ b/src/pages/Homebrew/HomebrewEditorPage/RulesSection/NonLinearMeters/NonLinearMeterDialogForm.tsx @@ -10,7 +10,7 @@ import { TextField, } from "@mui/material"; import { DialogTitleWithCloseButton } from "components/shared/DialogTitleWithCloseButton"; -import { useEffect, useState } from "react"; +import { useState } from "react"; import { StoredNonLinearMeter } from "types/homebrew/HomebrewRules.type"; import { useForm, SubmitHandler, Controller } from "react-hook-form"; import { convertIdPart } from "functions/dataswornIdEncoder";