+ )
}
ModerateCommentsAccepted.propTypes = {
@@ -52,4 +73,8 @@ ModerateCommentsAccepted.propTypes = {
accepted_comments: PropTypes.arrayOf(PropTypes.object)
}
-export default ModerateCommentsAccepted
+const mapStateToProps = (state) => ({
+ dispatch: state.mod_comments_accepted.dispatch,
+ accepted_comments: state.mod_comments_accepted.accepted_comments,
+});
+export default connect(mapStateToProps)(ModerateCommentsAccepted)
\ No newline at end of file
diff --git a/client-admin/src/components/conversation-admin/comment-moderation/moderate-comments-rejected.js b/client-admin/src/components/conversation-admin/comment-moderation/moderate-comments-rejected.js
index d9dd77747..5b29681a0 100644
--- a/client-admin/src/components/conversation-admin/comment-moderation/moderate-comments-rejected.js
+++ b/client-admin/src/components/conversation-admin/comment-moderation/moderate-comments-rejected.js
@@ -1,6 +1,6 @@
// Copyright (C) 2012-present, The Authors. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License, version 3, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see .
-import React from 'react'
+import React, { useEffect, useState } from 'react'
import PropTypes from 'prop-types'
import {
changeCommentStatusToAccepted,
@@ -9,47 +9,72 @@ import {
import { connect } from 'react-redux'
import Comment from './comment'
-@connect((state) => state.mod_comments_rejected)
-class ModerateCommentsRejected extends React.Component {
- onCommentAccepted(comment) {
- this.props.dispatch(changeCommentStatusToAccepted(comment))
+function ModerateCommentsRejected({ dispatch, rejected_comments = [] }) {
+ const [currentItem, setCurrentItem] = useState(0)
+ useEffect(() => {
+ function handleKeyDown(e) {
+ if (e.code === 'KeyA') {
+ onCommentAccepted(rejected_comments[currentItem])
+ }
+ if (e.code === 'KeyW') {
+ setCurrentItem(Math.max(0, currentItem - 1))
+ }
+ if (rejected_comments && e.code === 'KeyS') {
+ setCurrentItem(Math.min(rejected_comments.length - 1, currentItem + 1))
+ }
+ }
+ window.addEventListener('keydown', handleKeyDown);
+ return () => window.removeEventListener('keydown', handleKeyDown);
+ }, [currentItem, rejected_comments]);
+
+ useEffect(() => {
+ if (rejected_comments && currentItem > rejected_comments.length - 1) {
+ setCurrentItem(Math.min(rejected_comments.length - 1, currentItem))
+ }
+ }, [rejected_comments?.length ?? 0])
+
+
+ function onCommentAccepted(comment) {
+ dispatch(changeCommentStatusToAccepted(comment))
}
- toggleIsMetaHandler(comment, is_meta) {
- this.props.dispatch(changeCommentCommentIsMeta(comment, is_meta))
+ function toggleIsMetaHandler(comment, is_meta) {
+ dispatch(changeCommentCommentIsMeta(comment, is_meta))
}
- createCommentMarkup() {
- const comments = this.props.rejected_comments.map((comment, i) => {
+ function createCommentMarkup() {
+ const comments = rejected_comments.map((comment, i) => {
return (
)
})
return comments
}
- render() {
- return (
-
+ )
}
ModerateCommentsRejected.propTypes = {
dispatch: PropTypes.func,
rejected_comments: PropTypes.arrayOf(PropTypes.object)
}
-
-export default ModerateCommentsRejected
+const mapStateToProps = (state) => ({
+ dispatch: state.mod_comments_rejected.dispatch,
+ rejected_comments: state.mod_comments_rejected.rejected_comments,
+});
+export default connect(mapStateToProps)(ModerateCommentsRejected)
diff --git a/client-admin/src/components/conversation-admin/comment-moderation/moderate-comments-todo.js b/client-admin/src/components/conversation-admin/comment-moderation/moderate-comments-todo.js
index 45dc29b01..5a0073cd0 100644
--- a/client-admin/src/components/conversation-admin/comment-moderation/moderate-comments-todo.js
+++ b/client-admin/src/components/conversation-admin/comment-moderation/moderate-comments-todo.js
@@ -1,6 +1,6 @@
// Copyright (C) 2012-present, The Authors. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License, version 3, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see .
-import React from 'react'
+import React, { useEffect, useState } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import {
@@ -10,54 +10,79 @@ import {
} from '../../../actions'
import Comment from './comment'
-@connect((state) => state.mod_comments_unmoderated)
-class ModerateCommentsTodo extends React.Component {
- onCommentAccepted(comment) {
- this.props.dispatch(changeCommentStatusToAccepted(comment))
+function ModerateCommentsTodo({ dispatch, unmoderated_comments = [] }) {
+ const [currentItem, setCurrentItem] = useState(0)
+ useEffect(() => {
+ function handleKeyDown(e) {
+ if (e.code === 'KeyA') {
+ onCommentAccepted(unmoderated_comments[currentItem])
+ }
+ if (e.code === 'KeyR') {
+ onCommentRejected(unmoderated_comments[currentItem])
+ }
+ if (e.code === 'KeyW') {
+ setCurrentItem(Math.max(0, currentItem - 1))
+ }
+ if (unmoderated_comments && e.code === 'KeyS') {
+ setCurrentItem(Math.min(unmoderated_comments.slice(0, max).length - 1, currentItem + 1))
+ }
+ }
+ window.addEventListener('keydown', handleKeyDown);
+ return () => window.removeEventListener('keydown', handleKeyDown);
+ }, [currentItem, unmoderated_comments]);
+
+ const max = 100;
+
+ useEffect(() => {
+ if (unmoderated_comments && currentItem > unmoderated_comments.slice(0, max).length - 1) {
+ setCurrentItem(Math.min(unmoderated_comments.slice(0, max).length - 1, currentItem))
+ }
+ }, [unmoderated_comments?.length ?? 0])
+
+ function onCommentAccepted(comment) {
+ dispatch(changeCommentStatusToAccepted(comment))
}
- onCommentRejected(comment) {
- this.props.dispatch(changeCommentStatusToRejected(comment))
+ function onCommentRejected(comment) {
+ dispatch(changeCommentStatusToRejected(comment))
}
- toggleIsMetaHandler(comment, is_meta) {
- this.props.dispatch(changeCommentCommentIsMeta(comment, is_meta))
+ function toggleIsMetaHandler(comment, is_meta) {
+ dispatch(changeCommentCommentIsMeta(comment, is_meta))
}
- createCommentMarkup(max) {
+ function createCommentMarkup(max) {
- return this.props.unmoderated_comments.slice(0,max).map((comment, i) => {
+ return unmoderated_comments.slice(0, max).map((comment, i) => {
return (
)
})
-
+
}
- render() {
- const max = 100;
- return (
+ return (
+