Skip to content

Commit

Permalink
feat: add enabled prop
Browse files Browse the repository at this point in the history
  • Loading branch information
ha3 committed Dec 3, 2023
1 parent 0eb314a commit 2716648
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/recommend-react/src/FrequentlyBoughtTogether.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const UncontrolledFrequentlyBoughtTogether = createFrequentlyBoughtTogetherCompo

export type UseFrequentlyBoughtTogetherProps<TObject> = OptionalRecommendClient<
GetFrequentlyBoughtTogetherProps<TObject>
>;
> & { enabled?: boolean };

export type FrequentlyBoughtTogetherProps<
TObject
Expand Down
2 changes: 1 addition & 1 deletion packages/recommend-react/src/RelatedProducts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const UncontrolledRelatedProducts = createRelatedProductsComponent({

export type UseRelatedProductsProps<TObject> = OptionalRecommendClient<
GetRelatedProductsProps<TObject>
>;
> & { enabled?: boolean };

export type RelatedProductsProps<TObject> = UseRelatedProductsProps<TObject> &
Omit<
Expand Down
2 changes: 1 addition & 1 deletion packages/recommend-react/src/TrendingFacets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const UncontrolledTrendingFacets = createTrendingFacetsComponent({

export type UseTrendingFacetsProps<TObject> = OptionalRecommendClient<
GetTrendingFacetsProps<TObject>
>;
> & { enabled?: boolean };

export type TrendingFacetsProps<TObject> = UseTrendingFacetsProps<TObject> &
Omit<
Expand Down
2 changes: 1 addition & 1 deletion packages/recommend-react/src/TrendingItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const UncontrolledTrendingItems = createTrendingItemsComponent({

export type UseTrendingItemsProps<TObject> = OptionalRecommendClient<
GetTrendingItemsProps<TObject>
>;
> & { enabled?: boolean };

export type TrendingItemsProps<TObject> = UseTrendingItemsProps<TObject> &
Omit<
Expand Down
6 changes: 6 additions & 0 deletions packages/recommend-react/src/useFrequentlyBoughtTogether.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useStableValue } from './useStableValue';
import { useStatus } from './useStatus';

export function useFrequentlyBoughtTogether<TObject>({
enabled = true,
indexName,
maxRecommendations,
objectIDs: userObjectIDs,
Expand All @@ -38,6 +39,10 @@ export function useFrequentlyBoughtTogether<TObject>({
}, [userTransformItems]);

useEffect(() => {
if (!enabled) {
return;
}

const param = {
indexName,
maxRecommendations,
Expand Down Expand Up @@ -90,6 +95,7 @@ export function useFrequentlyBoughtTogether<TObject>({
});
return () => {};
}, [
enabled,
indexName,
maxRecommendations,
objectIDs,
Expand Down
10 changes: 9 additions & 1 deletion packages/recommend-react/src/useRecommendations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import { useAlgoliaAgent } from './useAlgoliaAgent';
import { useStableValue } from './useStableValue';
import { useStatus } from './useStatus';

export type UseRecommendationsProps<TObject> = GetRecommendationsProps<TObject>;
export type UseRecommendationsProps<
TObject
> = GetRecommendationsProps<TObject> & { enabled?: boolean };

export function useRecommendations<TObject>({
enabled = true,
fallbackParameters: userFallbackParameters,
indexName,
maxRecommendations,
Expand All @@ -38,6 +41,10 @@ export function useRecommendations<TObject>({
}, [userTransformItems]);

useEffect(() => {
if (!enabled) {
return;
}

setStatus('loading');
getRecommendations({
fallbackParameters,
Expand All @@ -54,6 +61,7 @@ export function useRecommendations<TObject>({
setStatus('idle');
});
}, [
enabled,
fallbackParameters,
indexName,
maxRecommendations,
Expand Down
6 changes: 6 additions & 0 deletions packages/recommend-react/src/useRelatedProducts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useStableValue } from './useStableValue';
import { useStatus } from './useStatus';

export function useRelatedProducts<TObject>({
enabled = true,
fallbackParameters: userFallbackParameters,
indexName,
maxRecommendations,
Expand Down Expand Up @@ -40,6 +41,10 @@ export function useRelatedProducts<TObject>({
}, [userTransformItems]);

useEffect(() => {
if (!enabled) {
return;
}

const param = {
fallbackParameters,
indexName,
Expand Down Expand Up @@ -95,6 +100,7 @@ export function useRelatedProducts<TObject>({
return () => {};
}, [
client,
enabled,
fallbackParameters,
hasProvider,
indexName,
Expand Down
6 changes: 6 additions & 0 deletions packages/recommend-react/src/useTrendingFacets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useAlgoliaAgent } from './useAlgoliaAgent';
import { useStatus } from './useStatus';

export function useTrendingFacets<TObject>({
enabled = true,
indexName,
maxRecommendations,
recommendClient,
Expand All @@ -35,6 +36,10 @@ export function useTrendingFacets<TObject>({
}, [userTransformItems]);

useEffect(() => {
if (!enabled) {
return;
}

const param = {
model: 'trending-facets' as TrendingModel,
indexName,
Expand Down Expand Up @@ -79,6 +84,7 @@ export function useTrendingFacets<TObject>({
});
return () => {};
}, [
enabled,
indexName,
maxRecommendations,
client,
Expand Down
6 changes: 6 additions & 0 deletions packages/recommend-react/src/useTrendingItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useStableValue } from './useStableValue';
import { useStatus } from './useStatus';

export function useTrendingItems<TObject>({
enabled = true,
fallbackParameters: userFallbackParameters,
indexName,
maxRecommendations,
Expand Down Expand Up @@ -40,6 +41,10 @@ export function useTrendingItems<TObject>({
}, [userTransformItems]);

useEffect(() => {
if (!enabled) {
return;
}

const param: BatchQuery<TObject> = {
model: 'trending-items',
fallbackParameters,
Expand Down Expand Up @@ -86,6 +91,7 @@ export function useTrendingItems<TObject>({
});
return () => {};
}, [
enabled,
fallbackParameters,
indexName,
maxRecommendations,
Expand Down

0 comments on commit 2716648

Please sign in to comment.