Commit 6b4bab02 authored by picklesrus's avatar picklesrus

Move logic about whether session is fetched into selectors

parent 17307cac
const {selectUserId, selectIsAdmin, selectIsSocial, const {selectUserId, selectIsAdmin, selectIsSocial,
selectIsLoggedIn, selectUsername, selectIsMuted} = require('./session'); selectIsLoggedIn, selectUsername, selectIsMuted,
selectHasFetchedSession, selectStudioCommentsGloballyEnabled} = require('./session');
// Fine-grain selector helpers - not exported, use the higher level selectors below // Fine-grain selector helpers - not exported, use the higher level selectors below
const isCreator = state => selectUserId(state) === state.studio.owner; const isCreator = state => selectUserId(state) === state.studio.owner;
...@@ -71,7 +72,9 @@ const selectShowProjectMuteError = state => selectIsMuted(state) && ...@@ -71,7 +72,9 @@ const selectShowProjectMuteError = state => selectIsMuted(state) &&
isCurator(state) || isCurator(state) ||
(selectIsSocial(state) && state.studio.openToAll)); (selectIsSocial(state) && state.studio.openToAll));
const selectShowCuratorMuteError = state => selectIsMuted(state) && (isManager(state) || selectIsAdmin(state)); const selectShowCuratorMuteError = state => selectIsMuted(state) && (isManager(state) || selectIsAdmin(state));
const selectShowCommentsGloballyOffError = state =>
selectHasFetchedSession(state) && !selectStudioCommentsGloballyEnabled(state);
const selectShowCommentsList = state => selectHasFetchedSession && selectStudioCommentsGloballyEnabled(state);
export { export {
selectCanEditInfo, selectCanEditInfo,
selectCanAddProjects, selectCanAddProjects,
...@@ -89,6 +92,8 @@ export { ...@@ -89,6 +92,8 @@ export {
selectCanRemoveManager, selectCanRemoveManager,
selectCanPromoteCurators, selectCanPromoteCurators,
selectCanRemoveProject, selectCanRemoveProject,
selectShowCommentsList,
selectShowCommentsGloballyOffError,
selectShowEditMuteError, selectShowEditMuteError,
selectShowProjectMuteError, selectShowProjectMuteError,
selectShowCuratorMuteError selectShowCuratorMuteError
......
...@@ -10,14 +10,16 @@ import TopLevelComment from '../preview/comment/top-level-comment.jsx'; ...@@ -10,14 +10,16 @@ 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 StudioCommentsNotAllowed from './studio-comments-not-allowed.jsx'; import StudioCommentsNotAllowed from './studio-comments-not-allowed.jsx';
import {selectIsAdmin, selectHasFetchedSession, selectStudioCommentsGloballyEnabled} from '../../redux/session'; import {selectIsAdmin, selectHasFetchedSession} from '../../redux/session';
import { import {
selectShowCommentComposer, selectShowCommentComposer,
selectCanDeleteComment, selectCanDeleteComment,
selectCanDeleteCommentWithoutConfirm, selectCanDeleteCommentWithoutConfirm,
selectCanReportComment, selectCanReportComment,
selectCanRestoreComment, selectCanRestoreComment,
selectCanEditCommentsAllowed selectCanEditCommentsAllowed,
selectShowCommentsList,
selectShowCommentsGloballyOffError
} from '../../redux/studio-permissions'; } from '../../redux/studio-permissions';
import {selectStudioCommentsAllowed} from '../../redux/studio.js'; import {selectStudioCommentsAllowed} from '../../redux/studio.js';
...@@ -32,7 +34,8 @@ const StudioComments = ({ ...@@ -32,7 +34,8 @@ const StudioComments = ({
replies, replies,
postURI, postURI,
shouldShowCommentComposer, shouldShowCommentComposer,
studioCommentsGloballyEnabled, shouldShowCommentsList,
shouldShowCommentsGloballyOffError,
canDeleteComment, canDeleteComment,
canDeleteCommentWithoutConfirm, canDeleteCommentWithoutConfirm,
canEditCommentsAllowed, canEditCommentsAllowed,
...@@ -75,7 +78,20 @@ const StudioComments = ({ ...@@ -75,7 +78,20 @@ const StudioComments = ({
<h2><FormattedMessage id="studio.commentsHeader" /></h2> <h2><FormattedMessage id="studio.commentsHeader" /></h2>
{canEditCommentsAllowed && <StudioCommentsAllowed />} {canEditCommentsAllowed && <StudioCommentsAllowed />}
</div> </div>
{!hasFetchedSession || studioCommentsGloballyEnabled ? {shouldShowCommentsGloballyOffError &&
<div>
<CommentingStatus>
<p>
<FormattedMessage id="studio.comments.turnedOffGlobally" />
</p>
</CommentingStatus>
<img
className="studio-comment-placholder-img"
src="/images/comments/comment-placeholder.png"
/>
</div>
}
{shouldShowCommentsList &&
<div> <div>
{shouldShowCommentComposer ? {shouldShowCommentComposer ?
(commentsAllowed ? (commentsAllowed ?
...@@ -123,17 +139,6 @@ const StudioComments = ({ ...@@ -123,17 +139,6 @@ const StudioComments = ({
<FormattedMessage id="general.loadMore" /> <FormattedMessage id="general.loadMore" />
</Button> </Button>
} }
</div> :
<div>
<CommentingStatus>
<p>
<FormattedMessage id="studio.comments.turnedOffGlobally" />
</p>
</CommentingStatus>
<img
className="studio-comment-placholder-img"
src="/images/comments/comment-placeholder.png"
/>
</div> </div>
} }
</div> </div>
...@@ -150,7 +155,8 @@ StudioComments.propTypes = { ...@@ -150,7 +155,8 @@ StudioComments.propTypes = {
moreCommentsToLoad: PropTypes.bool, moreCommentsToLoad: PropTypes.bool,
replies: PropTypes.shape({}), replies: PropTypes.shape({}),
shouldShowCommentComposer: PropTypes.bool, shouldShowCommentComposer: PropTypes.bool,
studioCommentsGloballyEnabled: PropTypes.bool, shouldShowCommentsGloballyOffError: PropTypes.bool,
shouldShowCommentsList: PropTypes.bool,
canDeleteComment: PropTypes.bool, canDeleteComment: PropTypes.bool,
canDeleteCommentWithoutConfirm: PropTypes.bool, canDeleteCommentWithoutConfirm: PropTypes.bool,
canEditCommentsAllowed: PropTypes.bool, canEditCommentsAllowed: PropTypes.bool,
...@@ -177,7 +183,8 @@ export default connect( ...@@ -177,7 +183,8 @@ export default connect(
replies: state.comments.replies, replies: state.comments.replies,
commentsAllowed: selectStudioCommentsAllowed(state), commentsAllowed: selectStudioCommentsAllowed(state),
shouldShowCommentComposer: selectShowCommentComposer(state), shouldShowCommentComposer: selectShowCommentComposer(state),
studioCommentsGloballyEnabled: selectStudioCommentsGloballyEnabled(state), shouldShowCommentsGloballyOffError: selectShowCommentsGloballyOffError(state),
shouldShowCommentsList: selectShowCommentsList(state),
canDeleteComment: selectCanDeleteComment(state), canDeleteComment: selectCanDeleteComment(state),
canDeleteCommentWithoutConfirm: selectCanDeleteCommentWithoutConfirm(state), canDeleteCommentWithoutConfirm: selectCanDeleteCommentWithoutConfirm(state),
canEditCommentsAllowed: selectCanEditCommentsAllowed(state), canEditCommentsAllowed: selectCanEditCommentsAllowed(state),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment