pictshareAvatarThumbnail,
showAvatars,
setupTippy,
- randomHsl,
+ colorList,
} from '../utils';
import moment from 'moment';
import { MomentTime } from './moment-time';
score: this.props.node.comment.score,
upvotes: this.props.node.comment.upvotes,
downvotes: this.props.node.comment.downvotes,
- borderColor: randomHsl(),
+ borderColor: this.props.node.comment.depth
+ ? colorList[this.props.node.comment.depth % colorList.length]
+ : colorList[0],
};
constructor(props: any, context: any) {
}
let tree: Array<CommentNodeI> = [];
for (let comment of this.state.comments) {
+ let child = map.get(comment.id);
if (comment.parent_id) {
- map.get(comment.parent_id).children.push(map.get(comment.id));
+ let parent_ = map.get(comment.parent_id);
+ parent_.children.push(child);
} else {
- tree.push(map.get(comment.id));
+ tree.push(child);
}
+
+ this.setDepth(child);
}
return tree;
}
+ setDepth(node: CommentNodeI, i: number = 0): void {
+ for (let child of node.children) {
+ child.comment.depth = i;
+ this.setDepth(child, i + 1);
+ }
+ }
+
commentsTree() {
let nodes = this.buildCommentsTree();
return (
saved?: boolean;
user_mention_id?: number; // For mention type
recipient_id?: number;
+ depth?: number;
}
export interface Category {
}
}
+export const colorList: Array<string> = [...Array(10)].map(() => randomHsl());
+
export function randomHsl() {
return `hsla(${Math.random() * 360}, 100%, 50%, 1)`;
}