Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
scratch-www
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
scratch-www
Commits
2c53c703
Unverified
Commit
2c53c703
authored
May 24, 2021
by
Paul Kaplan
Committed by
GitHub
May 24, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5436 from paulkaplan/fix-admin-studio-comments
Wait for session to be fetched before loading comments
parents
e012c806
53414e11
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
3 deletions
+13
-3
src/redux/session.js
src/redux/session.js
+1
-0
src/views/studio/studio-comments.jsx
src/views/studio/studio-comments.jsx
+6
-3
test/unit/components/studio-comments.test.jsx
test/unit/components/studio-comments.test.jsx
+6
-0
No files found.
src/redux/session.js
View file @
2c53c703
...
@@ -128,6 +128,7 @@ module.exports.selectToken = state => get(state, ['session', 'session', 'user',
...
@@ -128,6 +128,7 @@ module.exports.selectToken = state => get(state, ['session', 'session', 'user',
module
.
exports
.
selectIsAdmin
=
state
=>
get
(
state
,
[
'
session
'
,
'
session
'
,
'
permissions
'
,
'
admin
'
],
false
);
module
.
exports
.
selectIsAdmin
=
state
=>
get
(
state
,
[
'
session
'
,
'
session
'
,
'
permissions
'
,
'
admin
'
],
false
);
module
.
exports
.
selectIsSocial
=
state
=>
get
(
state
,
[
'
session
'
,
'
session
'
,
'
permissions
'
,
'
social
'
],
false
);
module
.
exports
.
selectIsSocial
=
state
=>
get
(
state
,
[
'
session
'
,
'
session
'
,
'
permissions
'
,
'
social
'
],
false
);
module
.
exports
.
selectIsEducator
=
state
=>
get
(
state
,
[
'
session
'
,
'
session
'
,
'
permissions
'
,
'
educator
'
],
false
);
module
.
exports
.
selectIsEducator
=
state
=>
get
(
state
,
[
'
session
'
,
'
session
'
,
'
permissions
'
,
'
educator
'
],
false
);
module
.
exports
.
selectHasFetchedSession
=
state
=>
state
.
session
.
status
===
module
.
exports
.
Status
.
FETCHED
;
// NB logged out user id as NaN so that it can never be used in equality testing since NaN !== NaN
// NB logged out user id as NaN so that it can never be used in equality testing since NaN !== NaN
module
.
exports
.
selectUserId
=
state
=>
get
(
state
,
[
'
session
'
,
'
session
'
,
'
user
'
,
'
id
'
],
NaN
);
module
.
exports
.
selectUserId
=
state
=>
get
(
state
,
[
'
session
'
,
'
session
'
,
'
user
'
,
'
id
'
],
NaN
);
src/views/studio/studio-comments.jsx
View file @
2c53c703
...
@@ -9,7 +9,7 @@ import TopLevelComment from '../preview/comment/top-level-comment.jsx';
...
@@ -9,7 +9,7 @@ import TopLevelComment from '../preview/comment/top-level-comment.jsx';
import
studioCommentActions
from
'
../../redux/studio-comment-actions.js
'
;
import
studioCommentActions
from
'
../../redux/studio-comment-actions.js
'
;
import
StudioCommentsAllowed
from
'
./studio-comments-allowed.jsx
'
;
import
StudioCommentsAllowed
from
'
./studio-comments-allowed.jsx
'
;
import
{
selectIsAdmin
}
from
'
../../redux/session
'
;
import
{
selectIsAdmin
,
selectHasFetchedSession
}
from
'
../../redux/session
'
;
import
{
import
{
selectShowCommentComposer
,
selectShowCommentComposer
,
selectCanDeleteComment
,
selectCanDeleteComment
,
...
@@ -24,6 +24,7 @@ const StudioComments = ({
...
@@ -24,6 +24,7 @@ const StudioComments = ({
comments
,
comments
,
commentsAllowed
,
commentsAllowed
,
isAdmin
,
isAdmin
,
hasFetchedSession
,
handleLoadMoreComments
,
handleLoadMoreComments
,
handleNewComment
,
handleNewComment
,
moreCommentsToLoad
,
moreCommentsToLoad
,
...
@@ -42,8 +43,8 @@ const StudioComments = ({
...
@@ -42,8 +43,8 @@ const StudioComments = ({
handleLoadMoreReplies
handleLoadMoreReplies
})
=>
{
})
=>
{
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
comments
.
length
===
0
)
handleLoadMoreComments
();
if
(
comments
.
length
===
0
&&
hasFetchedSession
)
handleLoadMoreComments
();
},
[
comments
.
length
===
0
]);
},
[
comments
.
length
===
0
,
hasFetchedSession
]);
// The comments you see depend on your admin status
// The comments you see depend on your admin status
// so reset them if isAdmin changes.
// so reset them if isAdmin changes.
...
@@ -108,6 +109,7 @@ StudioComments.propTypes = {
...
@@ -108,6 +109,7 @@ StudioComments.propTypes = {
comments
:
PropTypes
.
arrayOf
(
PropTypes
.
shape
({})),
comments
:
PropTypes
.
arrayOf
(
PropTypes
.
shape
({})),
commentsAllowed
:
PropTypes
.
bool
,
commentsAllowed
:
PropTypes
.
bool
,
isAdmin
:
PropTypes
.
bool
,
isAdmin
:
PropTypes
.
bool
,
hasFetchedSession
:
PropTypes
.
bool
,
handleLoadMoreComments
:
PropTypes
.
func
,
handleLoadMoreComments
:
PropTypes
.
func
,
handleNewComment
:
PropTypes
.
func
,
handleNewComment
:
PropTypes
.
func
,
moreCommentsToLoad
:
PropTypes
.
bool
,
moreCommentsToLoad
:
PropTypes
.
bool
,
...
@@ -133,6 +135,7 @@ export {
...
@@ -133,6 +135,7 @@ export {
export
default
connect
(
export
default
connect
(
state
=>
({
state
=>
({
comments
:
state
.
comments
.
comments
,
comments
:
state
.
comments
.
comments
,
hasFetchedSession
:
selectHasFetchedSession
(
state
),
isAdmin
:
selectIsAdmin
(
state
),
isAdmin
:
selectIsAdmin
(
state
),
moreCommentsToLoad
:
state
.
comments
.
moreCommentsToLoad
,
moreCommentsToLoad
:
state
.
comments
.
moreCommentsToLoad
,
replies
:
state
.
comments
.
replies
,
replies
:
state
.
comments
.
replies
,
...
...
test/unit/components/studio-comments.test.jsx
View file @
2c53c703
...
@@ -7,10 +7,14 @@ describe('Studio comments', () => {
...
@@ -7,10 +7,14 @@ describe('Studio comments', () => {
const
loadComments
=
jest
.
fn
();
const
loadComments
=
jest
.
fn
();
const
component
=
mountWithIntl
(
const
component
=
mountWithIntl
(
<
StudioComments
<
StudioComments
hasFetchedSession=
{
false
}
comments=
{
[]
}
comments=
{
[]
}
handleLoadMoreComments=
{
loadComments
}
handleLoadMoreComments=
{
loadComments
}
/>
/>
);
);
expect
(
loadComments
).
not
.
toHaveBeenCalled
();
component
.
setProps
({
hasFetchedSession
:
true
});
component
.
update
();
expect
(
loadComments
).
toHaveBeenCalled
();
expect
(
loadComments
).
toHaveBeenCalled
();
// When updated to have comments, load is not called again
// When updated to have comments, load is not called again
...
@@ -30,6 +34,7 @@ describe('Studio comments', () => {
...
@@ -30,6 +34,7 @@ describe('Studio comments', () => {
const
resetComments
=
jest
.
fn
();
const
resetComments
=
jest
.
fn
();
const
component
=
mountWithIntl
(
const
component
=
mountWithIntl
(
<
StudioComments
<
StudioComments
hasFetchedSession
isAdmin=
{
false
}
isAdmin=
{
false
}
comments=
{
[{
id
:
123
,
author
:
{}}]
}
comments=
{
[{
id
:
123
,
author
:
{}}]
}
handleResetComments=
{
resetComments
}
handleResetComments=
{
resetComments
}
...
@@ -57,6 +62,7 @@ describe('Studio comments', () => {
...
@@ -57,6 +62,7 @@ describe('Studio comments', () => {
mountWithIntl
(
mountWithIntl
(
<
StudioComments
<
StudioComments
isAdmin
isAdmin
hasFetchedSession
comments=
{
[{
id
:
123
,
author
:
{}}]
}
comments=
{
[{
id
:
123
,
author
:
{}}]
}
handleResetComments=
{
resetComments
}
handleResetComments=
{
resetComments
}
/>
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment