From d542862e7bbbb7bb401acaeb5f51e5568d9cc282 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Tue, 18 Feb 2025 14:42:49 -0700 Subject: [PATCH] favorites update --- web/src/context/Users/UserConfigProvider.tsx | 1 + web/src/context/Users/useFavoriteProvider.tsx | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/web/src/context/Users/UserConfigProvider.tsx b/web/src/context/Users/UserConfigProvider.tsx index ba5d1ba9c..22635c229 100644 --- a/web/src/context/Users/UserConfigProvider.tsx +++ b/web/src/context/Users/UserConfigProvider.tsx @@ -13,6 +13,7 @@ import { import { checkIfUserIsAdmin } from './helpers'; import { useUserOrganization } from './useUserOrganization'; import { useInviteUser } from './useInviteUser'; +import { useWhyDidYouUpdate } from 'ahooks'; export const useUserConfigProvider = ({ userInfo }: { userInfo: BusterUserResponse | null }) => { const isAnonymousUser = useSupabaseContext((state) => state.isAnonymousUser); diff --git a/web/src/context/Users/useFavoriteProvider.tsx b/web/src/context/Users/useFavoriteProvider.tsx index 64ea04a96..fbafb568e 100644 --- a/web/src/context/Users/useFavoriteProvider.tsx +++ b/web/src/context/Users/useFavoriteProvider.tsx @@ -1,6 +1,10 @@ import { useMemoizedFn } from 'ahooks'; import { useSocketQueryEmitOn, useSocketQueryMutation } from '@/api/buster_socket_query'; import { queryKeys } from '@/api/query_keys'; +import type { BusterUserFavorite } from '@/api/asset_interfaces'; +import isEmpty from 'lodash/isEmpty'; + +const DEFAULT_FAVORITES: BusterUserFavorite[] = []; export const useFavoriteProvider = () => { const { data: userFavorites, refetch: refreshFavoritesList } = useSocketQueryEmitOn({ @@ -42,7 +46,7 @@ export const useFavoriteProvider = () => { return { bulkEditFavorites, refreshFavoritesList, - userFavorites: userFavorites || [], + userFavorites: isEmpty(userFavorites) ? DEFAULT_FAVORITES : userFavorites, addItemToFavorite, removeItemFromFavorite };