From fe58a5076ed83ce45f8d2cb1911037ed5fe26a7f Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Mon, 8 May 2017 18:05:39 -0300 Subject: [PATCH] Adding coral-plugin-love --- .gitignore | 1 + plugins/coral-plugin-love/client/.babelrc | 14 ++++ .../coral-plugin-love/client/.eslintrc.json | 23 ++++++ .../coral-plugin-love/client/LoveButton.js | 41 +++++++++++ plugins/coral-plugin-love/client/index.js | 7 ++ plugins/coral-plugin-love/client/styles.css | 26 +++++++ .../client/translations.json | 10 +++ plugins/coral-plugin-love/index.js | 37 ++++++++++ .../coral-plugin-love/server/typeDefs.graphql | 70 +++++++++++++++++++ 9 files changed, 229 insertions(+) create mode 100644 plugins/coral-plugin-love/client/.babelrc create mode 100644 plugins/coral-plugin-love/client/.eslintrc.json create mode 100644 plugins/coral-plugin-love/client/LoveButton.js create mode 100644 plugins/coral-plugin-love/client/index.js create mode 100644 plugins/coral-plugin-love/client/styles.css create mode 100644 plugins/coral-plugin-love/client/translations.json create mode 100644 plugins/coral-plugin-love/index.js create mode 100644 plugins/coral-plugin-love/server/typeDefs.graphql diff --git a/.gitignore b/.gitignore index a619f0988..e3ae90b9c 100644 --- a/.gitignore +++ b/.gitignore @@ -20,5 +20,6 @@ plugins/* !plugins/coral-plugin-respect !plugins/coral-plugin-offtopic !plugins/coral-plugin-like +!plugins/coral-plugin-love **/node_modules/* diff --git a/plugins/coral-plugin-love/client/.babelrc b/plugins/coral-plugin-love/client/.babelrc new file mode 100644 index 000000000..60be246eb --- /dev/null +++ b/plugins/coral-plugin-love/client/.babelrc @@ -0,0 +1,14 @@ +{ + "presets": [ + "es2015" + ], + "plugins": [ + "add-module-exports", + "transform-class-properties", + "transform-decorators-legacy", + "transform-object-assign", + "transform-object-rest-spread", + "transform-async-to-generator", + "transform-react-jsx" + ] +} \ No newline at end of file diff --git a/plugins/coral-plugin-love/client/.eslintrc.json b/plugins/coral-plugin-love/client/.eslintrc.json new file mode 100644 index 000000000..9fe56bd14 --- /dev/null +++ b/plugins/coral-plugin-love/client/.eslintrc.json @@ -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"] }] + } +} diff --git a/plugins/coral-plugin-love/client/LoveButton.js b/plugins/coral-plugin-love/client/LoveButton.js new file mode 100644 index 000000000..667c32a79 --- /dev/null +++ b/plugins/coral-plugin-love/client/LoveButton.js @@ -0,0 +1,41 @@ +import React from 'react'; +import withReaction from 'coral-framework/hocs/withReaction'; +import styles from './styles.css'; +import {Icon} from 'coral-ui'; + +class LoveButton extends React.Component { + handleClick = () => { + const { postReaction, deleteReaction, showSignInDialog, reactionSummary} = this.props; + const { root: { me }, comment } = this.props; + + // If the current user does not exist, trigger sign in dialog. + if (!me) { + showSignInDialog(); + return; + } + + // If the current user is banned, do nothing. + if (me.status === 'BANNED') { + return; + } + + if (reactionSummary) { + deleteReaction(); + } else { + postReaction(); + } + }; + + render() { + const {count, reactionSummary} = this.props; + return ( + + ); + } +} + +export default withReaction('love')(LoveButton); \ No newline at end of file diff --git a/plugins/coral-plugin-love/client/index.js b/plugins/coral-plugin-love/client/index.js new file mode 100644 index 000000000..f048963b4 --- /dev/null +++ b/plugins/coral-plugin-love/client/index.js @@ -0,0 +1,7 @@ +import LoveButton from './LoveButton'; + +export default { + slots: { + commentReactions: [LoveButton] + } +}; diff --git a/plugins/coral-plugin-love/client/styles.css b/plugins/coral-plugin-love/client/styles.css new file mode 100644 index 000000000..d48e7e28c --- /dev/null +++ b/plugins/coral-plugin-love/client/styles.css @@ -0,0 +1,26 @@ +.respect { + display: inline-block; +} + +.button { + color: #2a2a2a; + margin: 5px 10px 5px 0px; + background: none; + padding: 0px; + border: none; + font-size: inherit; + + &:hover { + color: #767676; + cursor: pointer; + } + + &.loved { + color: #e52338; + + &:hover { + color: #e52839; + cursor: pointer; + } + } +} diff --git a/plugins/coral-plugin-love/client/translations.json b/plugins/coral-plugin-love/client/translations.json new file mode 100644 index 000000000..93d73d3a2 --- /dev/null +++ b/plugins/coral-plugin-love/client/translations.json @@ -0,0 +1,10 @@ +{ + "en": { + "like": "Like", + "liked": "Liked" + }, + "es": { + "like": "Me Gusta", + "liked": "Me Gustó" + } +} diff --git a/plugins/coral-plugin-love/index.js b/plugins/coral-plugin-love/index.js new file mode 100644 index 000000000..48b4d16c0 --- /dev/null +++ b/plugins/coral-plugin-love/index.js @@ -0,0 +1,37 @@ +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: { + createLove(_, {love: {item_id, item_type}}, {mutators: {Action}}) { + return wrapResponse('love')(Action.create({item_id, item_type, action_type: 'LOVE'})); + } + } + }, + hooks: { + Action: { + __resolveType: { + post({action_type}) { + switch (action_type) { + case 'LOVE': + return 'LoveAction'; + } + } + } + }, + ActionSummary: { + __resolveType: { + post({action_type}) { + switch (action_type) { + case 'LOVE': + return 'LoveActionSummary'; + } + } + } + } + } +}; + diff --git a/plugins/coral-plugin-love/server/typeDefs.graphql b/plugins/coral-plugin-love/server/typeDefs.graphql new file mode 100644 index 000000000..e22b91a2d --- /dev/null +++ b/plugins/coral-plugin-love/server/typeDefs.graphql @@ -0,0 +1,70 @@ +enum ACTION_TYPE { + + # Represents a Love. + LOVE +} + +enum ASSET_METRICS_SORT { + + # Represents a LoveAction. + LOVE +} + +input CreateLoveInput { + + # The item's id for which we are to create a love. + item_id: ID! + + # The type of the item for which we are to create the love. + item_type: ACTION_ITEM_TYPE! +} + +# LoveAction is used by users who "love" a specific entity. +type LoveAction implements Action { + + # The ID of the action. + id: ID! + + # The author of the action. + user: User + + # The time when the Action was updated. + updated_at: Date + + # The time when the Action was created. + created_at: Date +} + +type LoveActionSummary implements ActionSummary { + + # The count of actions with this group. + count: Int + + # The current user's action. + current_user: LoveAction +} + +# A summary of counts related to all the Loves on an Asset. +type LoveAssetActionSummary implements AssetActionSummary { + + # Number of loves associated with actionable types on this this Asset. + actionCount: Int + + # Number of unique actionable types that are referenced by the loves. + actionableItemCount: Int +} + +type CreateLoveResponse implements Response { + + # The love that was created. + love: LoveAction + + # An array of errors relating to the mutation that occurred. + errors: [UserError] +} + +type RootMutation { + + # Creates a love on an entity. + createLove(love: CreateLoveInput!): CreateLoveResponse +}