Skip to content

Commit 422fbf6

Browse files
authored
fix: fixed author liking its own post (#720)
1 parent e862ee6 commit 422fbf6

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

Diff for: src/discussions/common/HoverCard.jsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import classNames from 'classnames';
1212
import { useIntl } from '@edx/frontend-platform/i18n';
1313

1414
import { ThreadType } from '../../data/constants';
15-
import { useUserPostingEnabled } from '../data/hooks';
15+
import { useHasLikePermission, useUserPostingEnabled } from '../data/hooks';
1616
import PostCommentsContext from '../post-comments/postCommentsContext';
1717
import ActionsDropdown from './ActionsDropdown';
1818
import DiscussionContext from './context';
@@ -33,6 +33,7 @@ const HoverCard = ({
3333
const { enableInContextSidebar } = useContext(DiscussionContext);
3434
const { isClosed } = useContext(PostCommentsContext);
3535
const isUserPrivilegedInPostingRestriction = useUserPostingEnabled();
36+
const userHasLikePermission = useHasLikePermission(contentType, id);
3637

3738
return (
3839
<div
@@ -86,6 +87,7 @@ const HoverCard = ({
8687
iconAs={Icon}
8788
size="sm"
8889
alt="Like"
90+
disabled={!userHasLikePermission}
8991
iconClassNames="like-icon-dimensions"
9092
onClick={(e) => {
9193
e.preventDefault();

Diff for: src/discussions/data/hooks.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,20 @@ import { AppContext } from '@edx/frontend-platform/react';
1616
import selectCourseTabs from '../../components/NavigationBar/data/selectors';
1717
import { LOADED } from '../../components/NavigationBar/data/slice';
1818
import fetchTab from '../../components/NavigationBar/data/thunks';
19-
import { RequestStatus, Routes } from '../../data/constants';
19+
import { ContentActions, RequestStatus, Routes } from '../../data/constants';
2020
import { selectTopicsUnderCategory } from '../../data/selectors';
2121
import fetchCourseBlocks from '../../data/thunks';
2222
import DiscussionContext from '../common/context';
23+
import PostCommentsContext from '../post-comments/postCommentsContext';
2324
import { clearRedirect } from '../posts/data';
2425
import { threadsLoadingStatus } from '../posts/data/selectors';
2526
import { selectTopics } from '../topics/data/selectors';
2627
import tourCheckpoints from '../tours/constants';
2728
import selectTours from '../tours/data/selectors';
2829
import { updateTourShowStatus } from '../tours/data/thunks';
2930
import messages from '../tours/messages';
30-
import { discussionsPath } from '../utils';
31+
import { checkPermissions, discussionsPath } from '../utils';
32+
import { ContentSelectors } from './constants';
3133
import {
3234
selectAreThreadsFiltered,
3335
selectEnableInContext,
@@ -284,3 +286,10 @@ export const useDebounce = (value, delay) => {
284286
);
285287
return debouncedValue;
286288
};
289+
290+
export const useHasLikePermission = (contentType, id) => {
291+
const { postType } = useContext(PostCommentsContext);
292+
const content = { ...useSelector(ContentSelectors[contentType](id)), postType };
293+
294+
return checkPermissions(content, ContentActions.VOTE);
295+
};

Diff for: src/discussions/post-comments/comments/comment/Comment.jsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ const Comment = ({
104104
hideReportConfirmation();
105105
}, [abuseFlagged, id, hideReportConfirmation]);
106106

107+
const handleCommentLike = useCallback(async () => {
108+
await dispatch(editComment(id, { voted: !voted }));
109+
}, [id, voted]);
110+
107111
const actionHandlers = useMemo(() => ({
108112
[ContentActions.EDIT_CONTENT]: handleEditContent,
109113
[ContentActions.ENDORSE]: handleCommentEndorse,
@@ -124,10 +128,6 @@ const Comment = ({
124128
}
125129
}, [isUserPrivilegedInPostingRestriction]);
126130

127-
const handleCommentLike = useCallback(async () => {
128-
await dispatch(editComment(id, { voted: !voted }));
129-
}, [id, voted]);
130-
131131
const handleCloseEditor = useCallback(() => {
132132
setEditing(false);
133133
}, []);

Diff for: src/discussions/posts/post/Post.jsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ const Post = ({ handleAddResponseButton }) => {
8585
updateExistingThread(postId, { pinned: !pinned }),
8686
), [postId, pinned]);
8787

88+
const handlePostLike = useCallback(() => {
89+
dispatch(updateExistingThread(postId, { voted: !voted }));
90+
}, [postId, voted]);
91+
8892
const handlePostReport = useCallback(() => {
8993
if (abuseFlagged) {
9094
dispatch(updateExistingThread(postId, { flagged: !abuseFlagged }));
@@ -109,10 +113,6 @@ const Post = ({ handleAddResponseButton }) => {
109113
hideClosePostModal();
110114
}, [postId, hideClosePostModal]);
111115

112-
const handlePostLike = useCallback(() => {
113-
dispatch(updateExistingThread(postId, { voted: !voted }));
114-
}, [postId, voted]);
115-
116116
const handlePostFollow = useCallback(() => {
117117
dispatch(updateExistingThread(postId, { following: !following }));
118118
}, [postId, following]);

0 commit comments

Comments
 (0)