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

Function useBlockPostPanel

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

Source from the content-addressed store, hash-verified

98};
99
100export const useBlockPostPanel = (
101 post: Post | ReadHistoryPost,
102 { toastOnSuccess, blockedSource, feedId }: UseBlockPostProps = {},
103): UseBlockPost => {
104 const { openModal } = useLazyModal();
105 const { displayToast } = useToastNotification();
106 const { onBlockTags, onBlockSource, onUnblockTags, onUnblockSource } =
107 useTagAndSource({
108 origin: Origin.TagsFilter,
109 postId: post?.id,
110 shouldInvalidateQueries: false,
111 feedId,
112 });
113 const client = useQueryClient();
114 const { user } = useAuthContext();
115 const { checkHasCompleted, completeAction } = useActions();
116 const key = getBlockPanelQueryKey(user, post?.id);
117 const { data } = useQuery<BlockData>({
118 queryKey: key,
119 queryFn: () => client.getQueryData(key),
120 initialData: {},
121 ...disabledRefetch,
122 });
123 const setShowTagsPanel = useCallback(
124 (params: BlockData) =>
125 client.setQueryData<BlockData>(key, (current) => ({
126 ...current,
127 ...params,
128 })),
129 [client, key],
130 );
131
132 const value = useMemo<BlockData>(
133 () => ({
134 ...data,
135 showTagsPanel: checkHasCompleted(ActionType.HideBlockPanel)
136 ? undefined
137 : data?.showTagsPanel,
138 }),
139 [data, checkHasCompleted],
140 );
141
142 const updateFeedPreferences = useCallback(
143 async (
144 blocks: string[],
145 unblocks: string[],
146 shouldBlockSource?: boolean,
147 ) => {
148 const onUpdateSource = shouldBlockSource
149 ? onBlockSource
150 : onUnblockSource;
151
152 const results = await Promise.all([
153 blocks.length ? onBlockTags({ tags: blocks }) : ignoredCall(),
154 unblocks.length ? onUnblockTags({ tags: unblocks }) : ignoredCall(),
155 isNullOrUndefined(shouldBlockSource)
156 ? ignoredCall()
157 : onUpdateSource({ source: post.source }),

Callers 11

ActionBarFunction · 0.90
ArticleGrid.tsxFile · 0.90
PostActionsV1Function · 0.90
PostActionsFunction · 0.90
PostCapsuleFunction · 0.90
PostTagsPanelFunction · 0.90
usePostMenuActionsFunction · 0.90
useCardActionsFunction · 0.90
useHiddenFeedbackPanelFunction · 0.90
useHidePostFunction · 0.90

Calls 14

useLazyModalFunction · 0.90
useToastNotificationFunction · 0.90
useAuthContextFunction · 0.90
useActionsFunction · 0.90
isNullOrUndefinedFunction · 0.90
getBlockedMessageFunction · 0.90
getBlockedLengthFunction · 0.90
useTagAndSourceFunction · 0.85
getBlockPanelQueryKeyFunction · 0.85
ignoredCallFunction · 0.85
displayToastFunction · 0.85
openModalFunction · 0.85

Tested by

no test coverage detected