Skip to content

Commit

Permalink
fix(build): Fixed typescript issues preventing build
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbenton committed Apr 16, 2024
1 parent 195a27e commit b9666d4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Datasworn.OracleCollection>;
collections: Record<string, CombinedCollectionType>;
oracles: Record<string, Datasworn.OracleRollable>;
forceOpen?: boolean;
visibleCollections: Record<string, CATEGORY_VISIBILITY>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ export enum CATEGORY_VISIBILITY {
ALL,
}

type omittedKeys = "oracle_type" | "contents";
export interface IPinnedOracleCollection
extends Omit<Datasworn.OracleTablesCollection, omittedKeys> {
oracle_type: "pinned_oracles";
contents: Record<string, Datasworn.OracleRollable>;
}

export type CombinedCollectionType =
| Datasworn.OracleCollection
| IPinnedOracleCollection;

export function useFilterOracles() {
const [search, setSearch] = useState("");
const oracleCollectionsWithoutPinnedOracles = useStore(
Expand All @@ -21,33 +32,39 @@ export function useFilterOracles() {

const pinnedOracles = useStore((store) => store.settings.pinnedOraclesIds);

const { oracleCollections, rootOracles } = useMemo(() => {
const { oracleCollections, rootOracles } = useMemo<{
oracleCollections: Record<string, CombinedCollectionType>;
rootOracles: string[];
}>(() => {
const pinnedOracleRollables: Record<string, Datasworn.OracleRollable> = {};

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],
Expand Down Expand Up @@ -76,9 +93,7 @@ export function useFilterOracles() {

const enhancesCollections: Record<string, string[]> = {};

const filterCollection = (
collection: Datasworn.OracleCollection
): boolean => {
const filterCollection = (collection: CombinedCollectionType): boolean => {
if (collection.enhances) {
enhancesCollections[collection.enhances] = [
...(enhancesCollections[collection.enhances] ?? []),
Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit b9666d4

Please sign in to comment.