* chore: configure WDYR for react profiling * perf: reduced post content re-rendering * perf: post content view and it child optimization * perf: add memoization in post editor * perf: add memoization in postCommnetsView * perf: improved endorsed comment view rendering * perf: improved re-rendering in reply component * fix: uncomment questionType commentsView * fix: removed console errors in postContent area * perf: reduced postType and postId dependancy * perf: improved re-rendering in discussionHome * perf: improved re-rendering of postsList and its child components * perf: improved re-rendering of legacyTopic and learner sidebar * fix: postFilterBar filter was not updating * fix: resolve duplicate comment posts issue * fix: memory leaking issue in comments view * fix: duplicate topic posts in inContext sidebar * perf: add lazy loading * chore: remove WDYR configuration * fix: alert banner padding * chore: update package-lock file * fix: bind tour API call with buttons
102 lines
2.9 KiB
JavaScript
102 lines
2.9 KiB
JavaScript
import React, { useCallback, useEffect, useState } from 'react';
|
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
|
|
import { useIntl } from '@edx/frontend-platform/i18n';
|
|
import {
|
|
Button, Dropdown, ModalPopup, useToggle,
|
|
} from '@edx/paragon';
|
|
import { ExpandLess, ExpandMore } from '@edx/paragon/icons';
|
|
|
|
import { updateUserDiscussionsTourByName } from '../../tours/data';
|
|
import { selectCommentSortOrder } from '../data/selectors';
|
|
import { setCommentSortOrder } from '../data/slices';
|
|
import messages from '../messages';
|
|
|
|
const CommentSortDropdown = () => {
|
|
const intl = useIntl();
|
|
const dispatch = useDispatch();
|
|
const sortedOrder = useSelector(selectCommentSortOrder);
|
|
const [isOpen, open, close] = useToggle(false);
|
|
const [target, setTarget] = useState(null);
|
|
|
|
const handleActions = useCallback((reverseOrder) => {
|
|
close();
|
|
dispatch(setCommentSortOrder(reverseOrder));
|
|
}, []);
|
|
|
|
const enableCommentsSortTour = useCallback((enabled) => {
|
|
const data = {
|
|
enabled,
|
|
tourName: 'response_sort',
|
|
};
|
|
dispatch(updateUserDiscussionsTourByName(data));
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
enableCommentsSortTour(true);
|
|
return () => {
|
|
enableCommentsSortTour(false);
|
|
};
|
|
}, []);
|
|
|
|
return (
|
|
<>
|
|
<div className="comments-sort d-flex justify-content-end mx-4 mt-2">
|
|
<Button
|
|
id="comment-sort"
|
|
alt={intl.formatMessage(messages.actionsAlt)}
|
|
ref={setTarget}
|
|
variant="tertiary"
|
|
onClick={open}
|
|
size="sm"
|
|
iconAfter={isOpen ? ExpandLess : ExpandMore}
|
|
>
|
|
{intl.formatMessage(messages.commentSort, {
|
|
sort: sortedOrder,
|
|
})}
|
|
</Button>
|
|
</div>
|
|
<div className="actions-dropdown">
|
|
<ModalPopup
|
|
onClose={close}
|
|
positionRef={target}
|
|
isOpen={isOpen}
|
|
>
|
|
<div
|
|
className="bg-white p-1 shadow d-flex flex-column"
|
|
data-testid="comment-sort-dropdown-modal-popup"
|
|
>
|
|
<Dropdown.Item
|
|
className="d-flex justify-content-start py-1.5 mb-1"
|
|
as={Button}
|
|
variant="tertiary"
|
|
size="inline"
|
|
onClick={() => handleActions(false)}
|
|
autoFocus={sortedOrder === false}
|
|
>
|
|
{intl.formatMessage(messages.commentSort, {
|
|
sort: false,
|
|
})}
|
|
</Dropdown.Item>
|
|
<Dropdown.Item
|
|
className="d-flex justify-content-start py-1.5"
|
|
as={Button}
|
|
variant="tertiary"
|
|
size="inline"
|
|
onClick={() => handleActions(true)}
|
|
autoFocus={sortedOrder === true}
|
|
>
|
|
{intl.formatMessage(messages.commentSort, {
|
|
sort: true,
|
|
})}
|
|
</Dropdown.Item>
|
|
</div>
|
|
</ModalPopup>
|
|
</div>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default CommentSortDropdown;
|