feat: add quiet reading with rare confirmations
Part of the quiet-user-feedback change; docs and specs land in their own repositories.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { hashKey, useQueryClient } from "@tanstack/react-query";
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { ApiErrorCode, apiErrorCode, isApiErrorCode } from "@/shared/api";
|
||||
|
||||
@@ -29,15 +29,28 @@ function useBrokerageOperationHistory(
|
||||
cursor: cursors.at(-1),
|
||||
});
|
||||
|
||||
const isInvalidCursor = isApiErrorCode(
|
||||
apiErrorCode(operations.error),
|
||||
ApiErrorCode.InvalidOperationsCursor,
|
||||
);
|
||||
|
||||
const isRecoveringInvalidCursor = cursors.length > 0 && isInvalidCursor;
|
||||
|
||||
const reset = () => setPagination({ cursors: [], scope });
|
||||
|
||||
useEffect(() => {
|
||||
if (!isRecoveringInvalidCursor) return;
|
||||
|
||||
const timeout = setTimeout(() => {
|
||||
setPagination({ cursors: [], scope });
|
||||
void client.invalidateQueries({ exact: true, queryKey });
|
||||
}, 0);
|
||||
|
||||
return () => clearTimeout(timeout);
|
||||
}, [client, isRecoveringInvalidCursor, queryKey, scope]);
|
||||
|
||||
const retry = (retryScreen: () => unknown) => {
|
||||
if (
|
||||
isApiErrorCode(
|
||||
apiErrorCode(operations.error),
|
||||
ApiErrorCode.InvalidOperationsCursor,
|
||||
)
|
||||
) {
|
||||
if (isInvalidCursor) {
|
||||
reset();
|
||||
void client.invalidateQueries({
|
||||
exact: true,
|
||||
@@ -49,6 +62,7 @@ function useBrokerageOperationHistory(
|
||||
|
||||
return {
|
||||
hasPrevious: cursors.length > 0,
|
||||
isRecoveringInvalidCursor,
|
||||
onNext: () => {
|
||||
if (operations.data?.nextCursor)
|
||||
setPagination({
|
||||
|
||||
Reference in New Issue
Block a user