feat(fonts): implement Phase 3 - Update Filter Mapper
- Changed return type to Partial<ProxyFontsParams> - Map providers array to single provider value (or undefined) - Map categories array to single category value (or undefined) - Map subsets array to single subset value (or undefined) - Added type assertions for proper TypeScript compatibility Phase 3/7: Proxy API Integration for GlyphDiff
This commit is contained in:
@@ -1,18 +1,56 @@
|
|||||||
import type { FontshareParams } from '$entities/Font';
|
import type { ProxyFontsParams } from '$entities/Font/api';
|
||||||
import type { FilterManager } from '../filterManager/filterManager.svelte';
|
import type { FilterManager } from '../filterManager/filterManager.svelte';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps filter manager to fontshare params.
|
* Maps filter manager to proxy API parameters.
|
||||||
*
|
*
|
||||||
* @param manager - Filter manager instance.
|
* Transforms UI filter state into proxy API query parameters.
|
||||||
* @returns - Partial fontshare params.
|
* Handles conversion from filter groups to API-specific parameters.
|
||||||
|
*
|
||||||
|
* @param manager - Filter manager instance with reactive state
|
||||||
|
* @returns - Partial proxy API parameters ready for API call
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```ts
|
||||||
|
* // Example filter manager state:
|
||||||
|
* // {
|
||||||
|
* // queryValue: 'roboto',
|
||||||
|
* // providers: ['google'],
|
||||||
|
* // categories: ['sans-serif'],
|
||||||
|
* // subsets: ['latin']
|
||||||
|
* // }
|
||||||
|
*
|
||||||
|
* const params = mapManagerToParams(manager);
|
||||||
|
* // Returns: { provider: 'google', category: 'sans-serif', subset: 'latin', q: 'roboto' }
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
export function mapManagerToParams(manager: FilterManager): Partial<FontshareParams> {
|
export function mapManagerToParams(manager: FilterManager): Partial<ProxyFontsParams> {
|
||||||
|
const providers = manager.getGroup('providers')?.instance.selectedProperties.map(p => p.value);
|
||||||
|
const categories = manager.getGroup('categories')?.instance.selectedProperties.map(p =>
|
||||||
|
p.value
|
||||||
|
);
|
||||||
|
const subsets = manager.getGroup('subsets')?.instance.selectedProperties.map(p => p.value);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
q: manager.debouncedQueryValue,
|
// Search query (debounced)
|
||||||
// Map groups to specific API keys
|
q: manager.debouncedQueryValue || undefined,
|
||||||
categories: manager.getGroup('categories')?.instance.selectedProperties.map(p => p.value)
|
|
||||||
?? [],
|
// Provider filter (single value - proxy API doesn't support array)
|
||||||
tags: manager.getGroup('tags')?.instance.selectedProperties.map(p => p.value) ?? [],
|
// Use first provider if multiple selected, or undefined if none/all selected
|
||||||
|
provider: providers && providers.length === 1
|
||||||
|
? (providers[0] as 'google' | 'fontshare')
|
||||||
|
: undefined,
|
||||||
|
|
||||||
|
// Category filter (single value - proxy API doesn't support array)
|
||||||
|
// Use first category if multiple selected, or undefined if none/all selected
|
||||||
|
category: categories && categories.length === 1
|
||||||
|
? (categories[0] as ProxyFontsParams['category'])
|
||||||
|
: undefined,
|
||||||
|
|
||||||
|
// Subset filter (single value - proxy API doesn't support array)
|
||||||
|
// Use first subset if multiple selected, or undefined if none/all selected
|
||||||
|
subset: subsets && subsets.length === 1
|
||||||
|
? (subsets[0] as ProxyFontsParams['subset'])
|
||||||
|
: undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user