From 32b72854a86099221111c78c0113fe2b224b7693 Mon Sep 17 00:00:00 2001 From: Orion Wolf-Hubbard Date: Wed, 8 Jan 2025 13:58:02 -0500 Subject: [PATCH] chore: refactor to accept external user data and avoid making the call internally EB-832 --- packages/favorites/src/lib/Favorites.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/favorites/src/lib/Favorites.tsx b/packages/favorites/src/lib/Favorites.tsx index c62403e3a..ecb94d376 100644 --- a/packages/favorites/src/lib/Favorites.tsx +++ b/packages/favorites/src/lib/Favorites.tsx @@ -5,7 +5,7 @@ import type { Favorite } from './utils'; import { useFavoritesQuery, useSubmitFavorites, sendUpdateMessage, openMaxModal } from './utils'; import { AV_INTERNAL_GLOBALS, MAX_FAVORITES } from './constants'; -type StatusUnion = 'idle' | 'error' | 'loading' | 'success'; +type StatusUnion = 'idle' | 'error' | 'loading' | 'reloading' | 'success'; type FavoritesContextType = { favorites?: Favorite[]; @@ -21,14 +21,21 @@ const FavoritesContext = createContext(null); export const FavoritesProvider = ({ children, onFavoritesChange, + settingsFavorites, + settingsStatus, }: { children: React.ReactNode; onFavoritesChange?: (favorites: Favorite[]) => void; + settingsFavorites?: Favorite[]; + settingsStatus?: StatusUnion; }): JSX.Element => { const [lastClickedFavoriteId, setLastClickedFavoriteId] = useState(''); const queryClient = useQueryClient(); - const { data: favorites, status: queryStatus } = useFavoritesQuery(); + const { data: favorites, status: queryStatus } = settingsStatus ? { + data: settingsFavorites, + status: settingsStatus, + } : useFavoritesQuery(); const { submitFavorites, status: mutationStatus } = useSubmitFavorites({ onMutationStart(targetFavoriteId) { @@ -155,6 +162,7 @@ export const useFavorites = ( let status: MergedStatusUnion = 'initLoading'; if (queryStatus === 'loading') status = 'initLoading'; + if (queryStatus === 'reloading') status = 'reloading'; if (mutationStatus === 'loading') status = 'reloading'; if (queryStatus === 'error' || mutationStatus === 'error') status = 'error'; if (queryStatus === 'success' && (mutationStatus === 'success' || mutationStatus === 'idle')) status = 'success';