From 873dfa4ae8da56e050974d54f555fbf1558eba0e Mon Sep 17 00:00:00 2001 From: Victor Gonchar Date: Sat, 2 Feb 2019 23:45:02 +0200 Subject: [PATCH] 'add comments without css' --- .eslintrc | 2 +- Intl/localizationData/en.js | 5 ++ Intl/localizationData/fr.js | 5 ++ client/modules/App/App.js | 2 +- client/modules/App/AppActions.js | 7 ++ client/modules/App/AppReducer.js | 13 +++- client/modules/Post/CommentActions.js | 18 ++++++ .../modules/Post/CommentEdit/CommentEdit.css | 59 +++++++++++++++++ .../modules/Post/CommentEdit/CommentEdit.js | 62 ++++++++++++++++++ client/modules/Post/CommentReducer.js | 34 ++++++++++ client/modules/Post/PostReducer.js | 3 +- .../CommentCreate/CommentCreate.css | 52 +++++++++++++++ .../components/CommentCreate/CommentCreate.js | 64 +++++++++++++++++++ client/modules/Post/components/CommentList.js | 32 ++++++++++ .../CommentListItem/CommentListItem.css | 62 ++++++++++++++++++ .../CommentListItem/CommentListItem.js | 49 ++++++++++++++ client/modules/Post/components/PostList.js | 3 + .../components/PostListItem/PostListItem.js | 10 +++ .../pages/PostDetailPage/PostDetailPage.js | 1 + client/reducers.js | 2 + package-lock.json | 41 ++++++++---- server/controllers/post.controller.js | 3 +- server/dummyData.js | 4 +- 23 files changed, 512 insertions(+), 21 deletions(-) create mode 100644 client/modules/Post/CommentActions.js create mode 100644 client/modules/Post/CommentEdit/CommentEdit.css create mode 100644 client/modules/Post/CommentEdit/CommentEdit.js create mode 100644 client/modules/Post/CommentReducer.js create mode 100644 client/modules/Post/components/CommentCreate/CommentCreate.css create mode 100644 client/modules/Post/components/CommentCreate/CommentCreate.js create mode 100644 client/modules/Post/components/CommentList.js create mode 100644 client/modules/Post/components/CommentListItem/CommentListItem.css create mode 100644 client/modules/Post/components/CommentListItem/CommentListItem.js diff --git a/.eslintrc b/.eslintrc index 1e68f4e8c..c8f3bae20 100644 --- a/.eslintrc +++ b/.eslintrc @@ -22,7 +22,7 @@ "no-underscore-dangle" : 0, "max-len": [1, 180, 4], "arrow-body-style": [0], - "react/jsx-no-bind": [0], + "react/prefer-stateless-function": "off", "import/no-unresolved": [0] // Until import plugin supports webpack 2 resolveModules } } diff --git a/Intl/localizationData/en.js b/Intl/localizationData/en.js index 79b481d3c..6d94766eb 100644 --- a/Intl/localizationData/en.js +++ b/Intl/localizationData/en.js @@ -7,6 +7,11 @@ export default { twitterMessage: 'We are on Twitter', by: 'By', deletePost: 'Delete Post', + deleteComment:'Delete Comment', + addComment: 'Add Comment', + editComment: 'Edit Comment', + createComment: 'Create comment', + commentContent: 'Comment Content', createNewPost: 'Create new post', authorName: 'Author\'s Name', postTitle: 'Post Title', diff --git a/Intl/localizationData/fr.js b/Intl/localizationData/fr.js index 7e5b81b3f..14d83105b 100644 --- a/Intl/localizationData/fr.js +++ b/Intl/localizationData/fr.js @@ -7,6 +7,11 @@ export default { twitterMessage: 'Nous sommes sur Twitter', by: 'Par', deletePost: 'Supprimer le message', + deleteComment: 'Supprimer le commentaire', +    addComment: 'Ajouter un commentaire', +    editComment: 'Modifier le commentaire', + createComment: 'Créer un commentaire', + commentContent: 'Comment Content', createNewPost: 'Créer un nouveau message', authorName: 'Nom de l\'auteur', postTitle: 'Titre de l\'article', diff --git a/client/modules/App/App.js b/client/modules/App/App.js index 269df3d08..40cf5fbc5 100644 --- a/client/modules/App/App.js +++ b/client/modules/App/App.js @@ -32,7 +32,7 @@ export class App extends Component { toggleAddPostSection = () => { this.props.dispatch(toggleAddPost()); - }; + } render() { return ( diff --git a/client/modules/App/AppActions.js b/client/modules/App/AppActions.js index d4b7020a3..80594bb1f 100644 --- a/client/modules/App/AppActions.js +++ b/client/modules/App/AppActions.js @@ -1,5 +1,6 @@ // Export Constants export const TOGGLE_ADD_POST = 'TOGGLE_ADD_POST'; +export const TOGGLE_ADD_COMMENT = 'TOGGLE_ADD_COMMENT'; // Export Actions export function toggleAddPost() { @@ -7,3 +8,9 @@ export function toggleAddPost() { type: TOGGLE_ADD_POST, }; } + +export function toggleAddComment() { + return { + type: TOGGLE_ADD_COMMENT, + }; +} diff --git a/client/modules/App/AppReducer.js b/client/modules/App/AppReducer.js index ed3cf4827..295a9e46c 100644 --- a/client/modules/App/AppReducer.js +++ b/client/modules/App/AppReducer.js @@ -1,9 +1,10 @@ // Import Actions -import { TOGGLE_ADD_POST } from './AppActions'; +import { TOGGLE_ADD_POST, TOGGLE_ADD_COMMENT } from './AppActions'; // Initial State const initialState = { showAddPost: false, + showAddComment: false, }; const AppReducer = (state = initialState, action) => { @@ -11,8 +12,13 @@ const AppReducer = (state = initialState, action) => { case TOGGLE_ADD_POST: return { showAddPost: !state.showAddPost, + showAddComment: state.showAddComment, + }; + case TOGGLE_ADD_COMMENT: + return { + showAddPost: state.showAddPost, + showAddComment: !state.showAddComment, }; - default: return state; } @@ -22,6 +28,7 @@ const AppReducer = (state = initialState, action) => { // Get showAddPost export const getShowAddPost = state => state.app.showAddPost; - +// Get showAddComment +export const getShowAddComment = state => state.app.showAddComment; // Export Reducer export default AppReducer; diff --git a/client/modules/Post/CommentActions.js b/client/modules/Post/CommentActions.js new file mode 100644 index 000000000..c1c5165cf --- /dev/null +++ b/client/modules/Post/CommentActions.js @@ -0,0 +1,18 @@ +// Export Constants +export const ADD_COMMENT = 'ADD_COMMENT'; +export const DELETE_COMMENT = 'DELETE_COMMENT'; + +// Export Actions +export function addComment(comment) { + return { + type: ADD_COMMENT, + comment, + }; +} + +export function deleteComment(commentId) { + return { + type: DELETE_COMMENT, + commentId, + }; +} diff --git a/client/modules/Post/CommentEdit/CommentEdit.css b/client/modules/Post/CommentEdit/CommentEdit.css new file mode 100644 index 000000000..781d2a26a --- /dev/null +++ b/client/modules/Post/CommentEdit/CommentEdit.css @@ -0,0 +1,59 @@ +.form { + display: none; + background: #FAFAFA; + padding: 32px 0; + border: 1px solid #eee; + border-radius: 4px; +} + +.form-content{ + width: 100%; + max-width: 600px; + margin: auto; + font-size: 14px; +} + +.form-title{ + font-size: 16px; + font-weight: 700; + margin-bottom: 16px; + color: #757575; +} + +.form-field{ + width: 100%; + margin-bottom: 16px; + font-family: 'Lato', sans-serif; + font-size: 16px; + line-height: normal; + padding: 12px 16px; + border-radius: 4px; + border: 1px solid #ddd; + outline: none; + color: #212121; +} + +textarea { + min-height: 200px; +} + +.post-submit-button { + display: inline-block; + padding: 8px 16px; + font-size: 18px; + color: #FFF; + background: #03A9F4; + text-decoration: none; + border-radius: 4px; +} + +.appear { + display: block; +} + +.comment-edit { + color: #555; + text-decoration: none; + font-size: 14px; + font-style: italic; +} \ No newline at end of file diff --git a/client/modules/Post/CommentEdit/CommentEdit.js b/client/modules/Post/CommentEdit/CommentEdit.js new file mode 100644 index 000000000..8b40f3975 --- /dev/null +++ b/client/modules/Post/CommentEdit/CommentEdit.js @@ -0,0 +1,62 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { connect } from 'react-redux'; +import { FormattedMessage } from 'react-intl'; +import { addComment, deleteComment } from '../CommentActions'; +import { toggleAddComment } from '../../App/AppActions'; + +// Import Style +import styles from './CommentEdit.css'; + +export class CommentEditA extends Component { + editComment() { + this.props.toggleAddComment(); + const nameRef = this.refs.name; + const contentRef = this.refs.content; + if (nameRef.value && contentRef.value && this.props.comment.commentId) { + const comment = { postId: this.props.comment.postId, name: nameRef.value, content: contentRef.value, commentId: this.props.comment.commentId }; + this.props.deleteComment(this.props.comment.commentId); + this.props.addComment(comment); + nameRef.value = contentRef.value = ''; + } + } + + render() { + const cls = `${styles.form} ${(this.props.showAddComment ? styles.appear : '')}`; + if (this.props.showAddComment) { + this.refs.name.value = this.props.comment.name; + this.refs.content.value = this.props.comment.content; + } + return ( +
+
+
+

+ +