feat(filters): support multiple values
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user