Merge branch 'plugin' into plugin-kiwi

Conflicts:
	plugins/coral-plugin-respect/index.js
This commit is contained in:
Chi Vinh Le
2017-04-03 12:10:07 +07:00
10 changed files with 78 additions and 50 deletions
@@ -0,0 +1,23 @@
{
"env": {
"browser": true,
"es6": true,
"mocha": true
},
"parserOptions": {
"sourceType": "module",
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true
}
},
"parser": "babel-eslint",
"plugins": [
"react"
],
"rules": {
"react/jsx-uses-react": "error",
"react/jsx-uses-vars": "error",
"no-console": ["warn", { "allow": ["warn", "error"] }]
}
}
@@ -1,5 +1,5 @@
import React from 'react';
export default () => (
<i className="fa fa-handshake-o" aria-hidden="true"></i>
<i className="fa fa-handshake-o" aria-hidden="true"/>
);
@@ -1,4 +1,4 @@
{
"name": "Coral Plugin Respect",
"slot": "Comment.Detail"
}
}
+11 -3
View File
@@ -2,6 +2,10 @@ import React from 'react';
import styles from './style.css';
import Icon from './components/Icon';
import {I18n} from 'coral-framework';
import translations from './translations.json';
const lang = new I18n(translations);
import {getActionSummary} from 'coral-framework/utils';
class RespectButton extends React.Component {
@@ -15,7 +19,7 @@ class RespectButton extends React.Component {
}
handleClick = () => {
const {comment, postRespect, showSignInDialog, currentUser} = this.props.context;
const {comment, postRespect, showSignInDialog, currentUser, deleteAction} = this.props.context;
const {localPost, localDelete} = this.state;
const respect = getActionSummary('RespectActionSummary', comment);
const respected = (respect && respect.current_user && !localDelete) || localPost;
@@ -54,6 +58,7 @@ class RespectButton extends React.Component {
} else {
this.setState((prev) => prev.localPost ? {...prev, localPost: null} : {...prev, localDelete: true});
deleteAction(localPost || respect.current_user.id);
}
}
@@ -61,6 +66,7 @@ class RespectButton extends React.Component {
const {comment} = this.props.context;
const {localPost, localDelete} = this.state;
const respect = getActionSummary('RespectActionSummary', comment);
const respected = (respect && respect.current_user && !localDelete) || localPost;
let count = respect ? respect.count : 0;
if (localPost) {count += 1;}
@@ -68,8 +74,10 @@ class RespectButton extends React.Component {
return (
<div className={styles.Respect}>
<button onClick={this.handleClick}>
Respect
<button
className={respected ? styles.respected : ''}
onClick={this.handleClick} >
<span>{lang.t(respected ? 'respected' : 'respect')}</span>
<Icon />
{count > 0 && count}
</button>
@@ -14,11 +14,14 @@
}
}
.clicked {
.respected {
color: #ffcc00;
i {
color: #161616;
}
}
i {
padding: 0 5px;
}
}
}
+2 -1
View File
@@ -1,12 +1,13 @@
const {readFileSync} = require('fs');
const path = require('path');
const wrapResponse = require('../../graph/helpers/response');
module.exports = {
typeDefs: readFileSync(path.join(__dirname, 'server/typeDefs.graphql'), 'utf8'),
resolvers: {
RootMutation: {
createRespect(_, {respect: {item_id, item_type}}, {mutators: {Action}}) {
return Action.create({item_id, item_type, action_type: 'RESPECT'});
return wrapResponse('respect')(Action.create({item_id, item_type, action_type: 'RESPECT'}));
}
}
},