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

Function useBlockPostPanel

packages/shared/src/hooks/post/useBlockPostPanel.ts:73–273  ·  view source on GitHub ↗
(
  post: Post | ReadHistoryPost,
  { toastOnSuccess, blockedSource, feedId }: UseBlockPostProps = {},
)

Source from the content-addressed store, hash-verified

71const ignoredCall = () => Promise.resolve({ successful: true });
72
73export const useBlockPostPanel = (
74 post: Post | ReadHistoryPost,
75 { toastOnSuccess, blockedSource, feedId }: UseBlockPostProps = {},
76): UseBlockPost => {
77 const { openModal } = useLazyModal();
78 const { displayToast } = useToastNotification();
79 const { onBlockTags, onBlockSource, onUnblockTags, onUnblockSource } =
80 useTagAndSource({
81 origin: Origin.TagsFilter,
82 postId: post?.id,
83 shouldInvalidateQueries: false,
84 feedId,
85 });
86 const client = useQueryClient();
87 const { user } = useAuthContext();
88 const { checkHasCompleted, completeAction } = useActions();
89 const key = generateQueryKey(RequestKey.Post, user, `block:${post?.id}`);
90 const { data } = useQuery<BlockData>({
91 queryKey: key,
92 queryFn: () => client.getQueryData(key),
93 initialData: {},
94 ...disabledRefetch,
95 });
96 const setShowTagsPanel = useCallback(
97 (params: BlockData) =>
98 client.setQueryData<BlockData>(key, (current) => ({
99 ...current,
100 ...params,
101 })),
102 [client, key],
103 );
104
105 const value = useMemo<BlockData>(
106 () => ({
107 ...data,
108 showTagsPanel: checkHasCompleted(ActionType.HideBlockPanel)
109 ? undefined
110 : data?.showTagsPanel,
111 }),
112 [data, checkHasCompleted],
113 );
114
115 const updateFeedPreferences = useCallback(
116 async (
117 blocks: string[],
118 unblocks: string[],
119 shouldBlockSource?: boolean,
120 ) => {
121 const onUpdateSource = shouldBlockSource
122 ? onBlockSource
123 : onUnblockSource;
124
125 const results = await Promise.all([
126 blocks.length ? onBlockTags({ tags: blocks }) : ignoredCall(),
127 unblocks.length ? onUnblockTags({ tags: unblocks }) : ignoredCall(),
128 isNullOrUndefined(shouldBlockSource)
129 ? ignoredCall()
130 : onUpdateSource({ source: post.source }),

Callers 12

ArticleGrid.tsxFile · 0.90
PostActionsV1Function · 0.90
PostActionsFunction · 0.90
MobilePostFloatingBarFunction · 0.90
MobilePostFloatingBarV1Function · 0.90
PostTagsPanelFunction · 0.90
FocusCardActionBarFunction · 0.90
usePostMenuActionsFunction · 0.90
useCardActionsFunction · 0.90
useHiddenFeedbackPanelFunction · 0.90
useHidePostFunction · 0.90

Calls 13

useLazyModalFunction · 0.90
useToastNotificationFunction · 0.90
useAuthContextFunction · 0.90
useActionsFunction · 0.90
generateQueryKeyFunction · 0.90
isNullOrUndefinedFunction · 0.90
getBlockedMessageFunction · 0.90
getBlockedLengthFunction · 0.90
useTagAndSourceFunction · 0.85
ignoredCallFunction · 0.85
displayToastFunction · 0.85
getParamsFunction · 0.85

Tested by

no test coverage detected