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

Function useStopBoost

packages/shared/src/features/boost/useStopBoost.ts:55–101  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

53}
54
55export const useStopBoost = (): UseStopBoost => {
56 const { user } = useAuthContext();
57 const client = useQueryClient();
58 const { showPrompt } = usePrompt();
59 const { onCancelBoost, isLoadingCancel } = useCampaignMutation({});
60
61 const clearBoostedFlag = (campaign: Campaign) => {
62 const id = campaign.referenceId;
63
64 if (campaign.type === CampaignType.Post) {
65 updatePostCache(client, id, (old) => ({
66 flags: withoutCampaign(old.flags),
67 }));
68
69 client.setQueryData<PostData>(getPostByIdKey(id), (old) =>
70 old
71 ? {
72 ...old,
73 post: { ...old.post, flags: withoutCampaign(old.post.flags) },
74 }
75 : old,
76 );
77 }
78
79 if (campaign.type === CampaignType.Squad) {
80 client.setQueryData<Squad>(
81 generateQueryKey(RequestKey.Squad, user, campaign.source?.handle),
82 (old) => (old ? { ...old, flags: withoutCampaign(old.flags) } : old),
83 );
84 }
85 };
86
87 const onStopBoost = async (campaign: Campaign) => {
88 if (!(await showPrompt(stopBoostPromptOptions))) {
89 return;
90 }
91
92 // The mutation already shows a toast when it fails
93 const data = await onCancelBoost(campaign).catch(() => null);
94
95 if (data?.transactionId) {
96 clearBoostedFlag(campaign);
97 }
98 };
99
100 return { onStopBoost, isStopping: isLoadingCancel };
101};

Callers 1

BoostsListFunction · 0.90

Calls 3

useAuthContextFunction · 0.90
usePromptFunction · 0.90
useCampaignMutationFunction · 0.90

Tested by

no test coverage detected