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

Function useQuestUpdates

packages/shared/src/hooks/useQuestUpdates.ts:63–153  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

61// screen. Otherwise completions that land while the button is unmounted are
62// lost and the badge stays stale until an unrelated refetch.
63export const useQuestUpdates = (): void => {
64 const queryClient = useQueryClient();
65 const { user } = useAuthContext();
66 const { logEvent } = useLogContext();
67 const { data, dataUpdatedAt } = useQuestDashboard();
68
69 const questDashboardQueryKey = generateQueryKey(
70 RequestKey.QuestDashboard,
71 user,
72 );
73 const invalidateQuestDashboard = useCallback(() => {
74 queryClient.invalidateQueries({
75 queryKey: questDashboardQueryKey,
76 exact: true,
77 });
78 }, [queryClient, questDashboardQueryKey]);
79
80 const shouldLogClaimableQuestRef = useRef(false);
81 const previousClaimableQuestSnapshotsRef = useRef<Map<
82 string,
83 ClaimableQuestSnapshot
84 > | null>(null);
85 const previousQuestDashboardUpdatedAtRef = useRef<number | null>(null);
86 const handleQuestDashboardRefresh = useCallback(() => {
87 shouldLogClaimableQuestRef.current = true;
88 invalidateQuestDashboard();
89 }, [invalidateQuestDashboard]);
90
91 useSubscription(
92 () => ({
93 query: QUEST_UPDATE_SUBSCRIPTION,
94 }),
95 {
96 next: handleQuestDashboardRefresh,
97 },
98 [user?.id],
99 );
100
101 useSubscription(
102 () => ({
103 query: QUEST_ROTATION_UPDATE_SUBSCRIPTION,
104 }),
105 {
106 next: handleQuestDashboardRefresh,
107 },
108 [user?.id],
109 );
110
111 useEffect(() => {
112 if (!data) {
113 return;
114 }
115
116 const currentClaimableQuestSnapshots = getQuestClaimableSnapshots(data);
117 const currentQuestDashboardUpdatedAt = dataUpdatedAt;
118 const didReceiveFreshQuestDashboard =
119 previousQuestDashboardUpdatedAtRef.current !==
120 currentQuestDashboardUpdatedAt;

Callers 1

QuestUpdatesSubscriberFunction · 0.90

Calls 7

useAuthContextFunction · 0.90
useLogContextFunction · 0.90
useQuestDashboardFunction · 0.90
generateQueryKeyFunction · 0.90
useSubscriptionFunction · 0.85
logEventFunction · 0.85

Tested by

no test coverage detected