From 7ef2eec14b14b642a6ccc32204428a87aaeb592b Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 20 Dec 2016 23:26:46 -0300 Subject: [PATCH] Ivan - Add icon to drag and drop [skip ci] --- client/src/app-components/topic-viewer.js | 46 ++++++++++++--------- client/src/app-components/topic-viewer.scss | 22 +++++++++- client/src/core-components/icon.js | 2 +- 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/client/src/app-components/topic-viewer.js b/client/src/app-components/topic-viewer.js index 60efe0ad..2009da8c 100644 --- a/client/src/app-components/topic-viewer.js +++ b/client/src/app-components/topic-viewer.js @@ -1,4 +1,5 @@ import React from 'react'; +import ReactDOM from 'react-dom'; import _ from 'lodash'; import classNames from 'classnames'; import {Link} from 'react-router'; @@ -78,11 +79,33 @@ class TopicViewer extends React.Component { } renderArticleItem(article, index) { + let props = { + className: 'topic-viewer__list-item', + key: index, + draggable: true + }; + + if(this.props.editable) { + _.extend(props, { + onDragOver: (this.state.currentDraggedId) ? this.onItemDragOver.bind(this, article, index) : null, + onDrop: (this.state.currentDraggedId) ? this.onItemDrop.bind(this, article, index) : null, + onDragStart: () => { + this.setState({currentDraggedId: article.id}) + }, + onDragEnd: () => { + if(this.state.currentDraggedId) { + this.setState({articles: this.props.articles, currentDraggedId: 0}); + } + } + }); + } + return ( -
  • +
  • {article.title} +
  • ); } @@ -126,31 +149,16 @@ class TopicViewer extends React.Component { ); } - getArticleLinkProps(article, index) { + getArticleLinkProps(article) { let classes = { 'topic-viewer__list-item-button': true, 'topic-viewer__list-item-hidden': article.hidden }; - - let props = { + + return { className: classNames(classes), to: this.props.articlePath + article.id }; - - if(this.props.editable) { - _.extend(props, { - onDragOver: (this.state.currentDraggedId) ? this.onItemDragOver.bind(this, article, index) : null, - onDrop: (this.state.currentDraggedId) ? this.onItemDrop.bind(this, article, index) : null, - onDragStart: () => this.setState({currentDraggedId: article.id}), - onDragEnd: () => { - if(this.state.currentDraggedId) { - this.setState({articles: this.props.articles, currentDraggedId: 0}); - } - } - }); - } - - return props; } onDeleteClick() { diff --git a/client/src/app-components/topic-viewer.scss b/client/src/app-components/topic-viewer.scss index 0f489be2..f674fd88 100644 --- a/client/src/app-components/topic-viewer.scss +++ b/client/src/app-components/topic-viewer.scss @@ -38,12 +38,22 @@ width: 50%; color: $secondary-blue; margin-bottom: 10px; + user-select: none; &-hidden { - width: 80%; - display: inline-block; opacity: 0; } + + &:hover { + .topic-viewer__grab-icon { + display: inline-block; + left: 0; + } + } + + &-button { + user-select: none; + } } &-item:before { @@ -52,10 +62,18 @@ } &-item-button { + display: inline-block; color: $secondary-blue; } } + &__grab-icon { + color: $grey; + cursor: move; + margin-left: 10px; + display: none; + } + &__add-item { color: $dark-grey; } diff --git a/client/src/core-components/icon.js b/client/src/core-components/icon.js index d26123d1..becdb99b 100644 --- a/client/src/core-components/icon.js +++ b/client/src/core-components/icon.js @@ -19,7 +19,7 @@ class Icon extends React.Component { renderFontIcon() { return ( -