(
post: Post | ReadHistoryPost,
{ toastOnSuccess, blockedSource, feedId }: UseBlockPostProps = {},
)
| 98 | }; |
| 99 | |
| 100 | export 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 }), |
no test coverage detected