only push recently viewed if exists

This commit is contained in:
mbecker20
2024-06-02 04:43:01 -07:00
parent 8b537924fb
commit bc76b1c07e

View File

@@ -201,9 +201,15 @@ export const usePushRecentlyViewed = ({ type, id }: Types.ResourceTarget) => {
onSuccess: userInvalidate,
}).mutate;
const exists = useRead(`List${type as UsableResource}s`, {}).data?.find(
(r) => r.id === id
)
? true
: false;
useEffect(() => {
!!type && !!id && push({ resource: { type, id } });
}, [type, id, push]);
exists && push({ resource: { type, id } });
}, [exists, push]);
return () => push({ resource: { type, id } });
};