feature: Create BaseFontStore class with Tanstack query logic and FontshareStore, GoogleFontsStore based on it
This commit is contained in:
32
src/entities/Font/model/store/fontshareStore.svelte.ts
Normal file
32
src/entities/Font/model/store/fontshareStore.svelte.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import type { FontshareParams } from '../../api';
|
||||
import { fetchFontshareFontsQuery } from '../services';
|
||||
import type { UnifiedFont } from '../types';
|
||||
import { BaseFontStore } from './baseFontStore.svelte';
|
||||
|
||||
/**
|
||||
* Fontshare store wrapping TanStack Query with runes
|
||||
*/
|
||||
export class FontshareStore extends BaseFontStore<FontshareParams> {
|
||||
constructor(initialParams: FontshareParams = {}) {
|
||||
super(initialParams);
|
||||
}
|
||||
|
||||
protected getQueryKey(params: FontshareParams) {
|
||||
return ['fontshare', params] as const;
|
||||
}
|
||||
|
||||
protected async fetchFn(params: FontshareParams): Promise<UnifiedFont[]> {
|
||||
return fetchFontshareFontsQuery(params);
|
||||
}
|
||||
|
||||
// Provider-specific methods (shortcuts)
|
||||
setSearch(search: string) {
|
||||
this.setParams({ q: search } as any);
|
||||
}
|
||||
}
|
||||
|
||||
export function createFontshareStore(params: FontshareParams = {}) {
|
||||
return new FontshareStore(params);
|
||||
}
|
||||
|
||||
export const fontshareStore = new FontshareStore();
|
||||
Reference in New Issue
Block a user