Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjust 'New feedbacks are not shown in reason popup when there are too many feedbacks' #556

Merged
merged 4 commits into from
Feb 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion components/ArticleReplyFeedbackControl/ReasonsDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useQuery } from '@apollo/react-hooks';
import { withStyles, makeStyles } from '@material-ui/core/styles';
import { Box, Tab, Tabs, CircularProgress } from '@material-ui/core';
import { ThumbUpIcon, ThumbDownIcon } from 'components/icons';
import { LoadMore } from 'components/ListPageControls';
import { useIsUserBlocked } from 'lib/isUserBlocked';
import Feedback from './Feedback';

Expand Down Expand Up @@ -46,7 +47,7 @@ export const LOAD_FEEDBACKS = gql`
) {
ListArticleReplyFeedbacks(
filter: { articleId: $articleId, replyId: $replyId, statuses: $statuses }
first: 100
first: 1000
) {
edges {
node {
Expand All @@ -71,6 +72,8 @@ function ReasonsDisplay({ articleReply, onSizeChange = () => {} }) {
const classes = useStyles();
const isUserBlocked = useIsUserBlocked();
const [tab, setTab] = useState(0);
const [isLoadMoreUpvote, setIsLoadMoreUpvote] = useState(false);
const [isLoadMoreDownvote, setIsLoadMoreDownvote] = useState(false);
const { data, loading } = useQuery(LOAD_FEEDBACKS, {
variables: {
articleId: articleReply.articleId,
Expand Down Expand Up @@ -125,6 +128,15 @@ function ReasonsDisplay({ articleReply, onSizeChange = () => {} }) {
<Box display={tab === 0 ? 'block' : 'none'} className={classes.feedbacks}>
{feedbacks
.filter(({ vote }) => vote === 'UPVOTE')
.sort((a, b) => {
if (a.comment === '') return 1;
else if (b.comment === '') return -1;
return 0;
})
.slice(
0,
isLoadMoreUpvote ? feedbacks.length : Math.min(feedbacks.length, 10)
)
.map(feedback => (
<Feedback
key={feedback.id}
Expand All @@ -133,10 +145,30 @@ function ReasonsDisplay({ articleReply, onSizeChange = () => {} }) {
feedback={feedback}
/>
))}
{feedbacks.length > 10 && !isLoadMoreUpvote && (
<LoadMore
edges={feedbacks}
loading={loading}
onMoreRequest={() => {
setIsLoadMoreUpvote(true);
}}
/>
)}
</Box>
<Box display={tab === 1 ? 'block' : 'none'} className={classes.feedbacks}>
{feedbacks
.filter(({ vote }) => vote === 'DOWNVOTE')
.sort((a, b) => {
if (a.comment === '') return 1;
else if (b.comment === '') return -1;
return 0;
})
.slice(
0,
isLoadMoreDownvote
? feedbacks.length
: Math.min(feedbacks.length, 10)
)
.map(feedback => (
<Feedback
key={feedback.id}
Expand All @@ -145,6 +177,15 @@ function ReasonsDisplay({ articleReply, onSizeChange = () => {} }) {
feedback={feedback}
/>
))}
{feedbacks.length > 10 && !isLoadMoreDownvote && (
<LoadMore
edges={feedbacks}
loading={loading}
onMoreRequest={() => {
setIsLoadMoreDownvote(true);
}}
/>
)}
</Box>
</>
);
Expand Down
Loading