Skip to content

Commit

Permalink
chore: comments for issue
Browse files Browse the repository at this point in the history
  • Loading branch information
capJavert committed Jan 20, 2025
1 parent 40ff90d commit 04b2243
Showing 1 changed file with 73 additions and 1 deletion.
74 changes: 73 additions & 1 deletion packages/shared/src/hooks/useTagAndSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import useMutateFilters from './useMutateFilters';
import type { Source } from '../graphql/sources';
import AlertContext from '../contexts/AlertContext';
import type { BooleanPromise } from '../components/filters/common';
import { generateQueryKey } from '../lib/query';
import { generateQueryKey, RequestKey } from '../lib/query';
import useDebounceFn from './useDebounceFn';
import { SharedFeedPage } from '../components/utilities';
import type { Origin } from '../lib/log';
import { LogEvent } from '../lib/log';
import type { AuthTriggersType } from '../lib/auth';
import { ContentPreferenceType } from '../graphql/contentPreference';

export interface TagActionArguments {
tags: Array<string>;
Expand Down Expand Up @@ -82,6 +83,29 @@ export default function useTagAndSource({
});
}, 100);

const invalidateContentPreferences = useCallback(
({
entity,
subQuery,
}: {
entity: ContentPreferenceType;
subQuery: RequestKey;
}) => {
queryClient.invalidateQueries({
queryKey: generateQueryKey(
RequestKey.ContentPreference,
user,
subQuery,
{
feedId: feedId || user?.id,
entity,
},
),
});
},
[queryClient, user, feedId],
);

const onFollowTags = useCallback(
async ({ tags, category, requireLogin }: TagActionArguments) => {
if (shouldShowLogin(requireLogin)) {
Expand All @@ -101,6 +125,11 @@ export default function useTagAndSource({

invalidateQueries();

invalidateContentPreferences({
entity: ContentPreferenceType.Keyword,
subQuery: RequestKey.UserFollowing,
});

return { successful: true };
},
[
Expand All @@ -115,6 +144,7 @@ export default function useTagAndSource({
alerts?.filter,
invalidateQueries,
shouldUpdateAlerts,
invalidateContentPreferences,
],
);

Expand All @@ -134,6 +164,11 @@ export default function useTagAndSource({

invalidateQueries();

invalidateContentPreferences({
entity: ContentPreferenceType.Keyword,
subQuery: RequestKey.UserFollowing,
});

return { successful: true };
},
[
Expand All @@ -144,6 +179,7 @@ export default function useTagAndSource({
showLogin,
unfollowTags,
invalidateQueries,
invalidateContentPreferences,
],
);

Expand All @@ -164,6 +200,11 @@ export default function useTagAndSource({

invalidateQueries();

invalidateContentPreferences({
entity: ContentPreferenceType.Keyword,
subQuery: RequestKey.UserBlocked,
});

return { successful: true };
},
[
Expand All @@ -175,6 +216,7 @@ export default function useTagAndSource({
blockTag,
postId,
invalidateQueries,
invalidateContentPreferences,
],
);

Expand All @@ -194,6 +236,11 @@ export default function useTagAndSource({

invalidateQueries();

invalidateContentPreferences({
entity: ContentPreferenceType.Keyword,
subQuery: RequestKey.UserBlocked,
});

return { successful: true };
},
[
Expand All @@ -205,6 +252,7 @@ export default function useTagAndSource({
unblockTag,
postId,
invalidateQueries,
invalidateContentPreferences,
],
);

Expand All @@ -225,6 +273,11 @@ export default function useTagAndSource({

invalidateQueries();

invalidateContentPreferences({
entity: ContentPreferenceType.Source,
subQuery: RequestKey.UserBlocked,
});

return { successful: true };
},
[
Expand All @@ -236,6 +289,7 @@ export default function useTagAndSource({
unblockSource,
postId,
invalidateQueries,
invalidateContentPreferences,
],
);

Expand All @@ -256,6 +310,11 @@ export default function useTagAndSource({

invalidateQueries();

invalidateContentPreferences({
entity: ContentPreferenceType.Source,
subQuery: RequestKey.UserBlocked,
});

return { successful: true };
},
[
Expand All @@ -267,6 +326,7 @@ export default function useTagAndSource({
blockSource,
postId,
invalidateQueries,
invalidateContentPreferences,
],
);

Expand All @@ -288,6 +348,11 @@ export default function useTagAndSource({

invalidateQueries();

invalidateContentPreferences({
entity: ContentPreferenceType.Source,
subQuery: RequestKey.UserFollowing,
});

return { successful: true };
},
[
Expand All @@ -299,6 +364,7 @@ export default function useTagAndSource({
followSource,
postId,
invalidateQueries,
invalidateContentPreferences,
],
);

Expand All @@ -320,6 +386,11 @@ export default function useTagAndSource({

invalidateQueries();

invalidateContentPreferences({
entity: ContentPreferenceType.Source,
subQuery: RequestKey.UserFollowing,
});

return { successful: true };
},
[
Expand All @@ -331,6 +402,7 @@ export default function useTagAndSource({
unfollowSource,
invalidateQueries,
showLogin,
invalidateContentPreferences,
],
);

Expand Down

0 comments on commit 04b2243

Please sign in to comment.