fix: fixed author liking its own post (#720)
This commit is contained in:
@@ -12,7 +12,7 @@ import classNames from 'classnames';
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
|
||||
import { ThreadType } from '../../data/constants';
|
||||
import { useUserPostingEnabled } from '../data/hooks';
|
||||
import { useHasLikePermission, useUserPostingEnabled } from '../data/hooks';
|
||||
import PostCommentsContext from '../post-comments/postCommentsContext';
|
||||
import ActionsDropdown from './ActionsDropdown';
|
||||
import DiscussionContext from './context';
|
||||
@@ -33,6 +33,7 @@ const HoverCard = ({
|
||||
const { enableInContextSidebar } = useContext(DiscussionContext);
|
||||
const { isClosed } = useContext(PostCommentsContext);
|
||||
const isUserPrivilegedInPostingRestriction = useUserPostingEnabled();
|
||||
const userHasLikePermission = useHasLikePermission(contentType, id);
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -86,6 +87,7 @@ const HoverCard = ({
|
||||
iconAs={Icon}
|
||||
size="sm"
|
||||
alt="Like"
|
||||
disabled={!userHasLikePermission}
|
||||
iconClassNames="like-icon-dimensions"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
|
||||
@@ -16,10 +16,11 @@ import { AppContext } from '@edx/frontend-platform/react';
|
||||
import selectCourseTabs from '../../components/NavigationBar/data/selectors';
|
||||
import { LOADED } from '../../components/NavigationBar/data/slice';
|
||||
import fetchTab from '../../components/NavigationBar/data/thunks';
|
||||
import { RequestStatus, Routes } from '../../data/constants';
|
||||
import { ContentActions, RequestStatus, Routes } from '../../data/constants';
|
||||
import { selectTopicsUnderCategory } from '../../data/selectors';
|
||||
import fetchCourseBlocks from '../../data/thunks';
|
||||
import DiscussionContext from '../common/context';
|
||||
import PostCommentsContext from '../post-comments/postCommentsContext';
|
||||
import { clearRedirect } from '../posts/data';
|
||||
import { threadsLoadingStatus } from '../posts/data/selectors';
|
||||
import { selectTopics } from '../topics/data/selectors';
|
||||
@@ -27,7 +28,8 @@ import tourCheckpoints from '../tours/constants';
|
||||
import selectTours from '../tours/data/selectors';
|
||||
import { updateTourShowStatus } from '../tours/data/thunks';
|
||||
import messages from '../tours/messages';
|
||||
import { discussionsPath } from '../utils';
|
||||
import { checkPermissions, discussionsPath } from '../utils';
|
||||
import { ContentSelectors } from './constants';
|
||||
import {
|
||||
selectAreThreadsFiltered,
|
||||
selectEnableInContext,
|
||||
@@ -284,3 +286,10 @@ export const useDebounce = (value, delay) => {
|
||||
);
|
||||
return debouncedValue;
|
||||
};
|
||||
|
||||
export const useHasLikePermission = (contentType, id) => {
|
||||
const { postType } = useContext(PostCommentsContext);
|
||||
const content = { ...useSelector(ContentSelectors[contentType](id)), postType };
|
||||
|
||||
return checkPermissions(content, ContentActions.VOTE);
|
||||
};
|
||||
|
||||
@@ -104,6 +104,10 @@ const Comment = ({
|
||||
hideReportConfirmation();
|
||||
}, [abuseFlagged, id, hideReportConfirmation]);
|
||||
|
||||
const handleCommentLike = useCallback(async () => {
|
||||
await dispatch(editComment(id, { voted: !voted }));
|
||||
}, [id, voted]);
|
||||
|
||||
const actionHandlers = useMemo(() => ({
|
||||
[ContentActions.EDIT_CONTENT]: handleEditContent,
|
||||
[ContentActions.ENDORSE]: handleCommentEndorse,
|
||||
@@ -124,10 +128,6 @@ const Comment = ({
|
||||
}
|
||||
}, [isUserPrivilegedInPostingRestriction]);
|
||||
|
||||
const handleCommentLike = useCallback(async () => {
|
||||
await dispatch(editComment(id, { voted: !voted }));
|
||||
}, [id, voted]);
|
||||
|
||||
const handleCloseEditor = useCallback(() => {
|
||||
setEditing(false);
|
||||
}, []);
|
||||
|
||||
@@ -85,6 +85,10 @@ const Post = ({ handleAddResponseButton }) => {
|
||||
updateExistingThread(postId, { pinned: !pinned }),
|
||||
), [postId, pinned]);
|
||||
|
||||
const handlePostLike = useCallback(() => {
|
||||
dispatch(updateExistingThread(postId, { voted: !voted }));
|
||||
}, [postId, voted]);
|
||||
|
||||
const handlePostReport = useCallback(() => {
|
||||
if (abuseFlagged) {
|
||||
dispatch(updateExistingThread(postId, { flagged: !abuseFlagged }));
|
||||
@@ -109,10 +113,6 @@ const Post = ({ handleAddResponseButton }) => {
|
||||
hideClosePostModal();
|
||||
}, [postId, hideClosePostModal]);
|
||||
|
||||
const handlePostLike = useCallback(() => {
|
||||
dispatch(updateExistingThread(postId, { voted: !voted }));
|
||||
}, [postId, voted]);
|
||||
|
||||
const handlePostFollow = useCallback(() => {
|
||||
dispatch(updateExistingThread(postId, { following: !following }));
|
||||
}, [postId, following]);
|
||||
|
||||
Reference in New Issue
Block a user