diff --git a/client/src/app-components/articles-list.js b/client/src/app-components/articles-list.js new file mode 100644 index 00000000..077a79ac --- /dev/null +++ b/client/src/app-components/articles-list.js @@ -0,0 +1,86 @@ +import React from 'react'; + +import API from 'lib-app/api-call'; +import i18n from 'lib-app/i18n'; + +import TopicViewer from 'app-components/topic-viewer'; +import ModalContainer from 'app-components/modal-container'; +import TopicEditModal from 'app-components/topic-edit-modal'; + +import Loading from 'core-components/loading'; +import Button from 'core-components/button'; +import Icon from 'core-components/icon'; + +class ArticlesList extends React.Component { + + static propTypes = { + editable: React.PropTypes.bool + }; + + static defaultProps = { + editable: true + }; + + state = { + loading: true, + topics: [] + }; + + componentDidMount() { + this.retrieveArticles(); + } + + render() { + return (this.state.loading) ? : this.renderContent(); + } + + renderContent() { + return ( +
+ {this.renderTopics()} + {(this.props.editable) ? this.renderAddTopicButton() : null} +
+ ); + } + + renderTopics() { + return ( +
+ {this.state.topics.map((topic, index) => { + return ( +
+ + +
+ ); + })} +
+ ); + } + + renderAddTopicButton() { + return ( +
+ +
+ ); + } + + retrieveArticles() { + API.call({ + path: '/article/get-all', + data: {} + }).then(this.onRetrieveSuccess.bind(this)); + } + + onRetrieveSuccess(result) { + this.setState({ + loading: false, + topics: result.data + }); + } +} + +export default ArticlesList; \ No newline at end of file diff --git a/client/src/app-components/articles-list.scss b/client/src/app-components/articles-list.scss new file mode 100644 index 00000000..df4325bd --- /dev/null +++ b/client/src/app-components/articles-list.scss @@ -0,0 +1,22 @@ +@import "../scss/vars"; + +.articles-list { + + &__add { + position: relative; + } + + &__add-icon { + position: absolute; + left: 10px; + margin-top: -4px; + } + + &__topic-separator { + background-color: $grey; + display: block; + height: 1px; + margin: 30px 0; + width: 100%; + } +} \ No newline at end of file diff --git a/client/src/app-components/topic-edit-modal.js b/client/src/app-components/topic-edit-modal.js index bc15de30..f092699c 100644 --- a/client/src/app-components/topic-edit-modal.js +++ b/client/src/app-components/topic-edit-modal.js @@ -19,21 +19,22 @@ class TopicEditModal extends React.Component { static propTypes = { defaultValues: React.PropTypes.object, + addForm: React.PropTypes.bool, topicId: React.PropTypes.number }; state = { - values: this.props.defaultValues + values: this.props.defaultValues || {title: ''} }; render() { return (
-
+
- - + + {i18n('SAVE')} @@ -48,10 +49,10 @@ class TopicEditModal extends React.Component { onSubmit() { API.call({ - path: '/article/edit-topic', + path: (this.props.addForm) ? '/article/add-topic' : '/article/edit-topic', data: { topicId: this.props.topicId, - name: this.state.values['name'], + name: this.state.values['title'], icon: this.state.values['icon'], iconColor: this.state.values['color'] } diff --git a/client/src/app-components/topic-viewer.js b/client/src/app-components/topic-viewer.js index c85cb52d..9a97ebbf 100644 --- a/client/src/app-components/topic-viewer.js +++ b/client/src/app-components/topic-viewer.js @@ -15,7 +15,7 @@ import Button from 'core-components/button'; class TopicViewer extends React.Component { static propTypes = { - topicId: React.PropTypes.number.isRequired, + id: React.PropTypes.number.isRequired, name: React.PropTypes.string.isRequired, icon: React.PropTypes.string.isRequired, iconColor: React.PropTypes.string.isRequired, @@ -83,7 +83,7 @@ class TopicViewer extends React.Component { renderEditModal() { let props = { - topicId: this.props.topicId, + topicId: this.props.id, defaultValues: { title: this.props.name, icon: this.props.icon, @@ -98,7 +98,7 @@ class TopicViewer extends React.Component { renderAddNewArticle() { let props = { - topicId: this.props.topicId, + topicId: this.props.id, position: this.props.articles.length, topicName: this.props.name }; @@ -139,7 +139,7 @@ class TopicViewer extends React.Component { API.call({ path: '/article/delete-topic', data: { - topicId: this.props.topicId + topicId: this.props.id } }).then(this.onChange.bind(this)); } diff --git a/client/src/app/admin/panel/articles/admin-panel-list-articles.js b/client/src/app/admin/panel/articles/admin-panel-list-articles.js index 0899807b..223fb157 100644 --- a/client/src/app/admin/panel/articles/admin-panel-list-articles.js +++ b/client/src/app/admin/panel/articles/admin-panel-list-articles.js @@ -1,46 +1,21 @@ import React from 'react'; -import API from 'lib-app/api-call'; -import TopicViewer from 'app-components/topic-viewer'; +import i18n from 'lib-app/i18n'; +import ArticlesList from 'app-components/articles-list'; +import Header from 'core-components/header'; class AdminPanelListArticles extends React.Component { - state = { - loading: true, - topics: [] - }; - - componentDidMount() { - API.call({ - path: '/article/get-all', - data: {} - }).then(this.onRetrieveSuccess.bind(this)); - } - render() { return ( -
- {this.state.loading ? 'loading' : this.renderTopics()} +
+
+
+ +
); } - - renderTopics() { - return ( -
- {this.state.topics.map(function (topic) { - return - })} -
- ) - } - - onRetrieveSuccess(result) { - this.setState({ - loading: false, - topics: result.data - }); - } } export default AdminPanelListArticles; \ No newline at end of file diff --git a/client/src/app/admin/panel/articles/admin-panel-list-articles.scss b/client/src/app/admin/panel/articles/admin-panel-list-articles.scss new file mode 100644 index 00000000..1807e990 --- /dev/null +++ b/client/src/app/admin/panel/articles/admin-panel-list-articles.scss @@ -0,0 +1,6 @@ +.admin-panel-list-articles { + + &__list { + padding: 0 50px; + } +} \ No newline at end of file diff --git a/client/src/data/languages/en.js b/client/src/data/languages/en.js index 751a4790..f473f4b3 100644 --- a/client/src/data/languages/en.js +++ b/client/src/data/languages/en.js @@ -105,6 +105,7 @@ export default { 'DELETE_TOPIC_DESCRIPTION': 'By deleting the topic, all articles on it will be erased.', 'EDIT_TOPIC_DESCRIPTION': 'Here you can change the name, the icon and the icon color of the topic.', 'ADD_ARTICLE_DESCRIPTION': 'Here you can add an article that will be available for every user. It will be added inside the category {category}.', + 'LIST_ARTICLES_DESCRIPTION': 'This is a list of articles that includes information about our services.', //ERRORS 'EMAIL_OR_PASSWORD': 'Email or password invalid',