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,6 +1,7 @@
|
||||
import { useDebouncedValue } from "@mantine/hooks";
|
||||
import { useSearchParams } from "react-router";
|
||||
import { useBondSearch } from "@/entities/bond";
|
||||
import { useScreenSync } from "@/features/tbank-connection";
|
||||
import { apiErrorCode } from "@/shared/api";
|
||||
import { instrumentLogoUrl } from "@/shared/lib";
|
||||
|
||||
@@ -11,15 +12,23 @@ function useBondsPageVm() {
|
||||
const query = params.get("q") ?? "";
|
||||
const [debounced] = useDebouncedValue(query.trim(), SEARCH_DEBOUNCE_MS);
|
||||
const result = useBondSearch(debounced);
|
||||
const sync = useScreenSync({ screen: "bonds", query: debounced }, [result]);
|
||||
const waiting = query.trim() !== debounced;
|
||||
return {
|
||||
query,
|
||||
setQuery: (q: string) => setParams(q ? { q } : {}, { replace: true }),
|
||||
loading: query.trim().length >= 2 && (waiting || result.isLoading),
|
||||
error: result.isError,
|
||||
loading:
|
||||
query.trim().length >= 2 &&
|
||||
(waiting ||
|
||||
(!result.data &&
|
||||
!result.isError &&
|
||||
result.meta?.sync.state !== "failed")),
|
||||
error: result.isError || sync.sourceError || sync.transportError,
|
||||
refreshing: sync.refreshing,
|
||||
partial: result.meta?.availability === "partial",
|
||||
code: apiErrorCode(result.error),
|
||||
retry: () => {
|
||||
void result.refetch();
|
||||
void sync.refresh();
|
||||
},
|
||||
ready: debounced.length >= 2 && !waiting && Boolean(result.data),
|
||||
items:
|
||||
|
||||
Reference in New Issue
Block a user