Skip to content

Commit

Permalink
[B][E] Improve comment thread behavior
Browse files Browse the repository at this point in the history
* Ensure comment pages after first are fetched correctly
* Add hide comments toggle
* Refresh comments and open thread on create
  • Loading branch information
1aurend committed Jan 23, 2025
1 parent 1c07da8 commit f95e204
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"hide": "Hide",
"hide_all": "Hide all",
"hide_description": "$t(actions.hide) Description",
"hide_comments": "$t(actions.hide) Comments",
"import": "Import",
"join": "Join",
"join_group": "$t(actions.join) this group",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ function GroupAnnotationsEntityCollection({
filterProps,
isFiltered,
paginationProps,
refresh,
refreshGroup,
refreshAnnotations,
...passThroughProps
}) {
const { t } = useTranslation();
Expand Down Expand Up @@ -43,6 +44,7 @@ function GroupAnnotationsEntityCollection({
{hasAnnotations && (
<Annotation.List.Default
annotations={annotations}
refresh={refreshAnnotations}
showCommentsToggleAsBlock
/>
)}
Expand All @@ -54,7 +56,7 @@ function GroupAnnotationsEntityCollection({
{!hasAnnotations && !isFiltered && (
<EntityCollectionPlaceholder.GroupAnnotations
readingGroup={readingGroup}
refresh={refresh}
refresh={refreshGroup}
style={{ paddingBlockStart: "40px" }}
/>
)}
Expand Down
5 changes: 3 additions & 2 deletions client/src/frontend/containers/ReadingGroup/Annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function ReadingGroupAnnotationsContainer({

const { id } = useParams();

const { data: annotations, meta } = useFetch({
const { data: annotations, meta, refresh: refreshAnnotations } = useFetch({
request: [readingGroupsAPI.annotations, id, filters, pagination],
dependencies: [fetchVersion]
});
Expand All @@ -38,7 +38,8 @@ function ReadingGroupAnnotationsContainer({
annotationsMeta={meta}
filterProps={{ ...filterProps, hideSearch: true }}
isFiltered={!!Object.keys(filters).length}
refresh={refresh}
refreshGroup={refresh}
refreshAnnotations={refreshAnnotations}
nested
/>
</Styled.Body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Annotation extends PureComponent {
visitHandler: PropTypes.func.isRequired,
displayFormat: PropTypes.string,
deleteHandler: PropTypes.func,
showCommentsToggleAsBlock: PropTypes.bool
showCommentsToggleAsBlock: PropTypes.bool,
refresh: PropTypes.func
};

get annotationListClassNames() {
Expand Down Expand Up @@ -46,6 +47,7 @@ class Annotation extends PureComponent {
includeComments={false}
includeMarkers={false}
showCommentsToggleAsBlock={this.showCommentsToggleAsBlock}
refresh={this.props.refresh}
/>
</ul>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,42 @@ import PropTypes from "prop-types";
import { useTranslation } from "react-i18next";
import IconComposer from "global/components/utility/IconComposer";

export default function BlockCommentsToggle({ loadComments, commentsCount }) {
export default function BlockCommentsToggle({
toggleComments,
commentsCount,
expanded
}) {
const { t } = useTranslation();

return (
<button className="annotation-footer-button" onClick={loadComments}>
<button className="annotation-footer-button" onClick={toggleComments}>
<span className="annotation-footer-button__inner">
<span className="annotation-footer-button__icon-container">
<IconComposer icon="interactComment32" size="default" />
</span>
<span className="annotation-footer-button__text">
{t("counts.comment", { count: commentsCount })}
</span>
<IconComposer
icon="arrowLongRight16"
size={24}
className="annotation-footer-button__arrow-icon"
/>
{expanded ? (
<>
<IconComposer
icon="arrowLongLeft16"
size={24}
className="annotation-footer-button__arrow-icon"
/>
<span className="annotation-footer-button__text annotation-footer-button__text--hide">
{t("actions.hide_comments")}
</span>
</>
) : (
<>
<span className="annotation-footer-button__icon-container">
<IconComposer icon="interactComment32" size="default" />
</span>
<span className="annotation-footer-button__text">
{t("counts.comment", { count: commentsCount })}
</span>
<IconComposer
icon="arrowLongRight16"
size={24}
className="annotation-footer-button__arrow-icon"
/>
</>
)}
</span>
</button>
);
Expand All @@ -29,6 +48,7 @@ BlockCommentsToggle.displayName =
"Annotation.Annotation.UserContent.BlockCommentsToggle";

BlockCommentsToggle.propTypes = {
loadComments: PropTypes.func.isRequired,
commentsCount: PropTypes.number.isRequired
toggleComments: PropTypes.func.isRequired,
commentsCount: PropTypes.number.isRequired,
expanded: PropTypes.bool.isRequired
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export default function AnnotationDetail({
includeMarkers,
annotation,
showCommentsToggleAsBlock,
showLogin
showLogin,
refresh
}) {
const dispatch = useDispatch();
const { t } = useTranslation();
Expand Down Expand Up @@ -74,16 +75,15 @@ export default function AnnotationDetail({
return res.promise;
};

const loadComments = () => {
setShowComments(true);
const toggleComments = () => {
setShowComments(!showComments);

if (threadRef?.current) threadRef.current.focus();
if (!showComments && threadRef?.current) threadRef.current.focus();
};

const showCommentsToggle = !!commentsCount && !showComments;

const showBlockCommentsToggle =
showCommentsToggleAsBlock && showCommentsToggle;
const showBlockCommentsToggle = showCommentsToggleAsBlock && !!commentsCount;
const showInlineCommentsToggle =
!showBlockCommentsToggle && showCommentsToggle;

Expand All @@ -98,6 +98,11 @@ export default function AnnotationDetail({
return established || trusted;
};

const onReplySuccess = () => {
if (refresh) refresh();
setShowComments(true);
};

return (
<>
<li className="annotation-comments">
Expand Down Expand Up @@ -165,7 +170,7 @@ export default function AnnotationDetail({
{showInlineCommentsToggle && (
<InlineToggle
active={action === "editing"}
loadComments={loadComments}
loadComments={toggleComments}
commentsCount={commentsCount}
/>
)}
Expand All @@ -174,6 +179,7 @@ export default function AnnotationDetail({
<CommentContainer.Editor
subject={annotation}
cancel={stopReply}
onSuccess={onReplySuccess}
initialOpen
/>
)}
Expand Down Expand Up @@ -206,8 +212,9 @@ export default function AnnotationDetail({
</li>
{showBlockCommentsToggle && (
<BlockToggle
loadComments={loadComments}
toggleComments={toggleComments}
commentsCount={commentsCount}
expanded={showComments}
/>
)}
</>
Expand Down
7 changes: 5 additions & 2 deletions client/src/global/components/Annotation/List/Default.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import Annotation from "../Annotation";
function AnnotationListDefault({
annotations,
handleVisitAnnotation,
showCommentsToggleAsBlock
showCommentsToggleAsBlock,
refresh
}) {
return (
<ul className="notes-list notes-list--pad-top">
Expand All @@ -17,6 +18,7 @@ function AnnotationListDefault({
annotation={annotation}
displayFormat="fullPage"
showCommentsToggleAsBlock={showCommentsToggleAsBlock}
refresh={refresh}
/>
</li>
);
Expand All @@ -29,7 +31,8 @@ AnnotationListDefault.displayName = "Annotation.List.Default";
AnnotationListDefault.propTypes = {
annotations: PropTypes.array,
handleVisitAnnotation: PropTypes.func,
showCommentsToggleAsBlock: PropTypes.bool
showCommentsToggleAsBlock: PropTypes.bool,
refresh: PropTypes.func
};

export default AnnotationListDefault;
5 changes: 4 additions & 1 deletion client/src/global/containers/comment/Editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ export class CommentEditor extends PureComponent {
createComment(props, state) {
const comment = this.commentFromPropsAndState(props, state);
const call = commentsAPI.create(props.subject, comment);
const options = { adds: `comments-for-${props.subject.id}` };
const options = {
adds: `comments-for-${props.subject.id}`
};
const createRequest = request(call, requests.rCommentCreate, options);
this.processRequest(createRequest);
}
Expand Down Expand Up @@ -138,6 +140,7 @@ export class CommentEditor extends PureComponent {

handleSuccess() {
this.setState(this.initialState(this.props));
if (this.props.onSuccess) this.props.onSuccess();
if (this.props.cancel) this.props.cancel();
}

Expand Down
4 changes: 2 additions & 2 deletions client/src/global/containers/comment/Thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { commentsAPI } from "api";
import Utility from "global/components/utility";

const { request } = entityStoreActions;
const perPage = 50;
const perPage = 10;

export class CommentThread extends PureComponent {
static mapStateToProps = (state, ownProps) => {
Expand Down Expand Up @@ -44,7 +44,7 @@ export class CommentThread extends PureComponent {

componentDidMount() {
if (this.props.subject && !this.props.comments) {
this.fetchComments({ number: 1, size: 1 });
this.fetchComments({ number: 1, size: perPage });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ export default `
&__text {
${drawerIndent("padding-left")}
transform: translateY(-1px);
&--hide {
padding-left: 1rem;
}
}
&__arrow-icon {
Expand Down

0 comments on commit f95e204

Please sign in to comment.