Open platform to collect and prioritize feedback
refactor: move comment actions to a dropdown (#577)
Guilherme Oenning8fe7d83d84c8
diff --git a/public/assets/styles/main.scss b/public/assets/styles/main.scssindex a361ba4b6..2e12fe9fe 100644--- a/public/assets/styles/main.scss+++ b/public/assets/styles/main.scss@@ -249,6 +249,10 @@ body, h1, h2, h3, h4, h5, .ui, input {border-left: 4px solid $gray-light;margin: 5px 0;}+ ul, ol {+ margin: 0;+ padding-left: 30px;+ }img {max-width: 100%;}diff --git a/public/assets/styles/variables.scss b/public/assets/styles/variables.scssindex ded734baa..3852fe169 100644--- a/public/assets/styles/variables.scss+++ b/public/assets/styles/variables.scss@@ -19,7 +19,10 @@ $link-color: #07C;$focus-color: #85b7d9;// Buttons+$black-light: #232323;+$black: #000;$white: #fff;+$white-dark: #f9f9f9;$gray-lightest: rgba(0,0,0,.03);$gray-lighter: #eee;$gray-light: #d5d5d5;diff --git a/public/components/common/DropDown.scss b/public/components/common/DropDown.scssindex 811ca5887..5bad07e6e 100644--- a/public/components/common/DropDown.scss+++ b/public/components/common/DropDown.scss@@ -19,6 +19,12 @@}}+ &.m-left {+ .c-dropdown-menu {+ right: 0;+ }+ }+.c-dropdown-control {position: relative;overflow: hidden;diff --git a/public/components/common/DropDown.tsx b/public/components/common/DropDown.tsxindex 0e36ed9d2..528cc3e92 100644--- a/public/components/common/DropDown.tsx+++ b/public/components/common/DropDown.tsx@@ -18,6 +18,7 @@ export interface DropDownProps {searchable?: boolean;inline?: boolean;header?: string;+ direction?: "left" | "right";onChange?: (item: DropDownItem) => void;onSearchChange?: (e: React.FormEvent<HTMLInputElement>) => void;renderText?: (item?: DropDownItem) => JSX.Element | undefined;@@ -31,6 +32,10 @@ export interface DropDownState {export class DropDown extends React.Component<DropDownProps, DropDownState> {private mounted = false;+ public static defaultProps: Partial<DropDownProps> = {+ direction: "right"+ };+constructor(props: DropDownProps) {super(props);this.state = {@@ -160,7 +165,9 @@ export class DropDown extends React.Component<DropDownProps, DropDownState> {"c-dropdown": true,[`${this.props.className}`]: this.props.className,"is-open": this.state.isOpen,- "is-inline": this.props.inline+ "is-inline": this.props.inline,+ "m-right": this.props.direction === "right",+ "m-left": this.props.direction === "left"});return (diff --git a/public/components/common/UserName.scss b/public/components/common/UserName.scssindex 5703521e0..952dc5a20 100644--- a/public/components/common/UserName.scss+++ b/public/components/common/UserName.scss@@ -1,7 +1,7 @@@import '~@fider/assets/styles/variables.scss';.c-username {- color: #4f5e6b;+ color: $black-light;font-weight: 500;&.m-staff {diff --git a/public/pages/ShowPost/components/Comments.scss b/public/pages/ShowPost/components/Comments.scssindex dcf28326d..eb41a7ccd 100644--- a/public/pages/ShowPost/components/Comments.scss+++ b/public/pages/ShowPost/components/Comments.scss@@ -1,18 +1,19 @@@import '~@fider/assets/styles/variables.scss';.c-comment-list {- max-width: 650px;+ @include media(">=lg") {+ max-width: 650px;+ }.c-avatar {- margin-right: 5px;+ margin-right: 10px;vertical-align: top;margin-top: 2px;}.c-comment {position: relative;- margin: 0 0 15px 0;- border: none;+ margin: 0 0 20px 0;border-top: none;line-height: 1.2;@@ -20,15 +21,41 @@display: inline-block;width: 85%;- .c-comment-text {- margin-top: 2px;- }-.c-comment-metadata {display: inline-block;- margin-left: .5em;font-size: 80%;color: $gray-darker;+ margin-left: 3px;+ }++ .l-more-actions {+ cursor: pointer;+ display: inline-block;+ margin-left: 10px;+ position: relative;+ top: 2px;++ .c-dropdown-menu {+ border-radius: 5px;+ width: 100px;+ }++ .ellipsis.icon {+ color: $gray-dark;+ }++ &:hover {+ .ellipsis.icon {+ color: $gray-darkest;+ }+ }++ &.is-open {+ display: inline-block !important;+ .ellipsis.icon {+ color: $gray-darkest;+ }+ }}}}diff --git a/public/pages/ShowPost/components/ShowComment.tsx b/public/pages/ShowPost/components/ShowComment.tsxindex e78206671..b56332b97 100644--- a/public/pages/ShowPost/components/ShowComment.tsx+++ b/public/pages/ShowPost/components/ShowComment.tsx@@ -1,6 +1,16 @@import * as React from "react";-import { Comment, CurrentUser, Post } from "@fider/models";-import { Gravatar, UserName, Moment, Form, TextArea, Button, MultiLineText } from "@fider/components";+import { Comment, Post } from "@fider/models";+import {+ Gravatar,+ UserName,+ Moment,+ Form,+ TextArea,+ Button,+ MultiLineText,+ DropDown,+ DropDownItem+} from "@fider/components";import { formatDate, Failure, actions, Fider } from "@fider/services";interface ShowCommentProps {@@ -32,10 +42,6 @@ export class ShowComment extends React.Component<ShowCommentProps, ShowCommentStreturn false;}- private startEdit = () => {- this.setState({ isEditing: true, newContent: this.state.comment.content, error: undefined });- };-private cancelEdit = async () => {this.setState({isEditing: false,@@ -63,14 +69,25 @@ export class ShowComment extends React.Component<ShowCommentProps, ShowCommentStthis.setState({ newContent });};+ private renderEllipsis = () => {+ return <i className="ellipsis horizontal icon" />;+ };++ private onActionSelected = (item: DropDownItem) => {+ if (item.value === "edit") {+ this.setState({ isEditing: true, newContent: this.state.comment.content, error: undefined });+ }+ };+public render() {const c = this.state.comment;const editedMetadata = !!c.editedAt &&!!c.editedBy && (<div className="c-comment-metadata">- ·{" "}- <span title={`This comment has been edited by ${c.editedBy!.name} on ${formatDate(c.editedAt)}`}>edited</span>+ <span title={`This comment has been edited by ${c.editedBy!.name} on ${formatDate(c.editedAt)}`}>+ · edited+ </span></div>);@@ -85,12 +102,13 @@ export class ShowComment extends React.Component<ShowCommentProps, ShowCommentSt{editedMetadata}{!this.state.isEditing &&this.canEditComment(c) && (- <div className="c-comment-metadata">- ·{" "}- <span className="clickable" onClick={this.startEdit}>- edit- </span>- </div>+ <DropDown+ className="l-more-actions"+ direction="left"+ items={[{ label: "Edit", value: "edit" }]}+ onChange={this.onActionSelected}+ renderText={this.renderEllipsis}+ />)}<div className="c-comment-text">{this.state.isEditing ? (