feat/font-store-merge #32
@@ -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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user