Files
discord-decomp/modules/collectibles/CollectiblesShopVariantsUIStore.tsx
T
2026-11-01 12:12:55 +02:00

28 lines
1.1 KiB
TypeScript

// Metro module 8698 (f8699).
import { createWithEqualityFn } from "../../_bundle/identity_700";
import { shallow } from "../../_bundle/Module3802";
import { useDefaultVariantIndex } from "./hooks/useDefaultVariantIndex";
import { getIsVariantProduct } from "./utils/CollectiblesProductUtils";
const withEqualityFn = createWithEqualityFn(() => ({
selectionStates: new Map()
}), shallow);
export function useSelectedVariantIndex(a0) {
let c16733_0 = a0;
let r10 = useDefaultVariantIndex(a0);
const r13 = withEqualityFn((a0) => c16733_0 != null ? getIsVariantProduct(c16733_0) ? a0.selectionStates.get(c16733_0.storeListingId)?.selectedVariantIndex : null : null);
if (r13 != null) {
r10 = Math.max(0, r13);
}
return r10;
}
export function setSelectedVariantIndex(c16734_0, selectedVariantIndex) {
withEqualityFn.setState((state) => {
const selectionStates = state.selectionStates;
return selectionStates.get(c16734_0.storeListingId)?.selectedVariantIndex !== selectedVariantIndex ? {
selectionStates: new Map(state.selectionStates).set(c16734_0.storeListingId, {
selectedVariantIndex
})
} : state;
});
}