feat: show persisted investment data and sync state
Consume the provided resource-envelope API snapshot. Preserve financial snapshots during refresh, observe synchronization without importing, and fence late responses across account and connection changes.
This commit is contained in:
@@ -1,23 +1,44 @@
|
||||
import type { paths } from "@/shared/api";
|
||||
|
||||
type Meta =
|
||||
paths["/api/v1/tbank-sync/{id}"]["get"]["responses"][200]["content"]["application/json"]["resources"][number];
|
||||
type SectionState = {
|
||||
stale?: boolean;
|
||||
sourceError?: boolean;
|
||||
partial?: boolean;
|
||||
lastSuccessfulAt?: string | null;
|
||||
hasData: boolean;
|
||||
loading: boolean;
|
||||
error: boolean;
|
||||
refreshing: boolean;
|
||||
retry: () => void;
|
||||
};
|
||||
function section(query: {
|
||||
data: unknown;
|
||||
isError: boolean;
|
||||
isFetching: boolean;
|
||||
refetch: () => unknown;
|
||||
}): SectionState {
|
||||
function section(
|
||||
query: {
|
||||
data: unknown;
|
||||
meta?: Meta;
|
||||
isError: boolean;
|
||||
isFetching: boolean;
|
||||
refetch: () => unknown;
|
||||
},
|
||||
retry?: () => unknown,
|
||||
): SectionState {
|
||||
const error = query.isError || query.meta?.sync.state === "failed";
|
||||
return {
|
||||
stale: query.meta?.freshness === "stale",
|
||||
sourceError: query.meta?.sync.state === "failed",
|
||||
partial: query.meta?.availability === "partial",
|
||||
lastSuccessfulAt: query.meta?.lastSuccessfulAt,
|
||||
hasData: Boolean(query.data),
|
||||
loading: !query.data && !query.isError,
|
||||
error: query.isError,
|
||||
refreshing: Boolean(query.data) && query.isFetching,
|
||||
loading: !query.data && !error,
|
||||
error,
|
||||
refreshing:
|
||||
Boolean(query.data) &&
|
||||
(query.isFetching ||
|
||||
query.meta?.sync.state === "running" ||
|
||||
query.meta?.sync.state === "queued"),
|
||||
retry: () => {
|
||||
void query.refetch();
|
||||
void (retry ?? query.refetch)();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user