diff --git a/src/features/FilterFonts/lib/filterManager/filterManager.svelte.ts b/src/features/FilterFonts/lib/filterManager/filterManager.svelte.ts index 9417534..739dc0f 100644 --- a/src/features/FilterFonts/lib/filterManager/filterManager.svelte.ts +++ b/src/features/FilterFonts/lib/filterManager/filterManager.svelte.ts @@ -4,7 +4,7 @@ import type { FilterGroupConfig } from '../../model/const/types/common'; /** * Create a filter manager instance. */ -export function createFilterManager(configs: FilterGroupConfig[]) { +export function createFilterManager(configs: FilterGroupConfig[]) { // Create filter instances upfront const groups = $state( configs.map(config => ({ diff --git a/src/features/FilterFonts/model/const/const.ts b/src/features/FilterFonts/model/const/const.ts index 698cd93..e507e27 100644 --- a/src/features/FilterFonts/model/const/const.ts +++ b/src/features/FilterFonts/model/const/const.ts @@ -1,70 +1,90 @@ +import type { + FontCategory, + FontProvider, + FontSubset, +} from '$entities/Font'; import type { Property } from '$shared/lib'; -export const FONT_CATEGORIES: Property[] = [ +export const FONT_CATEGORIES: Property[] = [ { id: 'serif', name: 'Serif', + value: 'serif', }, { id: 'sans-serif', name: 'Sans-serif', + value: 'sans-serif', }, { id: 'display', name: 'Display', + value: 'display', }, { id: 'handwriting', name: 'Handwriting', + value: 'handwriting', }, { id: 'monospace', name: 'Monospace', + value: 'monospace', }, { id: 'script', name: 'Script', + value: 'script', }, { id: 'slab', name: 'Slab', + value: 'slab', }, ] as const; -export const FONT_PROVIDERS: Property[] = [ +export const FONT_PROVIDERS: Property[] = [ { id: 'google', name: 'Google Fonts', + value: 'google', }, { id: 'fontshare', name: 'Fontshare', + value: 'fontshare', }, ] as const; -export const FONT_SUBSETS: Property[] = [ +export const FONT_SUBSETS: Property[] = [ { id: 'latin', name: 'Latin', + value: 'latin', }, { id: 'latin-ext', name: 'Latin Extended', + value: 'latin-ext', }, { id: 'cyrillic', name: 'Cyrillic', + value: 'cyrillic', }, { id: 'greek', name: 'Greek', + value: 'greek', }, { id: 'arabic', name: 'Arabic', + value: 'arabic', }, { id: 'devanagari', name: 'Devanagari', + value: 'devanagari', }, ] as const; diff --git a/src/features/FilterFonts/model/const/types/common.ts b/src/features/FilterFonts/model/const/types/common.ts index 8da6850..d953359 100644 --- a/src/features/FilterFonts/model/const/types/common.ts +++ b/src/features/FilterFonts/model/const/types/common.ts @@ -1,7 +1,7 @@ import type { Property } from '$shared/lib'; -export interface FilterGroupConfig { +export interface FilterGroupConfig { id: string; label: string; - properties: Property[]; + properties: Property[]; } diff --git a/src/shared/lib/helpers/createFilter/createFilter.svelte.ts b/src/shared/lib/helpers/createFilter/createFilter.svelte.ts index 0a4ce4c..693cfe3 100644 --- a/src/shared/lib/helpers/createFilter/createFilter.svelte.ts +++ b/src/shared/lib/helpers/createFilter/createFilter.svelte.ts @@ -1,4 +1,4 @@ -export interface Property { +export interface Property { /** * Property identifier */ @@ -7,13 +7,17 @@ export interface Property { * Property name */ name: string; + /** + * Property value + */ + value: TValue; /** * Property selected state */ selected?: boolean; } -export interface FilterModel { +export interface FilterModel { /** * Search query */ @@ -21,15 +25,15 @@ export interface FilterModel { /** * Properties */ - properties: Property[]; + properties: Property[]; } /** * Create a filter store. * @param initialState - Initial state of the filter store */ -export function createFilter( - initialState: T, +export function createFilter( + initialState: FilterModel, ) { let properties = $state( initialState.properties.map(p => ({ diff --git a/src/shared/lib/helpers/createFilter/createFilter.test.ts b/src/shared/lib/helpers/createFilter/createFilter.test.ts index 3e2f001..2450073 100644 --- a/src/shared/lib/helpers/createFilter/createFilter.test.ts +++ b/src/shared/lib/helpers/createFilter/createFilter.test.ts @@ -22,6 +22,7 @@ describe('createFilter - Filter Logic', () => { return Array.from({ length: count }, (_, i) => ({ id: `prop-${i}`, name: `Property ${i}`, + value: `Value ${i}`, selected: selectedIndices.includes(i), })); } diff --git a/src/shared/ui/CheckboxFilter/CheckboxFilter.svelte.test.ts b/src/shared/ui/CheckboxFilter/CheckboxFilter.svelte.test.ts index 8ed4847..7e52cfb 100644 --- a/src/shared/ui/CheckboxFilter/CheckboxFilter.svelte.test.ts +++ b/src/shared/ui/CheckboxFilter/CheckboxFilter.svelte.test.ts @@ -33,7 +33,7 @@ describe('CheckboxFilter Component', () => { /** * Helper function to create a filter for testing */ - function createTestFilter(properties: Property[]) { + function createTestFilter(properties: Property[]) { return createFilter({ properties }); } @@ -44,6 +44,7 @@ describe('CheckboxFilter Component', () => { return Array.from({ length: count }, (_, i) => ({ id: `prop-${i}`, name: `Property ${i}`, + value: `Value ${i}`, selected: selectedIndices.includes(i), })); } @@ -437,10 +438,11 @@ describe('CheckboxFilter Component', () => { describe('Edge Cases', () => { it('handles long property names', () => { - const properties: Property[] = [ + const properties: Property[] = [ { id: '1', name: 'This is a very long property name that might wrap to multiple lines', + value: '1', selected: false, }, ]; @@ -458,10 +460,10 @@ describe('CheckboxFilter Component', () => { }); it('handles special characters in property names', () => { - const properties: Property[] = [ - { id: '1', name: 'Café & Restaurant', selected: true }, - { id: '2', name: '100% Organic', selected: false }, - { id: '3', name: '(Special) ', selected: false }, + const properties: Property[] = [ + { id: '1', name: 'Café & Restaurant', value: '1', selected: true }, + { id: '2', name: '100% Organic', value: '2', selected: false }, + { id: '3', name: '(Special) ', value: '3', selected: false }, ]; const filter = createTestFilter(properties); render(CheckboxFilter, { @@ -475,8 +477,8 @@ describe('CheckboxFilter Component', () => { }); it('handles single property filter', () => { - const properties: Property[] = [ - { id: '1', name: 'Only One', selected: true }, + const properties: Property[] = [ + { id: '1', name: 'Only One', value: '1', selected: true }, ]; const filter = createTestFilter(properties); render(CheckboxFilter, { @@ -527,12 +529,12 @@ describe('CheckboxFilter Component', () => { describe('Component Integration', () => { it('works correctly with real filter data', async () => { - const realProperties: Property[] = [ - { id: 'sans-serif', name: 'Sans-serif', selected: true }, - { id: 'serif', name: 'Serif', selected: false }, - { id: 'display', name: 'Display', selected: false }, - { id: 'handwriting', name: 'Handwriting', selected: true }, - { id: 'monospace', name: 'Monospace', selected: false }, + const realProperties: Property[] = [ + { id: 'sans-serif', name: 'Sans-serif', value: 'sans-serif', selected: true }, + { id: 'serif', name: 'Serif', value: 'serif', selected: false }, + { id: 'display', name: 'Display', value: 'display', selected: false }, + { id: 'handwriting', name: 'Handwriting', value: 'handwriting', selected: true }, + { id: 'monospace', name: 'Monospace', value: 'monospace', selected: false }, ]; const filter = createTestFilter(realProperties); render(CheckboxFilter, {