From 735aa6fbd35cdd8528c89db85f4495411da4a569 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Fri, 7 Apr 2017 16:40:30 -0600 Subject: [PATCH 01/22] Added new Metadata Service and models --- models/asset.js | 6 ++++ models/comment.js | 8 ++++- services/metadata.js | 80 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 services/metadata.js diff --git a/models/asset.js b/models/asset.js index f0046aef0..51ff42705 100644 --- a/models/asset.js +++ b/models/asset.js @@ -46,6 +46,12 @@ const AssetSchema = new Schema({ type: Schema.Types.Mixed, default: null }, + + // Additional metadata stored on the field. + metadata: { + default: {}, + type: Object + } }, { versionKey: false, timestamps: { diff --git a/models/comment.js b/models/comment.js index e6523e45f..0984a0832 100644 --- a/models/comment.js +++ b/models/comment.js @@ -75,7 +75,13 @@ const CommentSchema = new Schema({ default: 'NONE' }, tags: [TagSchema], - parent_id: String + parent_id: String, + + // Additional metadata stored on the field. + metadata: { + default: {}, + type: Object + } }, { timestamps: { createdAt: 'created_at', diff --git a/services/metadata.js b/services/metadata.js new file mode 100644 index 000000000..a0c433f8b --- /dev/null +++ b/services/metadata.js @@ -0,0 +1,80 @@ +/** + * The key must be composed of alpha characters with periods seperating them. + */ +const KEY_REGEX = /^(?:[A-Za-z][A-Za-z\.]*[A-Za-z])?(?:[A-Za-z]*)$/; + +/** + * Allows metadata properties to be set/unset from specific models. It is the + * expecatation of this API that the metadata field is either accessed later + * directly, or accessed as a result of another database load rather than + * this service providing an interface to do so. + * + * @class MetadataService + */ +class MetadataService { + + /** + * Parses a key by ensuring that if it is either a string, or an array with + * only characters defined in the `KEY_REGEX` + * + * @static + * @param {String|Array} key + * @returns {String} string form of the key + * + * @memberOf Metadata + */ + static parseKey(key) { + if (Array.isArray(key)) { + key = key.join('.'); + } + + if ((typeof key !== 'string') || !KEY_REGEX.test(key) || key.length === 0) { + throw new Error(`${key} is not valid, only a-zA-Z. allowed`); + } + + return ['metadata', key].join('.'); + } + + /** + * Sets an object on the metadata field of an object. + * + * @static + * @param {mongoose.Model} model the mongoose model for the object + * @param {String} id the value for the field `id` of the model + * @param {String|Array} key key for the metadata field + * @param {any} value javascript object to set the value of the metadata to + * @returns {Promise} resolves when the update is complete + * + * @memberOf Metadata + */ + static async set(model, id, key, value) { + key = MetadataService.parseKey(key); + + return model.update({id}, { + $set: { + [key]: value + } + }); + } + + /** + * Removes the value for the metadata field as the specific key. + * + * @static + * @param {mongoose.Model} model the mongoose model for the object + * @param {String} id the value for the field `id` of the model + * @param {String|Array} key key for the metadata field + * @returns + * + * @memberOf Metadata + */ + static async unset(model, id, key) { + key = MetadataService.parseKey(key); + + return model.update({id}, { + $unset: key + }); + } +} + +module.exports = MetadataService; From 8e33d25a2801c9c0816ccaaa398f9ff4a1261f86 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Mon, 10 Apr 2017 12:12:07 -0600 Subject: [PATCH 02/22] Some bug fixes + validation updates --- graph/hooks.js | 8 ++++++++ services/metadata.js | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/graph/hooks.js b/graph/hooks.js index 499eb60b1..c5b7541b3 100644 --- a/graph/hooks.js +++ b/graph/hooks.js @@ -3,6 +3,7 @@ const { GraphQLInterfaceType } = require('graphql'); const debug = require('debug')('talk:graph:schema'); +const Joi = require('joi'); /** * XXX taken from graphql-js: src/execution/execute.js, because that function @@ -82,6 +83,8 @@ const decorateWithHooks = (schema, hooks) => forEachField(schema, (field, typeNa Object.keys(hooks).forEach((hook) => { switch (hook) { case 'pre': + Joi.assert(hooks.pre, Joi.func().maxArity(4)); + debug(`adding pre hook to resolver ${typeName}.${fieldName} from plugin '${plugin.name}'`); if (typeof hooks.pre !== 'function') { @@ -91,6 +94,8 @@ const decorateWithHooks = (schema, hooks) => forEachField(schema, (field, typeNa acc.pre.push(hooks.pre); break; case 'post': + Joi.assert(hooks.pre, Joi.func().maxArity(5)); + debug(`adding post hook to resolver ${typeName}.${fieldName} from plugin '${plugin.name}'`); if (typeof hooks.post !== 'function') { @@ -129,6 +134,9 @@ const decorateWithHooks = (schema, hooks) => forEachField(schema, (field, typeNa return; } + // Ensure it matches the format we expect. + Joi.assert(post, Joi.array().items(Joi.func().maxArity(3)), `invalid post hooks were found for ${typeName}.${fieldName}`); + // Cache the original resolverType function. let resolveType = field.resolveType; diff --git a/services/metadata.js b/services/metadata.js index a0c433f8b..2cabed8b8 100644 --- a/services/metadata.js +++ b/services/metadata.js @@ -72,7 +72,7 @@ class MetadataService { key = MetadataService.parseKey(key); return model.update({id}, { - $unset: key + $unset: {[key]: ''} }); } } From c5520e3fb66e67ac61aa9445d23a413b167ab280 Mon Sep 17 00:00:00 2001 From: gaba Date: Tue, 11 Apr 2017 12:22:05 -0700 Subject: [PATCH 03/22] Adds missing template. --- services/email/suspension.html.ejs | 1 + 1 file changed, 1 insertion(+) create mode 100644 services/email/suspension.html.ejs diff --git a/services/email/suspension.html.ejs b/services/email/suspension.html.ejs new file mode 100644 index 000000000..b36560ec5 --- /dev/null +++ b/services/email/suspension.html.ejs @@ -0,0 +1 @@ +<%= body %> From 3a3b89b03b24ba19f154c98f4da41b057540900f Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Tue, 11 Apr 2017 14:59:02 -0600 Subject: [PATCH 04/22] Fixed bugs with plugin install --- package.json | 2 +- plugins.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f4e2eb725..d974a78d4 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "e2e": "NODE_ENV=test nightwatch", "poste2e": "NODE_ENV=test scripts/poste2e.sh", "embed-start": "NODE_ENV=development yarn build && ./bin/cli serve --jobs", - "heroku-postbuild": "yarn build" + "heroku-postbuild": "./bin/cli plugins reconcile && yarn build" }, "config": { "pre-git": { diff --git a/plugins.js b/plugins.js index 02cdb58e1..65e80dee5 100644 --- a/plugins.js +++ b/plugins.js @@ -124,7 +124,12 @@ function itteratePlugins(plugins) { // Add each plugin folder to the allowed import path so that they can import our // internal dependancies. Object.keys(plugins).forEach((type) => itteratePlugins(plugins[type]).forEach((plugin) => { - amp.enableForDir(path.dirname(plugin.path)); + + // The plugin may be remote, and therefore not installed. We check here if the + // plugin path is available before trying to monkeypatch it's require path. + if (plugin.path) { + amp.enableForDir(path.dirname(plugin.path)); + } })); /** From 56dedb551f4c8bf88c04a0b0aec7a01db259f082 Mon Sep 17 00:00:00 2001 From: gaba Date: Tue, 11 Apr 2017 15:02:04 -0700 Subject: [PATCH 05/22] Adds click to showAll and refresh query to the '# comments' tab. --- client/coral-embed-stream/src/Embed.js | 8 +++++++- client/coral-plugin-comment-count/CommentCount.js | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/client/coral-embed-stream/src/Embed.js b/client/coral-embed-stream/src/Embed.js index d9b5c8310..4df0290ac 100644 --- a/client/coral-embed-stream/src/Embed.js +++ b/client/coral-embed-stream/src/Embed.js @@ -144,7 +144,13 @@ class Embed extends Component {
- + { + this.props.viewAllComments(); + this.props.data.refetch(); + }}/> + {lang.t('MY_COMMENTS')} Configure Stream diff --git a/client/coral-plugin-comment-count/CommentCount.js b/client/coral-plugin-comment-count/CommentCount.js index 764984634..e53944025 100644 --- a/client/coral-plugin-comment-count/CommentCount.js +++ b/client/coral-plugin-comment-count/CommentCount.js @@ -3,8 +3,8 @@ import {I18n} from '../coral-framework'; import translations from './translations.json'; const name = 'coral-plugin-comment-count'; -const CommentCount = ({count}) => { - return
+const CommentCount = ({count, onClick}) => { + return
onClick()}> {`${count} ${count === 1 ? lang.t('comment') : lang.t('comment-plural')}`}
; }; From 3c6ce7a80f8221e921f19156e7a1416ce4bc31af Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Tue, 11 Apr 2017 21:56:43 -0300 Subject: [PATCH 06/22] QuestionBox --- client/coral-embed-stream/style/default.css | 21 ++++++++++++------- .../coral-plugin-questionbox/QuestionBox.js | 4 +++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/client/coral-embed-stream/style/default.css b/client/coral-embed-stream/style/default.css index 89436e000..41ec7a64b 100644 --- a/client/coral-embed-stream/style/default.css +++ b/client/coral-embed-stream/style/default.css @@ -129,15 +129,15 @@ hr { margin-bottom: 0px; font-weight: bold; font-size: 14px; - display: block; overflow: hidden; - height: 50px; + min-height: 50px; + display: flex; } .coral-plugin-questionbox-icon.bubble{ position: absolute; top: 11px; - left: 15px; + left: 10px; color: #949393; font-size: 20px; z-index: 0; @@ -146,7 +146,7 @@ hr { .coral-plugin-questionbox-icon.person{ z-index: 2; top: 20px; - left: 20px; + left: 15px; position: absolute; font-size: 24px; color: white; @@ -161,12 +161,19 @@ hr { margin-left: 0px !important; margin-right: 10px; display: inline-block; - width: 15px; - height: 100%; - padding: 3px 20px; + width: 10px; + min-height: 100%; + padding: 5px 20px; vertical-align: middle; } +.coral-plugin-questionbox-content { + padding: 5px; + display: flex; + align-items: center; + justify-content: center; +} + .hidden { visibility: hidden; display: none; diff --git a/client/coral-plugin-questionbox/QuestionBox.js b/client/coral-plugin-questionbox/QuestionBox.js index 3c2410d44..31ad45869 100644 --- a/client/coral-plugin-questionbox/QuestionBox.js +++ b/client/coral-plugin-questionbox/QuestionBox.js @@ -7,7 +7,9 @@ const QuestionBox = ({enable, content}) => chat_bubble person
- {content} +
+ {content} +
; export default QuestionBox; From f900727455521a03271f08172343ea53e975fd48 Mon Sep 17 00:00:00 2001 From: gaba Date: Tue, 11 Apr 2017 17:57:56 -0700 Subject: [PATCH 07/22] Move the method to the class, changes name and removes wrapper. --- client/coral-embed-stream/src/Embed.js | 25 +++++++++++++------ .../CommentCount.js | 4 +-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/client/coral-embed-stream/src/Embed.js b/client/coral-embed-stream/src/Embed.js index 4df0290ac..aa4223757 100644 --- a/client/coral-embed-stream/src/Embed.js +++ b/client/coral-embed-stream/src/Embed.js @@ -1,4 +1,4 @@ -import React, {Component} from 'react'; +import React from 'react'; import {compose} from 'react-apollo'; import {connect} from 'react-redux'; import isEqual from 'lodash/isEqual'; @@ -36,9 +36,18 @@ import HighlightedComment from './Comment'; import LoadMore from './LoadMore'; import NewCount from './NewCount'; -class Embed extends Component { +class Embed extends React.Component { - state = {activeTab: 0, showSignInDialog: false, activeReplyBox: ''}; + constructor(props) { + super(props); + this.state = { + activeTab: 0, + showSignInDialog: + false, activeReplyBox: '' + }; + + this.handleClick = this.handleClick.bind(this); + } changeTab = (tab) => { const {isAdmin} = this.props.auth; @@ -114,6 +123,11 @@ class Embed extends Component { } } + handleClick() { + this.props.viewAllComments(); + this.props.data.refetch(); + } + render () { const {activeTab} = this.state; const {closedAt, countCache = {}} = this.props.asset; @@ -146,10 +160,7 @@ class Embed extends Component { { - this.props.viewAllComments(); - this.props.data.refetch(); - }}/> + handleClick={this.handleClick}/> {lang.t('MY_COMMENTS')} Configure Stream diff --git a/client/coral-plugin-comment-count/CommentCount.js b/client/coral-plugin-comment-count/CommentCount.js index e53944025..be38d1425 100644 --- a/client/coral-plugin-comment-count/CommentCount.js +++ b/client/coral-plugin-comment-count/CommentCount.js @@ -3,8 +3,8 @@ import {I18n} from '../coral-framework'; import translations from './translations.json'; const name = 'coral-plugin-comment-count'; -const CommentCount = ({count, onClick}) => { - return
onClick()}> +const CommentCount = ({count, handleClick}) => { + return
{`${count} ${count === 1 ? lang.t('comment') : lang.t('comment-plural')}`}
; }; From e4aa98b87a1446d19fbf8d00d71fdbdc9d4aab42 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Tue, 11 Apr 2017 22:00:55 -0300 Subject: [PATCH 08/22] Hidding login as --- client/coral-embed-stream/src/Embed.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/coral-embed-stream/src/Embed.js b/client/coral-embed-stream/src/Embed.js index d9b5c8310..673fee69e 100644 --- a/client/coral-embed-stream/src/Embed.js +++ b/client/coral-embed-stream/src/Embed.js @@ -158,7 +158,7 @@ class Embed extends Component { this.props.data.refetch(); }}>{lang.t('showAllComments')} } - {loggedIn && this.props.logout().then(refetch)} changeTab={this.changeTab}/>} + {loggedIn && activeTab !== 1 && this.props.logout().then(refetch)} changeTab={this.changeTab}/>} { openStream From 63b630833a86d83f6845cc8d083f3e6ef7cf07ad Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Tue, 11 Apr 2017 22:12:10 -0300 Subject: [PATCH 09/22] Fake Comment Style --- client/coral-sign-in/components/FakeComment.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/client/coral-sign-in/components/FakeComment.js b/client/coral-sign-in/components/FakeComment.js index b5af6bf1c..518bda5e3 100644 --- a/client/coral-sign-in/components/FakeComment.js +++ b/client/coral-sign-in/components/FakeComment.js @@ -28,10 +28,10 @@ class FakeComment extends React.Component { author={{'name': username}}/> -
+
- @@ -43,16 +43,16 @@ class FakeComment extends React.Component { banned={false} />
-
+
From 2e3021e66bd6612e10bdc27f9e19dab5b8514cfe Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Tue, 11 Apr 2017 22:17:04 -0300 Subject: [PATCH 10/22] Linting --- client/coral-sign-in/components/FakeComment.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/coral-sign-in/components/FakeComment.js b/client/coral-sign-in/components/FakeComment.js index 518bda5e3..f5926852c 100644 --- a/client/coral-sign-in/components/FakeComment.js +++ b/client/coral-sign-in/components/FakeComment.js @@ -30,8 +30,8 @@ class FakeComment extends React.Component {
- From 6ac4bcf796876865e482e7975f1e58e3a4d086fa Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Tue, 11 Apr 2017 22:25:13 -0600 Subject: [PATCH 11/22] Fixed plugin validation --- plugins.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins.js b/plugins.js index 65e80dee5..22293c975 100644 --- a/plugins.js +++ b/plugins.js @@ -47,8 +47,8 @@ const hookSchemas = { pre: Joi.func(), post: Joi.func() }))), - loaders: Joi.object().pattern(/\w/, Joi.object().pattern(/\w/, Joi.func())), - mutators: Joi.object().pattern(/\w/, Joi.object().pattern(/\w/, Joi.func())), + loaders: Joi.func().maxArity(1), + mutators: Joi.func().maxArity(1), resolvers: Joi.object().pattern(/\w/, Joi.object().pattern(/(?:__resolveType|\w+)/, Joi.func())), typeDefs: Joi.string() }; From cc0f757746c32a745abb920947b47c416b88e6b3 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Wed, 12 Apr 2017 08:16:02 -0300 Subject: [PATCH 12/22] Removing username --- client/coral-embed-stream/src/Embed.js | 2 +- client/coral-settings/containers/ProfileContainer.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/client/coral-embed-stream/src/Embed.js b/client/coral-embed-stream/src/Embed.js index 673fee69e..d9b5c8310 100644 --- a/client/coral-embed-stream/src/Embed.js +++ b/client/coral-embed-stream/src/Embed.js @@ -158,7 +158,7 @@ class Embed extends Component { this.props.data.refetch(); }}>{lang.t('showAllComments')} } - {loggedIn && activeTab !== 1 && this.props.logout().then(refetch)} changeTab={this.changeTab}/>} + {loggedIn && this.props.logout().then(refetch)} changeTab={this.changeTab}/>} { openStream diff --git a/client/coral-settings/containers/ProfileContainer.js b/client/coral-settings/containers/ProfileContainer.js index 9a8117e87..6df926c7c 100644 --- a/client/coral-settings/containers/ProfileContainer.js +++ b/client/coral-settings/containers/ProfileContainer.js @@ -44,7 +44,6 @@ class ProfileContainer extends Component { return (
- { // Hiding bio until moderation can get figured out From 1a678a0cb31525e49b001e5f21cd93f8f4d3c27b Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Wed, 12 Apr 2017 08:21:39 -0300 Subject: [PATCH 13/22] Removing username -- with lintin --- client/coral-settings/containers/ProfileContainer.js | 1 - 1 file changed, 1 deletion(-) diff --git a/client/coral-settings/containers/ProfileContainer.js b/client/coral-settings/containers/ProfileContainer.js index 6df926c7c..331069058 100644 --- a/client/coral-settings/containers/ProfileContainer.js +++ b/client/coral-settings/containers/ProfileContainer.js @@ -8,7 +8,6 @@ import {myCommentHistory} from 'coral-framework/graphql/queries'; import {link} from 'coral-framework/services/PymConnection'; import NotLoggedIn from '../components/NotLoggedIn'; import {Spinner} from 'coral-ui'; -import ProfileHeader from '../components/ProfileHeader'; import CommentHistory from 'coral-plugin-history/CommentHistory'; import translations from '../translations'; From 8e76a34631341f48f491a2c5783e47ddd43d0703 Mon Sep 17 00:00:00 2001 From: Kim Gardner Date: Wed, 12 Apr 2017 08:45:19 -0400 Subject: [PATCH 14/22] Bump version and update description --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d974a78d4..41d8732de 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "talk", - "version": "1.4.0", - "description": "A commenting platform from The Coral Project. https://coralproject.net", + "version": "1.5.0", + "description": "A better commenting experience from Mozilla, The New York Times, and the Washington Post. https://coralproject.net", "main": "app.js", "scripts": { "postinstall": "./bin/cli plugins reconcile --skip-remote", From d74cdd938f51d09a14d5e5004a5e8f4dee9c79e3 Mon Sep 17 00:00:00 2001 From: Kim Gardner Date: Wed, 12 Apr 2017 09:51:32 -0400 Subject: [PATCH 15/22] Double quotes should be single --- client/coral-sign-in/translations.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/coral-sign-in/translations.json b/client/coral-sign-in/translations.json index 824888cca..e0203e0af 100644 --- a/client/coral-sign-in/translations.json +++ b/client/coral-sign-in/translations.json @@ -25,14 +25,14 @@ "emailInUse": "Email address already in use", "emailORusernameInUse": "Email address or Username already in use", "requiredField": "This field is required", - "passwordsDontMatch": "Passwords don\"t match.", + "passwordsDontMatch": "Passwords don\'t match.", "specialCharacters": "Usernames can contain letters, numbers and _ only", "checkTheForm": "Invalid Form. Please, check the fields" }, "createdisplay": { "writeyourusername": "Edit your username", "yourusername": "Your username appears on every comment you post.", - "ifyoudontchangeyourname": "If you don\"t change your username at this step, your Facebook display name will appear alongside of all your comments.", + "ifyoudontchangeyourname": "If you don\'t change your username at this step, your Facebook display name will appear alongside of all your comments.", "username": "Username", "continue": "Continue with the same Facebook username", "save": "Save", From a19d6544a7fa15c9785b452706a578d41d0893d2 Mon Sep 17 00:00:00 2001 From: Kim Gardner Date: Wed, 12 Apr 2017 10:05:21 -0400 Subject: [PATCH 16/22] Don't need to escape single quotes within double quotes --- client/coral-sign-in/translations.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/coral-sign-in/translations.json b/client/coral-sign-in/translations.json index e0203e0af..7ae84b2ff 100644 --- a/client/coral-sign-in/translations.json +++ b/client/coral-sign-in/translations.json @@ -25,14 +25,14 @@ "emailInUse": "Email address already in use", "emailORusernameInUse": "Email address or Username already in use", "requiredField": "This field is required", - "passwordsDontMatch": "Passwords don\'t match.", + "passwordsDontMatch": "Passwords don't match.", "specialCharacters": "Usernames can contain letters, numbers and _ only", "checkTheForm": "Invalid Form. Please, check the fields" }, "createdisplay": { "writeyourusername": "Edit your username", "yourusername": "Your username appears on every comment you post.", - "ifyoudontchangeyourname": "If you don\'t change your username at this step, your Facebook display name will appear alongside of all your comments.", + "ifyoudontchangeyourname": "If you don't change your username at this step, your Facebook display name will appear alongside of all your comments.", "username": "Username", "continue": "Continue with the same Facebook username", "save": "Save", From f4f8e5053f1a0d59d040631c687fe7cb536a0e5c Mon Sep 17 00:00:00 2001 From: gaba Date: Wed, 12 Apr 2017 10:11:21 -0700 Subject: [PATCH 17/22] Remove the binding in the constructor. --- client/coral-embed-stream/src/Embed.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/client/coral-embed-stream/src/Embed.js b/client/coral-embed-stream/src/Embed.js index aa4223757..453d645c2 100644 --- a/client/coral-embed-stream/src/Embed.js +++ b/client/coral-embed-stream/src/Embed.js @@ -42,11 +42,9 @@ class Embed extends React.Component { super(props); this.state = { activeTab: 0, - showSignInDialog: - false, activeReplyBox: '' + showSignInDialog: false, + activeReplyBox: '' }; - - this.handleClick = this.handleClick.bind(this); } changeTab = (tab) => { @@ -123,7 +121,7 @@ class Embed extends React.Component { } } - handleClick() { + handleClick = () => { this.props.viewAllComments(); this.props.data.refetch(); } From 48795b29bf600810a7d3cca01fe982c16c877862 Mon Sep 17 00:00:00 2001 From: gaba Date: Wed, 12 Apr 2017 10:40:15 -0700 Subject: [PATCH 18/22] Removes isAdmin for refetching when changing tabs. --- client/coral-embed-stream/src/Embed.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/coral-embed-stream/src/Embed.js b/client/coral-embed-stream/src/Embed.js index 453d645c2..342e490ea 100644 --- a/client/coral-embed-stream/src/Embed.js +++ b/client/coral-embed-stream/src/Embed.js @@ -48,10 +48,10 @@ class Embed extends React.Component { } changeTab = (tab) => { - const {isAdmin} = this.props.auth; // Everytime the comes from another tab, the Stream needs to be updated. - if (tab === 0 && isAdmin) { + if (tab === 0) { + this.props.viewAllComments(); this.props.data.refetch(); } From 92205a2c6f85c29519053cd07d398d9fec9fb5e9 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Thu, 13 Apr 2017 01:17:46 +0700 Subject: [PATCH 19/22] Fix load more buttons --- client/coral-embed-stream/src/Embed.js | 12 +++++++++--- client/coral-embed-stream/src/NewCount.js | 4 ++-- .../graphql/queries/streamQuery.graphql | 3 +++ graph/resolvers/asset.js | 7 +++++++ graph/typeDefs.graphql | 3 +++ 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/client/coral-embed-stream/src/Embed.js b/client/coral-embed-stream/src/Embed.js index d9b5c8310..a16852c00 100644 --- a/client/coral-embed-stream/src/Embed.js +++ b/client/coral-embed-stream/src/Embed.js @@ -79,10 +79,12 @@ class Embed extends Component { if(!isEqual(nextProps.data.asset, this.props.data.asset)) { loadAsset(nextProps.data.asset); - const {getCounts, updateCountCache} = this.props; + const {getCounts, updateCountCache, asset: {countCache}} = this.props; const {asset} = nextProps.data; - updateCountCache(asset.id, asset.commentCount); + if (!countCache) { + updateCountCache(asset.id, asset.commentCount); + } this.setState({ countPoll: setInterval(() => { @@ -127,6 +129,10 @@ class Embed extends Component { const banned = user && user.status === 'BANNED'; + const hasOlderComments = + asset && asset.lastComment && + asset.lastComment.id !== asset.comments[asset.comments.length - 1].id; + const expandForLogin = showSignInDialog ? { minHeight: document.body.scrollHeight + 200 } : {}; @@ -259,7 +265,7 @@ class Embed extends Component { topLevel={true} assetId={asset.id} comments={asset.comments} - moreComments={countCache[asset.id] > asset.comments.length} + moreComments={hasOlderComments} loadMore={this.props.loadMore} />
} diff --git a/client/coral-embed-stream/src/NewCount.js b/client/coral-embed-stream/src/NewCount.js index 2368c1ab8..8d7333aab 100644 --- a/client/coral-embed-stream/src/NewCount.js +++ b/client/coral-embed-stream/src/NewCount.js @@ -17,10 +17,10 @@ const onLoadMoreClick = ({loadMore, commentCount, firstCommentDate, assetId, upd const NewCount = (props) => { const newComments = props.commentCount - props.countCache; - return
+ return
{ props.countCache && newComments > 0 ? -