Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment depth #1072

Merged
merged 8 commits into from
Jun 15, 2023
5 changes: 5 additions & 0 deletions src/assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ blockquote {
overflow-y: auto;
}

.comments {
list-style: none;
padding: 0;
}

.thumbnail {
object-fit: cover;
min-height: 60px;
Expand Down
47 changes: 18 additions & 29 deletions src/shared/components/comment/comment-node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,78 +159,65 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
}

render() {
let node = this.props.node;
let cv = this.props.node.comment_view;
const node = this.props.node;
const cv = this.props.node.comment_view;

let purgeTypeText =
const purgeTypeText =
this.state.purgeType == PurgeType.Comment
? i18n.t("purge_comment")
: `${i18n.t("purge")} ${cv.creator.name}`;

let canMod_ =
const canMod_ =
canMod(cv.creator.id, this.props.moderators, this.props.admins) &&
cv.community.local;
let canModOnSelf =
const canModOnSelf =
canMod(
cv.creator.id,
this.props.moderators,
this.props.admins,
UserService.Instance.myUserInfo,
true
) && cv.community.local;
let canAdmin_ =
const canAdmin_ =
canAdmin(cv.creator.id, this.props.admins) && cv.community.local;
let canAdminOnSelf =
const canAdminOnSelf =
canAdmin(
cv.creator.id,
this.props.admins,
UserService.Instance.myUserInfo,
true
) && cv.community.local;
let isMod_ = isMod(cv.creator.id, this.props.moderators);
let isAdmin_ =
const isMod_ = isMod(cv.creator.id, this.props.moderators);
const isAdmin_ =
isAdmin(cv.creator.id, this.props.admins) && cv.community.local;
let amCommunityCreator_ = amCommunityCreator(
const amCommunityCreator_ = amCommunityCreator(
cv.creator.id,
this.props.moderators
);

let borderColor = this.props.node.depth
? colorList[(this.props.node.depth - 1) % colorList.length]
: colorList[0];
let moreRepliesBorderColor = this.props.node.depth
const moreRepliesBorderColor = this.props.node.depth
? colorList[this.props.node.depth % colorList.length]
: colorList[0];

let showMoreChildren =
const showMoreChildren =
this.props.viewType == CommentViewType.Tree &&
!this.state.collapsed &&
node.children.length == 0 &&
node.comment_view.counts.child_count > 0;

return (
<div
className={`comment ${
this.props.node.depth && !this.props.noIndent ? "ml-1" : ""
}`}
>
<li className="comment" role="comment">
<div
id={`comment-${cv.comment.id}`}
className={classNames(`details comment-node py-2`, {
"border-top border-light": !this.props.noBorder,
mark:
this.isCommentNew ||
this.props.node.comment_view.comment.distinguished,
})}
style={
!this.props.noIndent && this.props.node.depth
? `border-left: 2px ${borderColor} solid !important`
: ""
}
>
<div
className={classNames({
"ml-2": !this.props.noIndent && this.props.node.depth,
"ml-2": !this.props.noIndent,
})}
>
<div className="d-flex flex-wrap align-items-center text-muted small">
Expand Down Expand Up @@ -1024,11 +1011,13 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
allLanguages={this.props.allLanguages}
siteLanguages={this.props.siteLanguages}
hideImages={this.props.hideImages}
isChild={!this.props.noIndent}
depth={this.props.node.depth + 1}
/>
)}
{/* A collapsed clearfix */}
{this.state.collapsed && <div className="row col-12"></div>}
</div>
{this.state.collapsed && <div className="row col-12" />}
</li>
);
}

Expand Down
24 changes: 19 additions & 5 deletions src/shared/components/comment/comment-nodes.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import classNames from "classnames";
import { Component } from "inferno";
import { CommunityModeratorView, Language, PersonView } from "lemmy-js-client";
import { CommentNodeI, CommentViewType } from "../../interfaces";
import { colorList } from "../../utils";
import { CommentNode } from "./comment-node";

interface CommentNodesProps {
Expand All @@ -20,6 +22,8 @@ interface CommentNodesProps {
allLanguages: Language[];
siteLanguages: number[];
hideImages?: boolean;
isChild?: boolean;
depth?: number;
}

export class CommentNodes extends Component<CommentNodesProps, any> {
Expand All @@ -28,10 +32,20 @@ export class CommentNodes extends Component<CommentNodesProps, any> {
}

render() {
let maxComments = this.props.maxCommentsShown ?? this.props.nodes.length;
const maxComments = this.props.maxCommentsShown ?? this.props.nodes.length;

return (
<div className="comments">
const borderColor = this.props.depth
? colorList[this.props.depth % colorList.length]
: colorList[0];

return this.props.nodes.length > 0 ? (
SleeplessOne1917 marked this conversation as resolved.
Show resolved Hide resolved
SleeplessOne1917 marked this conversation as resolved.
Show resolved Hide resolved
<ul
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be an ordered list, since it's sorted by some criterion?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could make it ordered. Whichever you think would be better for accessibility. However, I don't think children of top level comments get sorted, so that's worth keeping in mind.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @fastfinge said, ul makes more sense from a screen reader perspective. With an ol, you'd (depending on settings) get the item number and the number of items on the list: the comment number and the total number of comments at that depth, in that thread. That seems like a lot of extra info to process.

className={classNames("comments", {
"ms-1": !!this.props.isChild,
"border-top border-light": !this.props.noBorder,
})}
style={`border-left: 2px solid ${borderColor} !important;`}
>
{this.props.nodes.slice(0, maxComments).map(node => (
<CommentNode
key={node.comment_view.comment.id}
Expand All @@ -52,7 +66,7 @@ export class CommentNodes extends Component<CommentNodesProps, any> {
hideImages={this.props.hideImages}
/>
))}
</div>
);
</ul>
) : null;
}
}