Files
frontend/src/features/instrument-details/model/section.ts
T
codex-bot 8ce1e8e444
Frontend verify / commits (push) Skipped
Frontend verify / security (push) Successful in 9s
Frontend verify / verify (push) Failing after 7m5s
feat(investments): warn and offer retry after exhausted read retries (WealthLedger/frontend#55) (#136)
2026-11-03 09:49:08 +03:00

46 lines
1.0 KiB
TypeScript

import { type InvestmentResourceMeta, readRetry } from "@/shared/api";
type SectionState = {
error: boolean;
hasData: boolean;
loading: boolean;
partial?: boolean;
readRetry?: ReturnType<typeof readRetry>;
};
function hasSectionData(data: unknown) {
return data !== undefined;
}
function section(query: {
data: unknown;
error?: unknown;
isError: boolean;
isFetching?: boolean;
meta?: InvestmentResourceMeta;
refetch?: () => Promise<unknown>;
}): SectionState {
const isError = query.isError || query.meta?.lastAttempt.state === "failed";
const hasData = hasSectionData(query.data);
return {
error: isError,
hasData,
loading: !hasData && !isError,
partial: query.meta?.completeness === "incomplete",
// Each section retries only its own GET, so sections recover independently.
readRetry: query.refetch
? readRetry([
{
error: query.error,
isError: query.isError,
isFetching: query.isFetching ?? false,
refetch: query.refetch,
},
])
: undefined,
};
}
export { section, type SectionState };