mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-27 09:35:56 -05:00
Merge pull request #6458 from LLK/hotfix/comment-reply-load-more
[Develop] Hotfix - Fix for comment reply regression
This commit is contained in:
commit
1535c64249
3 changed files with 12 additions and 5 deletions
|
@ -2,7 +2,13 @@ const keyMirror = require('keymirror');
|
||||||
const mergeWith = require('lodash.mergewith');
|
const mergeWith = require('lodash.mergewith');
|
||||||
const uniqBy = require('lodash.uniqby');
|
const uniqBy = require('lodash.uniqby');
|
||||||
|
|
||||||
const COMMENT_LIMIT = 20;
|
// Number of replies to fetch at a time.
|
||||||
|
// The way this code is currently structured, it expects
|
||||||
|
// this number to be the same for project comment reply threads
|
||||||
|
// as well as studio comment reply threads.
|
||||||
|
// These could be decoupled in the future.
|
||||||
|
const REPLY_FETCH_LIMIT = 25;
|
||||||
|
|
||||||
|
|
||||||
module.exports.Status = keyMirror({
|
module.exports.Status = keyMirror({
|
||||||
FETCHED: null,
|
FETCHED: null,
|
||||||
|
@ -108,7 +114,7 @@ module.exports.commentsReducer = (state, action) => {
|
||||||
comments: state.comments.map(comment => {
|
comments: state.comments.map(comment => {
|
||||||
if (action.replies[comment.id]) {
|
if (action.replies[comment.id]) {
|
||||||
return Object.assign({}, comment, {
|
return Object.assign({}, comment, {
|
||||||
moreRepliesToLoad: action.replies[comment.id].length === COMMENT_LIMIT
|
moreRepliesToLoad: action.replies[comment.id].length === REPLY_FETCH_LIMIT
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return comment;
|
return comment;
|
||||||
|
|
|
@ -4,6 +4,7 @@ const api = require('../lib/api');
|
||||||
const log = require('../lib/log');
|
const log = require('../lib/log');
|
||||||
|
|
||||||
const COMMENT_LIMIT = 20;
|
const COMMENT_LIMIT = 20;
|
||||||
|
const REPLY_LIMIT = 25; // Number of replies to fetch at a time
|
||||||
|
|
||||||
const {
|
const {
|
||||||
addNewComment,
|
addNewComment,
|
||||||
|
@ -28,7 +29,7 @@ const getReplies = (projectId, commentIds, offset, ownerUsername, isAdmin, token
|
||||||
api({
|
api({
|
||||||
uri: `${isAdmin ? '/admin' : `/users/${ownerUsername}`}/projects/${projectId}/comments/${parentId}/replies`,
|
uri: `${isAdmin ? '/admin' : `/users/${ownerUsername}`}/projects/${projectId}/comments/${parentId}/replies`,
|
||||||
authentication: token ? token : null,
|
authentication: token ? token : null,
|
||||||
params: {offset: offset || 0, limit: COMMENT_LIMIT}
|
params: {offset: offset || 0, limit: REPLY_LIMIT}
|
||||||
}, (err, body, res) => {
|
}, (err, body, res) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(`Error fetching comment replies: ${err}`);
|
return callback(`Error fetching comment replies: ${err}`);
|
||||||
|
|
|
@ -140,9 +140,9 @@ tap.test('setReplies', t => {
|
||||||
t.equal(state.comments[0].moreRepliesToLoad, false);
|
t.equal(state.comments[0].moreRepliesToLoad, false);
|
||||||
t.equal(state.comments[1].moreRepliesToLoad, false);
|
t.equal(state.comments[1].moreRepliesToLoad, false);
|
||||||
|
|
||||||
// Getting 20 (COMMENT_LIMIT) replies sets moreRepliesToLoad to true
|
// Getting 25 (REPLY_FETCH_LIMIT) replies sets moreRepliesToLoad to true
|
||||||
state = reducer(state, Comments.setReplies({
|
state = reducer(state, Comments.setReplies({
|
||||||
id3: (new Array(20)).map((_, i) => ({id: `id${i + 1}`}))
|
id3: (new Array(25)).map((_, i) => ({id: `id${i + 1}`}))
|
||||||
}));
|
}));
|
||||||
t.equal(state.comments[0].moreRepliesToLoad, false);
|
t.equal(state.comments[0].moreRepliesToLoad, false);
|
||||||
t.equal(state.comments[1].moreRepliesToLoad, false);
|
t.equal(state.comments[1].moreRepliesToLoad, false);
|
||||||
|
|
Loading…
Reference in a new issue