From 30cb9ada1a7980f77cb2a67bf9f5ce8fac0dd636 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Tue, 13 Jan 2026 20:06:58 +0300 Subject: [PATCH] fix(Font): refresh types --- src/entities/Font/model/store/types.ts | 43 ++++++++++++++++++++++ src/entities/Font/model/types/common.ts | 12 ++++++ src/entities/Font/model/types/fontshare.ts | 29 ++++++++++++--- 3 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 src/entities/Font/model/store/types.ts diff --git a/src/entities/Font/model/store/types.ts b/src/entities/Font/model/store/types.ts new file mode 100644 index 0000000..45c7b5c --- /dev/null +++ b/src/entities/Font/model/store/types.ts @@ -0,0 +1,43 @@ +/** + * ============================================================================ + * UNIFIED FONT STORE TYPES + * ============================================================================ + * + * Type definitions for the unified font store infrastructure. + * Provides types for filters, sorting, and fetch parameters. + */ + +import type { + FontshareParams, + GoogleFontsParams, +} from '$entities/Font/api'; +import type { + FontCategory, + FontProvider, + FontSubset, +} from '$entities/Font/model/types/common'; + +/** + * Sort configuration + */ +export interface FontSort { + field: 'name' | 'popularity' | 'category' | 'date'; + direction: 'asc' | 'desc'; +} + +/** + * Fetch params for unified API + */ +export interface FetchFontsParams { + providers?: FontProvider[]; + categories?: FontCategory[]; + subsets?: FontSubset[]; + search?: string; + sort?: FontSort; + forceRefetch?: boolean; +} + +/** + * Provider-specific params union + */ +export type ProviderParams = GoogleFontsParams | FontshareParams; diff --git a/src/entities/Font/model/types/common.ts b/src/entities/Font/model/types/common.ts index ca7100f..eddcb80 100644 --- a/src/entities/Font/model/types/common.ts +++ b/src/entities/Font/model/types/common.ts @@ -20,3 +20,15 @@ export type FontProvider = 'google' | 'fontshare'; * Font subset */ export type FontSubset = 'latin' | 'latin-ext' | 'cyrillic' | 'greek' | 'arabic' | 'devanagari'; + +/** + * Filter state + */ +export interface FontFilters { + providers: FontProvider[]; + categories: FontCategory[]; + subsets: FontSubset[]; +} + +export type CheckboxFilter = 'providers' | 'categories' | 'subsets'; +export type FilterType = CheckboxFilter | 'searchQuery'; diff --git a/src/entities/Font/model/types/fontshare.ts b/src/entities/Font/model/types/fontshare.ts index 319b272..66850c4 100644 --- a/src/entities/Font/model/types/fontshare.ts +++ b/src/entities/Font/model/types/fontshare.ts @@ -3,18 +3,37 @@ * FONTHARE API TYPES * ============================================================================ */ - -import type { CollectionApiModel } from '$shared/types/collection'; - -export const FONTSHARE_API_URL = 'https://api.fontshare.com/v2' as const; +export const FONTSHARE_API_URL = 'https://api.fontshare.com/v2/fonts' as const; export type FontCategory = 'sans' | 'serif' | 'slab' | 'display' | 'handwritten' | 'script'; /** * Model of Fontshare API response * @see https://fontshare.com + * + * Fontshare API uses 'fonts' key instead of 'items' for the array */ -export type FontshareApiModel = CollectionApiModel; +export interface FontshareApiModel { + /** + * Number of items returned in current page/response + */ + count: number; + + /** + * Total number of items available across all pages + */ + count_total: number; + + /** + * Indicates if there are more items available beyond this page + */ + has_more: boolean; + + /** + * Array of fonts (Fontshare uses 'fonts' key, not 'items') + */ + fonts: FontshareFont[]; +} /** * Individual font metadata from Fontshare API