fix: avoid unnecessary favorites reloads
All checks were successful
Deploy Staging (terry-wallet-login) / deploy (push) Successful in 1m20s
All checks were successful
Deploy Staging (terry-wallet-login) / deploy (push) Successful in 1m20s
This commit is contained in:
@@ -23,6 +23,7 @@ type FavoriteStatus = "unknown" | "favorited" | "notFavorited";
|
||||
type FavoritesContextValue = {
|
||||
favoriteIds: Set<string>;
|
||||
pendingIds: Set<string>;
|
||||
mutationVersion: number;
|
||||
statusFor: (resourceId: string) => FavoriteStatus;
|
||||
ensureFavoriteIds: (resourceIds: string[]) => Promise<void>;
|
||||
toggleFavorite: (resourceId: string) => Promise<boolean | null>;
|
||||
@@ -45,6 +46,7 @@ export function FavoritesProvider({ children }: { children: ReactNode }) {
|
||||
const [favoriteIds, setFavoriteIds] = useState<Set<string>>(() => new Set());
|
||||
const [knownIds, setKnownIds] = useState<Set<string>>(() => new Set());
|
||||
const [pendingIds, setPendingIds] = useState<Set<string>>(() => new Set());
|
||||
const [mutationVersion, setMutationVersion] = useState(0);
|
||||
const pendingAfterLoginRef = useRef<string | null>(null);
|
||||
const lastAddressRef = useRef<string | null>(null);
|
||||
const knownIdsRef = useRef<Set<string>>(new Set());
|
||||
@@ -170,6 +172,7 @@ export function FavoritesProvider({ children }: { children: ReactNode }) {
|
||||
showToast(
|
||||
currentlyFavorite ? t("favoriteRemoved") : t("favoriteAdded"),
|
||||
);
|
||||
setMutationVersion((value) => value + 1);
|
||||
return nextFavorited;
|
||||
} catch (error) {
|
||||
markFavorite(resourceId, currentlyFavorite);
|
||||
@@ -221,6 +224,7 @@ export function FavoritesProvider({ children }: { children: ReactNode }) {
|
||||
() => ({
|
||||
favoriteIds,
|
||||
pendingIds,
|
||||
mutationVersion,
|
||||
statusFor,
|
||||
ensureFavoriteIds,
|
||||
toggleFavorite,
|
||||
@@ -230,6 +234,7 @@ export function FavoritesProvider({ children }: { children: ReactNode }) {
|
||||
ensureFavoriteIds,
|
||||
favoriteIds,
|
||||
markFavorite,
|
||||
mutationVersion,
|
||||
pendingIds,
|
||||
statusFor,
|
||||
toggleFavorite,
|
||||
|
||||
Reference in New Issue
Block a user