Enable every plugin recommended preset and replace Biome with ESLint formatting. Preserve API contracts and JSX whitespace; verify source, tests, builds and tooling.
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import type { paths } from "@/shared/api";
|
|
|
|
type Meta
|
|
= paths["/api/v1/tbank-sync/{id}"]["get"]["responses"][200]["content"]["application/json"]["resources"][number];
|
|
type SectionState = {
|
|
error: boolean;
|
|
hasData: boolean;
|
|
lastSuccessfulAt?: null | string;
|
|
loading: boolean;
|
|
partial?: boolean;
|
|
refreshing: boolean;
|
|
retry: () => void;
|
|
sourceError?: boolean;
|
|
stale?: boolean;
|
|
};
|
|
function section(
|
|
query: {
|
|
data: unknown;
|
|
isError: boolean;
|
|
isFetching: boolean;
|
|
meta?: Meta;
|
|
refetch: () => unknown;
|
|
},
|
|
retry?: () => unknown,
|
|
): SectionState {
|
|
const isError = query.isError || query.meta?.sync.state === "failed";
|
|
return {
|
|
error: isError,
|
|
hasData: Boolean(query.data),
|
|
lastSuccessfulAt: query.meta?.lastSuccessfulAt,
|
|
loading: !query.data && !isError,
|
|
partial: query.meta?.availability === "partial",
|
|
refreshing:
|
|
Boolean(query.data)
|
|
&& (query.isFetching
|
|
|| query.meta?.sync.state === "running"
|
|
|| query.meta?.sync.state === "queued"),
|
|
retry: () => {
|
|
void (retry ?? query.refetch)();
|
|
},
|
|
sourceError: query.meta?.sync.state === "failed",
|
|
stale: query.meta?.freshness === "stale",
|
|
};
|
|
}
|
|
|
|
export { section, type SectionState };
|