diff --git a/frontend/src/v2/composables/useScanProviders/index.ts b/frontend/src/v2/composables/useScanProviders/index.ts index 058441e61..b5c0ba789 100644 --- a/frontend/src/v2/composables/useScanProviders/index.ts +++ b/frontend/src/v2/composables/useScanProviders/index.ts @@ -32,10 +32,11 @@ const LOCAL_STORAGE_LAUNCHBOX_REMOTE_ENABLED_KEY = const LOCAL_STORAGE_HASHEOUS_ENABLED_KEY = "scan.hasheousEnabled"; const LOCAL_STORAGE_PLAYMATCH_ENABLED_KEY = "scan.playmatchEnabled"; -const HASH_MATCHER_KEYS: readonly string[] = providerKeysInGroup("proxy"); - export type HashMatcherKey = MetadataProviderKeyIn<"proxy">; +// Render order for the hash-matcher switches. +const HASH_MATCHER_KEYS = providerKeysInGroup("proxy"); + export interface HashMatcher { value: HashMatcherKey; name: string; @@ -84,7 +85,7 @@ export function useScanProviders(): UseScanProviders { const metadataOptions = computed(() => heartbeat .getMetadataOptionsByPriority() - .filter((option) => !HASH_MATCHER_KEYS.includes(option.value)) + .filter((option) => metadataProviderGroup(option.value) !== "proxy") .map((option) => { const requiresHashes = option.value === "ra"; let disabled = option.disabled; @@ -120,14 +121,10 @@ export function useScanProviders(): UseScanProviders { LOCAL_STORAGE_LAUNCHBOX_REMOTE_ENABLED_KEY, true, ); - const hasheousEnabled = useLocalStorage( - LOCAL_STORAGE_HASHEOUS_ENABLED_KEY, - true, - ); - const playmatchEnabled = useLocalStorage( - LOCAL_STORAGE_PLAYMATCH_ENABLED_KEY, - true, - ); + const hashMatcherEnabled: Record> = { + hasheous: useLocalStorage(LOCAL_STORAGE_HASHEOUS_ENABLED_KEY, true), + playmatch: useLocalStorage(LOCAL_STORAGE_PLAYMATCH_ENABLED_KEY, true), + }; // A group with no pick stays empty, which the selects read as All. const metadataSources = ref([]); @@ -201,9 +198,8 @@ export function useScanProviders(): UseScanProviders { const hasheousAdmin = Boolean(sources?.HASHEOUS_API_ENABLED); const playmatchAdmin = Boolean(sources?.PLAYMATCH_API_ENABLED); - return [ - { - value: "hasheous", + const matchers: Record> = { + hasheous: { name: "Hasheous", logo: "/assets/scrappers/hasheous.png", blockedReason: !hasheousAdmin @@ -213,8 +209,7 @@ export function useScanProviders(): UseScanProviders { : null, switchEnabled: hasheousAdmin && !noHashes, }, - { - value: "playmatch", + playmatch: { name: "Playmatch", logo: "/assets/scrappers/playmatch.png", blockedReason: !playmatchAdmin @@ -226,19 +221,17 @@ export function useScanProviders(): UseScanProviders { : null, switchEnabled: playmatchAdmin && !noHashes && igdbSelected, }, - ]; + }; + + return HASH_MATCHER_KEYS.map((value) => ({ value, ...matchers[value] })); }); function setHashMatcher(value: HashMatcherKey, next: boolean) { - if (value === "hasheous") hasheousEnabled.value = next; - else playmatchEnabled.value = next; + hashMatcherEnabled[value].value = next; } function isHashMatcherOn(matcher: HashMatcher): boolean { - if (!matcher.switchEnabled) return false; - return matcher.value === "hasheous" - ? hasheousEnabled.value - : playmatchEnabled.value; + return matcher.switchEnabled && hashMatcherEnabled[matcher.value].value; } function isOn(value: HashMatcherKey): boolean { diff --git a/frontend/src/v2/utils/metadataProviderGroups.ts b/frontend/src/v2/utils/metadataProviderGroups.ts index be6c1901f..1fbff8760 100644 --- a/frontend/src/v2/utils/metadataProviderGroups.ts +++ b/frontend/src/v2/utils/metadataProviderGroups.ts @@ -24,9 +24,9 @@ export const METADATA_PROVIDER_GROUPS = { export type MetadataProviderKey = keyof typeof METADATA_PROVIDER_GROUPS; -/** The provider keys of one group, as a union. Lets a consumer that - * branches per provider (the hash-matcher switches) get a compile error - * when the group grows a member. */ +/** The provider keys of one group, as a union. A consumer that holds + * per-provider state or config in a `Record` keyed by this gets a + * compile error when the group grows a member. */ export type MetadataProviderKeyIn = { [K in MetadataProviderKey]: (typeof METADATA_PROVIDER_GROUPS)[K] extends G ? K @@ -40,12 +40,15 @@ export const METADATA_PROVIDER_GROUP_ORDER = [ "proxy", ] as const satisfies readonly MetadataProviderGroup[]; -export function providerKeysInGroup( - group: MetadataProviderGroup, -): MetadataProviderKey[] { +export function providerKeysInGroup( + group: G, +): MetadataProviderKeyIn[] { return ( Object.keys(METADATA_PROVIDER_GROUPS) as MetadataProviderKey[] - ).filter((key) => METADATA_PROVIDER_GROUPS[key] === group); + ).filter( + (key): key is MetadataProviderKeyIn => + METADATA_PROVIDER_GROUPS[key] === group, + ); } /** Group of an unvalidated key (a heartbeat option value), or undefined