(
post: Post | ReadHistoryPost,
{ toastOnSuccess, blockedSource, feedId }: UseBlockPostProps = {},
)
| 71 | const ignoredCall = () => Promise.resolve({ successful: true }); |
| 72 | |
| 73 | export 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 }), |
no test coverage detected