feat(filters): support multiple values

This commit is contained in:
Ilia Mashkov
2026-03-02 14:12:55 +03:00
parent 37a528f0aa
commit db7ffd3246
3 changed files with 93 additions and 152 deletions
@@ -4,26 +4,58 @@ import {
FONT_PROVIDERS,
FONT_SUBSETS,
} from '../const/const';
import { filtersStore } from './filters.svelte';
const initialConfig = {
queryValue: '',
groups: [
{
id: 'providers',
label: 'Font provider',
properties: FONT_PROVIDERS,
},
{
id: 'subsets',
label: 'Font subset',
properties: FONT_SUBSETS,
},
{
id: 'categories',
label: 'Font category',
properties: FONT_CATEGORIES,
},
],
};
/**
* Creates initial filter config
*
* Uses dynamic filters from backend if available,
* otherwise falls back to hard-coded constants
*/
function createInitialConfig() {
const dynamicFilters = filtersStore.filters;
// If filters are loaded, use them
if (dynamicFilters.length > 0) {
return {
queryValue: '',
groups: dynamicFilters.map(filter => ({
id: filter.id,
label: filter.name,
properties: filter.options.map(opt => ({
id: opt.id,
name: opt.name,
value: opt.value,
count: opt.count,
selected: false,
})),
})),
};
}
// Fallback to hard-coded constants (backward compatibility)
return {
queryValue: '',
groups: [
{
id: 'providers',
label: 'Font provider',
properties: FONT_PROVIDERS,
},
{
id: 'subsets',
label: 'Font subset',
properties: FONT_SUBSETS,
},
{
id: 'categories',
label: 'Font category',
properties: FONT_CATEGORIES,
},
],
};
}
const initialConfig = createInitialConfig();
export const filterManager = createFilterManager(initialConfig);