feat/font-store-merge #32

Merged
ilia merged 10 commits from feat/font-store-merge into main 2026-04-10 05:13:40 +00:00
Showing only changes of commit a9e4633b64 - Show all commits

View File

@@ -5,7 +5,15 @@ import {
type InfiniteQueryObserverResult,
type QueryFunctionContext,
} from '@tanstack/query-core';
import type { ProxyFontsParams } from '../../../api';
import {
type ProxyFontsParams,
type ProxyFontsResponse,
fetchProxyFonts,
} from '../../../api';
import {
FontNetworkError,
FontResponseError,
} from '../../../lib/errors/errors';
import type { UnifiedFont } from '../../types';
/**
@@ -175,8 +183,24 @@ export class FontStore {
};
}
private async fetchPage(_params: ProxyFontsParams): Promise<FontPage> {
return { fonts: [], total: 0, limit: 0, offset: 0 };
private async fetchPage(params: ProxyFontsParams): Promise<FontPage> {
let response: ProxyFontsResponse;
try {
response = await fetchProxyFonts(params);
} catch (cause) {
throw new FontNetworkError(cause);
}
if (!response) throw new FontResponseError('response', response);
if (!response.fonts) throw new FontResponseError('response.fonts', response.fonts);
if (!Array.isArray(response.fonts)) throw new FontResponseError('response.fonts', response.fonts);
return {
fonts: response.fonts,
total: response.total ?? 0,
limit: response.limit ?? params.limit ?? 50,
offset: response.offset ?? params.offset ?? 0,
};
}
}