-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add block user option on post context menu #4053
Changes from 26 commits
5a17ffe
0540f79
8be4262
eef302c
63e5977
88066b5
08de8e0
aa74858
9b01e41
aecc124
4388eb2
02706e2
f9f7bbc
0271bc1
3d6d522
b2ac887
a8194bf
a190049
a4d967d
e3dd167
7abf0c8
50466d5
fcb8a0d
1fd60e5
921f5cf
ed004e1
38898f5
adbb414
10cdb3d
63da103
8a92e2f
7a582eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,30 +7,30 @@ import classNames from 'classnames'; | |
import useFeedSettings from '../hooks/useFeedSettings'; | ||
import useReportPost from '../hooks/useReportPost'; | ||
import type { Post } from '../graphql/posts'; | ||
import { UserVote, isVideoPost } from '../graphql/posts'; | ||
import { isVideoPost, UserVote } from '../graphql/posts'; | ||
import { | ||
TrashIcon, | ||
HammerIcon, | ||
EyeIcon, | ||
AddUserIcon, | ||
BellAddIcon, | ||
BellSubscribedIcon, | ||
BlockIcon, | ||
FlagIcon, | ||
PlusIcon, | ||
EditIcon, | ||
UpvoteIcon, | ||
DownvoteIcon, | ||
SendBackwardIcon, | ||
BringForwardIcon, | ||
PinIcon, | ||
BellSubscribedIcon, | ||
ShareIcon, | ||
DownvoteIcon, | ||
EditIcon, | ||
EyeIcon, | ||
FlagIcon, | ||
FolderIcon, | ||
HammerIcon, | ||
MiniCloseIcon, | ||
MinusIcon, | ||
BellAddIcon, | ||
AddUserIcon, | ||
PinIcon, | ||
PlusIcon, | ||
RemoveUserIcon, | ||
FolderIcon, | ||
SendBackwardIcon, | ||
ShareIcon, | ||
ShieldIcon, | ||
ShieldWarningIcon, | ||
TrashIcon, | ||
UpvoteIcon, | ||
} from './icons'; | ||
import type { ReportedCallback } from './modals'; | ||
import useTagAndSource from '../hooks/useTagAndSource'; | ||
|
@@ -63,7 +63,10 @@ import { useBookmarkReminder } from '../hooks/notifications'; | |
import { BookmarkReminderIcon } from './icons/Bookmark/Reminder'; | ||
import { useSourceActionsFollow } from '../hooks/source/useSourceActionsFollow'; | ||
import { useContentPreference } from '../hooks/contentPreference/useContentPreference'; | ||
import { ContentPreferenceType } from '../graphql/contentPreference'; | ||
import { | ||
ContentPreferenceStatus, | ||
ContentPreferenceType, | ||
} from '../graphql/contentPreference'; | ||
import { isFollowingContent } from '../hooks/contentPreference/types'; | ||
import { useIsSpecialUser } from '../hooks/auth/useIsSpecialUser'; | ||
import { useActiveFeedContext } from '../contexts'; | ||
|
@@ -135,8 +138,7 @@ export default function PostOptionsMenu({ | |
const { logEvent } = useContext(LogContext); | ||
const { hidePost, unhidePost } = useReportPost(); | ||
const { openSharePost } = useSharePost(origin); | ||
const { follow, unfollow } = useContentPreference(); | ||
|
||
const { follow, unfollow, unblock } = useContentPreference(); | ||
const { openModal } = useLazyModal(); | ||
|
||
const { | ||
|
@@ -156,6 +158,8 @@ export default function PostOptionsMenu({ | |
(excludedSource) => excludedSource.id === post?.source?.id, | ||
); | ||
}, [feedSettings?.excludeSources, post?.source?.id]); | ||
const isBlockedAuthor = | ||
post?.author?.contentPreference?.status === ContentPreferenceStatus.Blocked; | ||
|
||
const shouldShowSubscribe = | ||
isLoggedIn && | ||
|
@@ -456,6 +460,7 @@ export default function PostOptionsMenu({ | |
const shouldShowFollow = | ||
!useIsSpecialUser({ userId: post?.author?.id }) && | ||
post?.author && | ||
!isBlockedAuthor && | ||
isLoggedIn; | ||
|
||
if (shouldShowFollow) { | ||
|
@@ -495,11 +500,51 @@ export default function PostOptionsMenu({ | |
postOptions.push({ | ||
icon: <MenuIcon Icon={BlockIcon} />, | ||
label: isSourceBlocked | ||
? `Show posts from ${post?.source?.name}` | ||
: `Don't show posts from ${post?.source?.name}`, | ||
? `Unblock ${post?.source?.name}` | ||
: `Block ${post?.source?.name}`, | ||
action: isSourceBlocked ? onUnblockSourceClick : onBlockSourceClick, | ||
}); | ||
|
||
if (post?.author && post?.author?.id !== user?.id) { | ||
postOptions.push({ | ||
icon: <MenuIcon Icon={BlockIcon} />, | ||
label: isBlockedAuthor | ||
? `Unblock ${post.author.name}` | ||
: `Block ${post.author.name}`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should be different my feed vs custom feed but raised it here. |
||
action: async () => { | ||
const clearCache = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe best to abstract this above in it's own function for readability? |
||
const postQueryKey = getPostByIdKey(post.id); | ||
const postCache = client.getQueryData(postQueryKey); | ||
if (postCache) { | ||
client.invalidateQueries({ queryKey: postQueryKey }); | ||
} | ||
}; | ||
|
||
if (!isBlockedAuthor) { | ||
openModal({ | ||
type: LazyModal.ReportUser, | ||
props: { | ||
offendingUser: post.author, | ||
defaultBlockUser: true, | ||
onBlockUser: clearCache, | ||
...(isCustomFeed && { feedId: customFeedId }), | ||
}, | ||
}); | ||
return; | ||
} | ||
|
||
await unblock({ | ||
id: post.author.id, | ||
entity: ContentPreferenceType.User, | ||
entityName: post.author.name, | ||
feedId: router.query.slugOrId ? `${router.query.slugOrId}` : null, | ||
}); | ||
|
||
clearCache(); | ||
}, | ||
}); | ||
} | ||
|
||
if (video && isVideoPost(post)) { | ||
const isEnabled = checkSettingsEnabledState(video.id); | ||
const label = isEnabled ? `Don't show` : 'Show'; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels like the
Block
can be misleading that it will block the source across the board. Maybe saying "Block Source from this Feed" or something similar. Either way, this is non-blocking. Just some thought about the new labe.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I've raised the issue as well before. I don't like that we use the same wording for a global block and just removing someone of a feed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change comes from the slack thread in description, but feel free to propose some changes in slack and I can change in minutes ✔️