Skip to content

Commit

Permalink
Merge branch 'master' into bilalqamar95/jest-v29-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
BilalQamar95 authored Jul 4, 2024
2 parents cd8de35 + 422fbf6 commit 506018e
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 31 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ jobs:
- name: i18n_extract
run: npm run i18n_extract
- name: Coverage
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
6 changes: 4 additions & 2 deletions src/discussions/common/HoverCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -33,6 +33,7 @@ const HoverCard = ({
const { enableInContextSidebar } = useContext(DiscussionContext);
const { isClosed } = useContext(PostCommentsContext);
const isUserPrivilegedInPostingRestriction = useUserPostingEnabled();
const userHasLikePermission = useHasLikePermission(contentType, id);

return (
<div
Expand All @@ -45,7 +46,7 @@ const HoverCard = ({
<Button
variant="tertiary"
className={classNames(
'px-2.5 py-2 border-0 font-style text-gray-700 font-size-12',
'px-2.5 py-2 border-0 font-style text-gray-700',
{ 'w-100': enableInContextSidebar },
)}
onClick={() => handleResponseCommentButton()}
Expand Down Expand Up @@ -86,6 +87,7 @@ const HoverCard = ({
iconAs={Icon}
size="sm"
alt="Like"
disabled={!userHasLikePermission}
iconClassNames="like-icon-dimensions"
onClick={(e) => {
e.preventDefault();
Expand Down
4 changes: 3 additions & 1 deletion src/discussions/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ ensureConfig([
], 'Posts API service');

export const getCourseConfigApiUrl = () => `${getConfig().LMS_BASE_URL}/api/discussion/v2/courses/`;
export const getCourseSettingsApiUrl = () => `${getConfig().LMS_BASE_URL}/api/discussion/v1/courses/`;
export const getDiscussionsConfigUrl = (courseId) => `${getCourseConfigApiUrl()}${courseId}/`;
export const getDiscussionsSettingsUrl = (courseId) => `${getCourseSettingsApiUrl()}${courseId}/settings`;
/**
* Get discussions course config
* @param {string} courseId
Expand All @@ -21,7 +23,7 @@ export async function getDiscussionsConfig(courseId) {
* @param {string} courseId
*/
export async function getDiscussionsSettings(courseId) {
const url = `${getDiscussionsConfigUrl(courseId)}settings`;
const url = `${getDiscussionsSettingsUrl(courseId)}`;
const { data } = await getAuthenticatedHttpClient().get(url);
return data;
}
13 changes: 11 additions & 2 deletions src/discussions/data/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@ 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';
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,
Expand Down Expand Up @@ -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);
};
5 changes: 3 additions & 2 deletions src/discussions/post-comments/PostCommentsView.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import executeThunk from '../../test-utils';
import { getCohortsApiUrl } from '../cohorts/data/api';
import fetchCourseCohorts from '../cohorts/data/thunks';
import DiscussionContext from '../common/context';
import { getCourseConfigApiUrl } from '../data/api';
import { getCourseConfigApiUrl, getCourseSettingsApiUrl } from '../data/api';
import fetchCourseConfig from '../data/thunks';
import DiscussionContent from '../discussions-home/DiscussionContent';
import { getThreadsApiUrl } from '../posts/data/api';
Expand All @@ -37,6 +37,7 @@ import '../topics/data/__factories__';
import '../cohorts/data/__factories__';

const courseConfigApiUrl = getCourseConfigApiUrl();
const courseSettingsApiUrl = getCourseSettingsApiUrl();
const commentsApiUrl = getCommentsApiUrl();
const threadsApiUrl = getThreadsApiUrl();
const discussionPostId = 'thread-1';
Expand Down Expand Up @@ -105,7 +106,7 @@ async function setupCourseConfig() {
{ code: 'reason-2', label: 'reason 2' },
],
});
axiosMock.onGet(`${courseConfigApiUrl}${courseId}/settings`).reply(200, {});
axiosMock.onGet(`${courseSettingsApiUrl}${courseId}/settings`).reply(200, {});
await executeThunk(fetchCourseConfig(courseId), store.dispatch, store.getState);
}

Expand Down
8 changes: 4 additions & 4 deletions src/discussions/post-comments/comments/comment/Comment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -124,10 +128,6 @@ const Comment = ({
}
}, [isUserPrivilegedInPostingRestriction]);

const handleCommentLike = useCallback(async () => {
await dispatch(editComment(id, { voted: !voted }));
}, [id, voted]);

const handleCloseEditor = useCallback(() => {
setEditing(false);
}, []);
Expand Down
13 changes: 5 additions & 8 deletions src/discussions/posts/post/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
Expand All @@ -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]);
Expand Down Expand Up @@ -188,10 +188,7 @@ const Post = ({ handleAddResponseButton }) => {
</div>
{(topicContext || topic) && (
<div
className={classNames(
'mt-14px font-style font-size-12',
{ 'w-100': enableInContextSidebar, 'mb-1': !displayPostFooter },
)}
className={classNames('mt-14px font-style', { 'w-100': enableInContextSidebar, 'mb-1': !displayPostFooter })}
style={{ lineHeight: '20px' }}
>
<span className="text-gray-500" style={{ lineHeight: '20px' }}>
Expand Down
2 changes: 1 addition & 1 deletion src/discussions/posts/post/PostSummaryFooter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const PostSummaryFooter = ({
</OverlayTrigger>

{preview && commentCount > 1 && (
<div className="d-flex align-items-center ml-4.5 text-gray-700 font-style font-size-12">
<div className="d-flex align-items-center ml-4.5 text-gray-700 font-style">
<OverlayTrigger
overlay={(
<Tooltip id={`follow-${postId}-tooltip`}>
Expand Down
15 changes: 5 additions & 10 deletions src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ body,
outline: $light-400 solid 2px;
}


.font-size-12 {
font-size: 12px !important;
}

.font-size-8 {
font-size: 8px !important;
}
Expand Down Expand Up @@ -630,7 +625,7 @@ th, td {
}

.post-form h4,
.btn-md {
.discussion-posts .btn-md {
font-size: 12px !important;
}
}
Expand All @@ -656,28 +651,28 @@ th, td {
}

.post-form h4,
.btn-md {
.discussion-posts .btn-md {
font-size: 14px !important;
}
}

@media only screen and (min-device-width: 769px) {
@media only screen and (min-width: 769px) {

body,
#main {
font-size: 14px;
}
}

@media only screen and (max-device-width: 768px) {
@media only screen and (max-width: 768px) {

body,
#main {
font-size: 12px;
}
}

@media only screen and (max-device-width: 366px) {
@media only screen and (max-width: 366px) {

body,
#main {
Expand Down

0 comments on commit 506018e

Please sign in to comment.