Skip to content

Commit

Permalink
Merge pull request #232 from cofacts/no-user-error
Browse files Browse the repository at this point in the history
Fixes searchUserByArticleId and reply page error
  • Loading branch information
MrOrz authored Mar 7, 2020
2 parents 65d624a + 4b0a15c commit 1fc016d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 23 deletions.
2 changes: 2 additions & 0 deletions components/ReplyItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ ReplyItem.fragments = {
type
createdAt
user {
id
name
}
articleReplies(status: NORMAL) {
articleId
replyId
}
}
`,
Expand Down
4 changes: 4 additions & 0 deletions constants/errors.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
// Matches setup in rumors-api
export const AUTH_ERROR_MSG = 'userId is not set via query string.';

// Matches setup in rumors-api
export const NO_USER_FOR_ARTICLE =
'fromUserOfArticleId does not match any existing articles';
2 changes: 2 additions & 0 deletions lib/rollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
import Rollbar from 'rollbar';
import getConfig from 'next/config';
import { NO_USER_FOR_ARTICLE } from 'constants/errors';

if (typeof window !== 'undefined') {
throw new Error(
Expand All @@ -25,6 +26,7 @@ const rollbar = new Rollbar({
captureUncaught: true,
captureUnhandledRejections: true,
nodeSourceMaps: true,
ignoredMessages: [NO_USER_FOR_ARTICLE],
});

export default rollbar;
4 changes: 2 additions & 2 deletions pages/_document.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import Document, { Head, Main, NextScript } from 'next/document';
import getConfig from 'next/config';
import { ServerStyleSheets } from '@material-ui/styles';
import { AUTH_ERROR_MSG } from 'constants/errors';
import { AUTH_ERROR_MSG, NO_USER_FOR_ARTICLE } from 'constants/errors';
import theme from 'lib/theme';
import agent from 'lib/stackimpact';
import rollbar from 'lib/rollbar';
Expand Down Expand Up @@ -60,7 +60,7 @@ class MyDocument extends Document {
captureUncaught: true,
captureUnhandledRejections: true,
payload: { environment: "${PUBLIC_ROLLBAR_ENV}" },
ignoredMessages: ["${AUTH_ERROR_MSG}"],
ignoredMessages: ["${AUTH_ERROR_MSG}", "${NO_USER_FOR_ARTICLE}"],
};
${rollbarSnippet}
`,
Expand Down
25 changes: 15 additions & 10 deletions pages/articles.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ function ArticleListPage() {

const {
loading,
data: { ListArticles: articleData },
data: listArticlesData,
error: listArticlesError,
} = useQuery(LIST_ARTICLES, {
variables: {
...listQueryVars,
Expand All @@ -207,19 +208,21 @@ function ArticleListPage() {
// Separate these stats query so that it will be cached by apollo-client and sends no network request
// on page change, but still works when filter options are updated.
//
const {
loading: statsLoading,
data: { ListArticles: statsData },
} = useQuery(LIST_STAT, {
const { loading: statsLoading, data: listStatData } = useQuery(LIST_STAT, {
variables: listQueryVars,
});

// List data
const statsData = listStatData?.ListArticles || {};
const articleEdges = listArticlesData?.ListArticles?.edges || [];

// Flags
const showOneTimeMessages = +query.replyRequestCount === 1;
const searchedArticleEdge = (articleData?.edges || []).find(
const searchedArticleEdge = articleEdges.find(
({ node: { id } }) => id === query.searchUserByArticleId
);
const searchedUserArticleElem = (
<mark>
<mark key="searched-user">
{ellipsis(searchedArticleEdge?.node?.text || '', { wordCount: 15 })}
</mark>
);
Expand Down Expand Up @@ -304,15 +307,17 @@ function ArticleListPage() {

{loading ? (
'Loading....'
) : listArticlesError ? (
listArticlesError.toString()
) : (
<>
<Pagination
query={query}
pageInfo={statsData?.pageInfo}
edges={articleData?.edges}
edges={articleEdges}
/>
<ul className="article-list">
{articleData.edges.map(({ node }) => (
{articleEdges.map(({ node }) => (
<ArticleItem
key={node.id}
article={node}
Expand All @@ -323,7 +328,7 @@ function ArticleListPage() {
<Pagination
query={query}
pageInfo={statsData?.pageInfo}
edges={articleData?.edges}
edges={articleEdges}
/>
{!showOneTimeMessages && (
<Typography variant="body2" component="p">
Expand Down
19 changes: 8 additions & 11 deletions pages/replies.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,7 @@ function ReplyListPage() {
orderBy: urlQuery2OrderBy(query),
};

const {
loading,
data: { ListReplies: replyData },
} = useQuery(LIST_REPLIES, {
const { loading, data: listRepliesData } = useQuery(LIST_REPLIES, {
variables: {
...listQueryVars,
before: query.before,
Expand All @@ -185,15 +182,15 @@ function ReplyListPage() {
// Separate these stats query so that it will be cached by apollo-client and sends no network request
// on page change, but still works when filter options are updated.

const {
loading: statsLoading,
data: { ListReplies: statsData },
} = useQuery(LIST_STAT, {
const { loading: statsLoading, data: listStatData } = useQuery(LIST_STAT, {
variables: listQueryVars,
});

const currentUser = useCurrentUser();

const replyEdges = listRepliesData?.ListReplies?.edges || [];
const statsData = listStatData?.ListReplies || {};

return (
<AppLayout>
<Head>
Expand Down Expand Up @@ -261,17 +258,17 @@ function ReplyListPage() {
<Pagination
query={query}
pageInfo={statsData?.pageInfo}
edges={replyData?.edges}
edges={replyEdges}
/>
<ul className="reply-list">
{replyData.edges.map(({ node }) => (
{replyEdges.map(({ node }) => (
<ReplyItem key={node.id} reply={node} showUser={!query.mine} />
))}
</ul>
<Pagination
query={query}
pageInfo={statsData?.pageInfo}
edges={replyData?.edges}
edges={replyEdges}
/>
</>
)}
Expand Down

0 comments on commit 1fc016d

Please sign in to comment.