From c4365d09fe884a64e94f8bf4c20ded2c2785f8f2 Mon Sep 17 00:00:00 2001 From: igoradamenko Date: Fri, 2 Feb 2018 23:47:28 +0200 Subject: [PATCH] add input for replying to comment component --- .../comment/__body/comment__body.scss | 3 ++ .../comment/__controls/comment__controls.scss | 12 +++++ .../comment/__input/comment__input.scss | 4 ++ .../comment/__reply/comment__reply.scss | 3 ++ web/app/components/comment/comment.jsx | 49 ++++++++++++++----- web/app/components/comment/comment.scss | 12 ++++- web/app/components/comment/index.js | 4 ++ 7 files changed, 75 insertions(+), 12 deletions(-) create mode 100644 web/app/components/comment/__body/comment__body.scss create mode 100644 web/app/components/comment/__controls/comment__controls.scss create mode 100644 web/app/components/comment/__input/comment__input.scss create mode 100644 web/app/components/comment/__reply/comment__reply.scss diff --git a/web/app/components/comment/__body/comment__body.scss b/web/app/components/comment/__body/comment__body.scss new file mode 100644 index 00000000..d0d91822 --- /dev/null +++ b/web/app/components/comment/__body/comment__body.scss @@ -0,0 +1,3 @@ +.comment__body { + display: flex; +} diff --git a/web/app/components/comment/__controls/comment__controls.scss b/web/app/components/comment/__controls/comment__controls.scss new file mode 100644 index 00000000..ebd3eb42 --- /dev/null +++ b/web/app/components/comment/__controls/comment__controls.scss @@ -0,0 +1,12 @@ +.comment__controls { + display: inline-block; + margin-left: 8px; + color: #06c5c5; + + @media (hover: hover) { + margin-left: 0; + transition: transform .2s .1s ease-out, opacity .2s .1s ease-out; + font-weight: 700; + opacity: 0; + } +} diff --git a/web/app/components/comment/__input/comment__input.scss b/web/app/components/comment/__input/comment__input.scss new file mode 100644 index 00000000..060b336e --- /dev/null +++ b/web/app/components/comment/__input/comment__input.scss @@ -0,0 +1,4 @@ +.comment__input { + padding-left: 56px; + margin-top: 8px; +} diff --git a/web/app/components/comment/__reply/comment__reply.scss b/web/app/components/comment/__reply/comment__reply.scss new file mode 100644 index 00000000..31696d41 --- /dev/null +++ b/web/app/components/comment/__reply/comment__reply.scss @@ -0,0 +1,3 @@ +.comment__reply { + cursor: pointer; +} diff --git a/web/app/components/comment/comment.jsx b/web/app/components/comment/comment.jsx index a5891ec6..847e868b 100644 --- a/web/app/components/comment/comment.jsx +++ b/web/app/components/comment/comment.jsx @@ -4,6 +4,8 @@ import { vote } from 'common/api'; import { url } from 'common/settings'; import store from 'common/store'; +import Input from 'components/input'; + export default class Comment extends Component { constructor(props) { super(props); @@ -15,10 +17,19 @@ export default class Comment extends Component { score: score, scoreIncreased: userId in votes && votes[userId], scoreDecreased: userId in votes && !votes[userId], + isInputVisible: false, }; this.decreaseScore = this.decreaseScore.bind(this); this.increaseScore = this.increaseScore.bind(this); + this.onReplyClick = this.onReplyClick.bind(this); + this.onReply = this.onReply.bind(this); + } + + onReplyClick() { + const { isInputVisible } = this.state; + + this.setState({ isInputVisible: !isInputVisible }); } increaseScore() { @@ -49,9 +60,13 @@ export default class Comment extends Component { vote({ id: this.props.data.id, url, value: -1 }); } - render(props, { score, scoreIncreased, scoreDecreased }) { + onReply(...rest) { + this.props.onReply(...rest); + this.setState({ isInputVisible: false }); + } + + render(props, { score, scoreIncreased, scoreDecreased, isInputVisible }) { const { data, mix, mods = {} } = props; - console.log('rerender', data.id) const time = new Date(data.time); // TODO: which format for datetime should we choose? @@ -70,14 +85,15 @@ export default class Comment extends Component { return ( // TODO: add default view mod or don't? -
- +
+
+ -
-
- {o.user.name} +
+
+ {o.user.name} - + vote down - {o.time} -
+ {o.time} -
+ + reply + +
+ +
+
+ + { + isInputVisible && ( + + ) + }
); } diff --git a/web/app/components/comment/comment.scss b/web/app/components/comment/comment.scss index 5077aa31..351c9ca6 100644 --- a/web/app/components/comment/comment.scss +++ b/web/app/components/comment/comment.scss @@ -1,10 +1,20 @@ @import 'common/variables'; .comment { - display: flex; position: relative; overflow: hidden; margin-bottom: $offset; font-size: 16px; line-height: 1.2; + + &:hover { + .comment__controls { + font-weight: 700; + + @media (hover: hover) { + transform: translateX(8px); + opacity: 1; + } + } + } } diff --git a/web/app/components/comment/index.js b/web/app/components/comment/index.js index ed1a8f65..a3edfb37 100644 --- a/web/app/components/comment/index.js +++ b/web/app/components/comment/index.js @@ -3,7 +3,11 @@ export { default } from './comment'; require('./comment.scss'); require('./__avatar/comment__avatar.scss'); +require('./__body/comment__body.scss'); +require('./__controls/comment__controls.scss'); require('./__info/comment__info.scss'); +require('./__input/comment__input.scss'); +require('./__reply/comment__reply.scss'); require('./__score/comment__score.scss'); require('./__score-sign/comment__score-sign.scss'); require('./__score-value/comment__score-value.scss');