From 001bedde3e20646fca228f2a65968c03a8763ab0 Mon Sep 17 00:00:00 2001 From: zagreer Date: Mon, 4 Nov 2024 19:29:03 -0500 Subject: [PATCH 1/2] Add campaign setting to hide oracles --- src/api-calls/campaign/_campaign.type.ts | 1 + src/api-calls/campaign/updateHiddenOracles.ts | 33 ++++++++ .../CollapsibleSectionHeader.tsx | 5 +- .../ListItemButtonWithSecondaryAction.tsx | 3 +- .../OracleSection/OracleCollection.tsx | 64 ++++++++++++--- .../OracleSection/OracleListItem.tsx | 49 ++++++++++-- .../OracleSection/OracleSection.tsx | 79 +++++++++++-------- ...leSelectableRollableCollectionListItem.tsx | 45 +++++++++-- .../shared/ToggleVisibilityButton.tsx | 63 +++++++++++++++ .../CampaignSettingsMenu.tsx | 20 +++++ .../HideOraclesDialog.tsx | 43 ++++++++++ .../currentCampaign/currentCampaign.slice.ts | 9 +++ .../currentCampaign.slice.type.ts | 4 + 13 files changed, 357 insertions(+), 61 deletions(-) create mode 100644 src/api-calls/campaign/updateHiddenOracles.ts create mode 100644 src/components/shared/ToggleVisibilityButton.tsx create mode 100644 src/pages/Campaign/CampaignPage/components/CampaignSettingsMenu/HideOraclesDialog.tsx diff --git a/src/api-calls/campaign/_campaign.type.ts b/src/api-calls/campaign/_campaign.type.ts index 454dec45..c4323004 100644 --- a/src/api-calls/campaign/_campaign.type.ts +++ b/src/api-calls/campaign/_campaign.type.ts @@ -15,6 +15,7 @@ export interface CampaignDocument { worldId?: string; expansionIds?: string[]; hiddenAssetIds?: string[]; + hiddenOracleIds?: string[]; customTracks?: Record; conditionMeters?: Record; specialTracks?: Record; diff --git a/src/api-calls/campaign/updateHiddenOracles.ts b/src/api-calls/campaign/updateHiddenOracles.ts new file mode 100644 index 00000000..81f688a4 --- /dev/null +++ b/src/api-calls/campaign/updateHiddenOracles.ts @@ -0,0 +1,33 @@ +import { arrayUnion, arrayRemove, updateDoc } from "firebase/firestore"; +import { getCampaignDoc } from "./_getRef"; +import { createApiFunction } from "api-calls/createApiFunction"; + +export const updateCampaignHiddenOracles = createApiFunction< + { + campaignId: string; + oracleId: string; + hidden: boolean; + }, + void +>((params) => { + const { campaignId, oracleId, hidden } = params; + + return new Promise((resolve, reject) => { + updateDoc( + getCampaignDoc(campaignId), + hidden + ? { + hiddenOracleIds: arrayUnion(oracleId), + } + : { + hiddenOracleIds: arrayRemove(oracleId), + } + ) + .then(() => { + resolve(); + }) + .catch((e) => { + reject(e); + }); + }); +}, "Failed to update hidden oracles."); diff --git a/src/components/features/charactersAndCampaigns/CollapsibleSectionHeader.tsx b/src/components/features/charactersAndCampaigns/CollapsibleSectionHeader.tsx index f93b3a1c..21e11043 100644 --- a/src/components/features/charactersAndCampaigns/CollapsibleSectionHeader.tsx +++ b/src/components/features/charactersAndCampaigns/CollapsibleSectionHeader.tsx @@ -18,10 +18,11 @@ export interface CollapsibleSectionHeaderProps { toggleOpen: () => void; disabled?: boolean; actions?: React.JSX.Element; + hidden?: boolean; } export function CollapsibleSectionHeader(props: CollapsibleSectionHeaderProps) { - const { component, text, open, forcedOpen, toggleOpen, disabled, actions } = + const { component, text, open, forcedOpen, toggleOpen, disabled, actions, hidden } = props; if (forcedOpen) { @@ -39,6 +40,7 @@ export function CollapsibleSectionHeader(props: CollapsibleSectionHeaderProps) { transition: theme.transitions.create(["margin"], { duration: theme.transitions.duration.shorter, }), + filter: hidden ? "grayscale(30%) opacity(70%)" : undefined })} > {text} @@ -72,6 +74,7 @@ export function CollapsibleSectionHeader(props: CollapsibleSectionHeaderProps) { transition: theme.transitions.create(["margin"], { duration: theme.transitions.duration.shorter, }), + filter: hidden ? "grayscale(30%) opacity(70%)" : undefined })} > {!forcedOpen ? ( diff --git a/src/components/features/charactersAndCampaigns/OracleSection/ListItemButtonWithSecondaryAction.tsx b/src/components/features/charactersAndCampaigns/OracleSection/ListItemButtonWithSecondaryAction.tsx index af7bda22..56236179 100644 --- a/src/components/features/charactersAndCampaigns/OracleSection/ListItemButtonWithSecondaryAction.tsx +++ b/src/components/features/charactersAndCampaigns/OracleSection/ListItemButtonWithSecondaryAction.tsx @@ -65,11 +65,12 @@ export function ListItemButtonWithSecondaryAction( {...listItemProps} > ({ pr: `calc(${theme.spacing(2)} + ${actionWidth ?? 0}px) !important`, + opacity: !onClick ? "1 !important" : undefined })} > {children} diff --git a/src/components/features/charactersAndCampaigns/OracleSection/OracleCollection.tsx b/src/components/features/charactersAndCampaigns/OracleSection/OracleCollection.tsx index 8eded4d6..351cbb7d 100644 --- a/src/components/features/charactersAndCampaigns/OracleSection/OracleCollection.tsx +++ b/src/components/features/charactersAndCampaigns/OracleSection/OracleCollection.tsx @@ -8,6 +8,8 @@ import { CATEGORY_VISIBILITY, CombinedCollectionType, } from "./useFilterOracles"; +import { useStore } from "stores/store"; +import { ToggleVisibilityButton } from "../../../shared/ToggleVisibilityButton"; export interface OracleCollectionProps { collectionId: string; @@ -18,6 +20,7 @@ export interface OracleCollectionProps { visibleOracles: Record; enhancesCollections: Record; disabled?: boolean; + actionIsHide?: boolean; } export function OracleCollection(props: OracleCollectionProps) { @@ -30,8 +33,28 @@ export function OracleCollection(props: OracleCollectionProps) { visibleOracles, enhancesCollections, disabled, + actionIsHide, } = props; + const hiddenOracles = useStore( + (store) => store.campaigns.currentCampaign.currentCampaign?.hiddenOracleIds + ); + const updateHiddenOracles = useStore( + (store) => store.campaigns.currentCampaign.updateHiddenOracles + ); + + const [hideIsloading, setHideIsLoading] = useState(false); + + const onToggleVisibility = () => { + setHideIsLoading(true); + updateHiddenOracles(collectionId, !hidden) + .catch(() => { + }) + .finally(() => { + setHideIsLoading(false); + }); + }; + const [isExpanded, setIsExpanded] = useState(false); const isExpandedOrForced = isExpanded || forceOpen; @@ -71,9 +94,12 @@ export function OracleCollection(props: OracleCollectionProps) { return { oracleIds, subCollectionIds }; }, [contents, subCollections, collections, enhancingCollectionIds]); + const hidden = hiddenOracles?.includes(collectionId); + if ( visibleCollections[collectionId] === CATEGORY_VISIBILITY.HIDDEN || - !collection + !collection || + (!actionIsHide && hidden) ) { return null; } else if ( @@ -85,6 +111,8 @@ export function OracleCollection(props: OracleCollectionProps) {