-
Notifications
You must be signed in to change notification settings - Fork 3
feat: 커뮤니티 사용자 차단 분리 #549
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
Merged
Merged
feat: 커뮤니티 사용자 차단 분리 #549
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
apps/web/src/app/community/_hooks/useBlockCommunityUser.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| "use client"; | ||
|
|
||
| import { Ban } from "lucide-react"; | ||
| import type { ComponentType, SVGProps } from "react"; | ||
| import { postBlockUser } from "@/apis/users"; | ||
| import { showIconToast } from "@/lib/toast/showIconToast"; | ||
| import { customConfirm } from "@/lib/zustand/useConfirmModalStore"; | ||
| import useReportedPostsStore from "@/lib/zustand/useReportedPostsStore"; | ||
|
|
||
| type BlockCommunityUserOptions = { | ||
| onBlocked?: () => void; | ||
| }; | ||
|
|
||
| type BlockCommunityUserParams = { | ||
| userId?: number; | ||
| postId?: number; | ||
| nickname?: string; | ||
| }; | ||
|
|
||
| const IconBlock = Ban as ComponentType<SVGProps<SVGSVGElement>>; | ||
|
|
||
| const useBlockCommunityUser = ({ onBlocked }: BlockCommunityUserOptions = {}) => { | ||
| const { mutateAsync: blockUser, isPending } = postBlockUser(); | ||
| const blockedUserIds = useReportedPostsStore((state) => state.blockedUserIds); | ||
| const addBlockedUser = useReportedPostsStore((state) => state.addBlockedUser); | ||
| const addBlockedPost = useReportedPostsStore((state) => state.addBlockedPost); | ||
|
|
||
| const handleBlockUser = async ({ userId, postId, nickname }: BlockCommunityUserParams) => { | ||
| if (!userId) { | ||
| return; | ||
| } | ||
|
|
||
| if (blockedUserIds.includes(userId)) { | ||
| showIconToast("logo", "이미 차단한 사용자입니다."); | ||
| onBlocked?.(); | ||
| return; | ||
| } | ||
|
|
||
| const userLabel = nickname ? `${nickname}님` : "이 사용자"; | ||
| const ok = await customConfirm({ | ||
| title: "사용자 차단", | ||
| content: `${userLabel}의 게시글과 댓글이 보이지 않도록 차단할까요?`, | ||
| approveMessage: "차단하기", | ||
| rejectMessage: "취소", | ||
| icon: IconBlock, | ||
| }); | ||
|
|
||
| if (!ok) { | ||
| return; | ||
| } | ||
|
|
||
| addBlockedUser(userId); | ||
| if (postId) { | ||
| addBlockedPost(postId); | ||
| } | ||
| onBlocked?.(); | ||
|
|
||
| try { | ||
| await blockUser({ | ||
| blockedId: userId, | ||
| data: {}, | ||
| }); | ||
| } catch { | ||
| // 서버 차단 동기화 실패와 관계없이 현재 화면에서는 차단 상태를 즉시 반영합니다. | ||
| } | ||
|
|
||
| showIconToast("logo", "사용자를 차단했습니다."); | ||
| }; | ||
|
|
||
| return { | ||
| handleBlockUser, | ||
| isBlocking: isPending, | ||
| }; | ||
| }; | ||
|
|
||
| export default useBlockCommunityUser; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
When the
/boards/{boardCode}list payload does not includepostFindSiteUserResponse(the repository’s current board-list shape inapps/web/src/apis/community/api.tsonly defines id/title/content/counts/category/thumbnail for this endpoint),authorIdisundefinedand every blocked author’s post passes this filter. In that scenario, after blocking someone from a post detail the app routes back to the list but still renders that author’s posts, so the new local block feature only works on detail/comment data that has author IDs.Useful? React with 👍 / 👎.
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.
반영했습니다. 목록 응답에 작성자 ID가 없을 때도 차단을 누른 현재 게시글은 다시 노출되지 않도록
blockedPostIds를 저장하고, 목록/상세 가드에서 함께 필터링하도록 보완했습니다.