MCPcopy Create free account
hub / github.com/dailydotdev/apps / useCampaigns

Function useCampaigns

packages/shared/src/features/boost/useCampaigns.ts:40–89  ·  view source on GitHub ↗
({
  entityId,
  first = FIRST_DEFAULT_VALUE,
  enabled = true,
}: UseCampaignsProps = {})

Source from the content-addressed store, hash-verified

38};
39
40export const useCampaigns = ({
41 entityId,
42 first = FIRST_DEFAULT_VALUE,
43 enabled = true,
44}: UseCampaignsProps = {}): UsePostBoost => {
45 const { user } = useAuthContext();
46 const key = generateQueryKey(RequestKey.Campaigns, user, {
47 first,
48 entityId,
49 });
50 const queryResult = useInfiniteQuery({
51 queryKey: key,
52 queryFn: ({ pageParam }) =>
53 getCampaigns({
54 first,
55 after: pageParam,
56 entityId,
57 }),
58 initialPageParam: '',
59 getNextPageParam: (data, _, lastPageParam) => {
60 const nextPageparam = getNextPageParam(data?.pageInfo);
61
62 if (lastPageParam === nextPageparam) {
63 return null;
64 }
65
66 return getNextPageParam(data?.pageInfo);
67 },
68 enabled: !!user && !!enabled,
69 staleTime: StaleTime.Default,
70 });
71
72 const {
73 data: campaigns,
74 isPending,
75 isFetched,
76 isFetchingNextPage,
77 fetchNextPage,
78 } = queryResult;
79
80 return {
81 data: campaigns,
82 isLoading: isPending && !isFetched,
83 infiniteScrollingProps: {
84 isFetchingNextPage,
85 fetchNextPage,
86 canFetchMore: checkFetchMore(queryResult),
87 },
88 };
89};

Callers 2

AdsDashboardModalFunction · 0.90
PostAnalyticsPageFunction · 0.90

Calls 5

useAuthContextFunction · 0.90
generateQueryKeyFunction · 0.90
getCampaignsFunction · 0.90
getNextPageParamFunction · 0.90
checkFetchMoreFunction · 0.90

Tested by

no test coverage detected