Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions dotcom-rendering/src/components/Discussion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ export const Discussion = ({
signal: controller.signal,
})
.then((result) => {
if (result.kind === 'error') {
if (!result.ok) {
if (result.error !== 'AbortedSignal') {
console.error(`getDiscussion - error: ${result.error}`);
}
Expand Down Expand Up @@ -440,7 +440,7 @@ export const Discussion = ({
remapToValidFilters(filters, hashCommentId),
)
.then((context) => {
if (context.kind === 'ok') {
if (context.ok) {
dispatch({
type: 'updateCommentPage',
commentPage: context.value.page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export const AbuseReportForm = ({
commentId,
})
.then((response) => {
if (response.kind === 'error') {
if (!response.ok) {
// Fallback to errors returned from the API
setErrors({ ...errors, response: response.error });
} else {
Expand Down
23 changes: 12 additions & 11 deletions dotcom-rendering/src/components/Discussion/Comment.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
ReplyType,
Staff,
} from '../../lib/discussion';
import { ok } from '../../lib/result';
import { error, ok, type Result } from '../../lib/result';
import { Comment } from './Comment';

type Props = Parameters<typeof Comment>[0];
Expand Down Expand Up @@ -113,10 +113,11 @@ const longBothReplyCommentData: ReplyType = {
},
};

const commentResponseError = {
kind: 'error',
error: 'NetworkError',
} as const;
const commentResponseError = function <A>(): Promise<
Result<'NetworkError', A>
> {
return Promise.resolve(error('NetworkError'));
};

const user: Reader = {
kind: 'Reader',
Expand All @@ -134,8 +135,8 @@ const user: Reader = {
hasCommented: true,
},
},
onComment: () => Promise.resolve(commentResponseError),
onReply: () => Promise.resolve(commentResponseError),
onComment: commentResponseError,
onReply: commentResponseError,
onRecommend: () => Promise.resolve(true),
addUsername: () => Promise.resolve(ok(true)),
reportAbuse: () => Promise.resolve(ok(true)),
Expand All @@ -157,12 +158,12 @@ const staffUser: Staff = {
hasCommented: true,
},
},
onComment: () => Promise.resolve(commentResponseError),
onReply: () => Promise.resolve(commentResponseError),
onComment: commentResponseError,
onReply: commentResponseError,
onRecommend: () => Promise.resolve(true),
addUsername: () => Promise.resolve(ok(true)),
onPick: () => Promise.resolve(commentResponseError),
onUnpick: () => Promise.resolve(commentResponseError),
onPick: commentResponseError,
onUnpick: commentResponseError,
reportAbuse: () => Promise.resolve(ok(true)),
};

Expand Down
4 changes: 2 additions & 2 deletions dotcom-rendering/src/components/Discussion/Comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ export const Comment = ({
const pick = async (staffUser: Staff) => {
setPickError('');
const response = await staffUser.onPick(comment.id);
if (response.kind === 'error') {
if (!response.ok) {
setPickError(response.error);
} else {
setIsHighlighted(response.value);
Expand All @@ -352,7 +352,7 @@ export const Comment = ({
const unPick = async (staffUser: Staff) => {
setPickError('');
const response = await staffUser.onUnpick(comment.id);
if (response.kind === 'error') {
if (!response.ok) {
setPickError(response.error);
} else {
setIsHighlighted(response.value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { splitTheme } from '../../../.storybook/decorators/splitThemeDecorator';
import { ArticleDesign, ArticleDisplay, Pillar } from '../../lib/articleFormat';
import type { CommentType, Reader, ReplyType } from '../../lib/discussion';
import { ok } from '../../lib/result';
import { error, ok, type Result } from '../../lib/result';
import { CommentContainer } from './CommentContainer';

export default { title: 'Discussion/CommentContainer' };
Expand Down Expand Up @@ -134,10 +134,11 @@ const commentDataWithLongThread: CommentType = {
},
};

const commentResponseError = {
kind: 'error',
error: 'NetworkError',
} as const;
const commentResponseError = function <A>(): Promise<
Result<'NetworkError', A>
> {
return Promise.resolve(error('NetworkError'));
};

const aUser: Reader = {
kind: 'Reader',
Expand All @@ -155,8 +156,8 @@ const aUser: Reader = {
hasCommented: true,
},
},
onComment: () => Promise.resolve(commentResponseError),
onReply: () => Promise.resolve(commentResponseError),
onComment: commentResponseError,
onReply: commentResponseError,
onRecommend: () => Promise.resolve(true),
addUsername: () => Promise.resolve(ok(true)),
reportAbuse: () => Promise.resolve(ok(true)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const CommentContainer = ({
setLoading(true);
getAllReplies(commentId)
.then((result) => {
if (result.kind === 'error') {
if (!result.ok) {
console.error(result.error);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState } from 'react';
import { splitTheme } from '../../../.storybook/decorators/splitThemeDecorator';
import { ArticleDesign, ArticleDisplay, Pillar } from '../../lib/articleFormat';
import type { CommentType, Reader } from '../../lib/discussion';
import { ok } from '../../lib/result';
import { error, ok, type Result } from '../../lib/result';
import { CommentForm } from './CommentForm';

export default { component: CommentForm, title: 'Discussion/CommentForm' };
Expand All @@ -15,10 +15,11 @@ const defaultFormat = {
theme: Pillar.News,
};

const commentResponseError = {
kind: 'error',
error: 'NetworkError',
} as const;
const commentResponseError = function <A>(): Promise<
Result<'NetworkError', A>
> {
return Promise.resolve(error('NetworkError'));
};

const aUser: Reader = {
kind: 'Reader',
Expand All @@ -36,8 +37,8 @@ const aUser: Reader = {
hasCommented: true,
},
},
onComment: () => Promise.resolve(commentResponseError),
onReply: () => Promise.resolve(commentResponseError),
onComment: commentResponseError,
onReply: commentResponseError,
onRecommend: () => Promise.resolve(true),
addUsername: () => Promise.resolve(ok(true)),
reportAbuse: () => Promise.resolve(ok(true)),
Expand Down
6 changes: 3 additions & 3 deletions dotcom-rendering/src/components/Discussion/CommentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ export const CommentForm = ({
const preview = onPreview ?? defaultPreview;
const response = await preview(body);

if (response.kind === 'error') {
if (!response.ok) {
// If the preview fails, we handle the error and reset the preview body
handleError(response.error, false);
setPreviewBody('');
Expand Down Expand Up @@ -416,7 +416,7 @@ export const CommentForm = ({
? await user.onReply(shortUrl, body, commentBeingRepliedTo.id)
: await user.onComment(shortUrl, body);
// Check response message for error states
if (response.kind === 'error') {
if (!response.ok) {
handleError(response.error);
} else {
onAddComment(
Expand Down Expand Up @@ -447,7 +447,7 @@ export const CommentForm = ({
}

const response = await user.addUsername(userName);
if (response.kind === 'ok') {
if (response.ok) {
// If we are able to submit userName we should continue with submitting comment
void submitForm();
setUserNameMissing(false);
Expand Down
15 changes: 8 additions & 7 deletions dotcom-rendering/src/components/Discussion/Comments.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
Reader,
} from '../../lib/discussion';
import { discussionApiResponseSchema } from '../../lib/discussion';
import { ok } from '../../lib/result';
import { error, ok, type Result } from '../../lib/result';
import { Comments } from './Comments';

const meta = {
Expand Down Expand Up @@ -44,10 +44,11 @@ const discussionWithTwoComments = parse(
);
if (discussionWithTwoComments.status !== 'ok') throw new Error('Invalid mock');

const commentResponseError = {
kind: 'error',
error: 'NetworkError',
} as const;
const commentResponseError = function <A>(): Promise<
Result<'NetworkError', A>
> {
return Promise.resolve(error('NetworkError'));
};

const aUser: Reader = {
kind: 'Reader',
Expand All @@ -65,8 +66,8 @@ const aUser: Reader = {
hasCommented: true,
},
},
onComment: () => Promise.resolve(commentResponseError),
onReply: () => Promise.resolve(commentResponseError),
onComment: commentResponseError,
onReply: commentResponseError,
onRecommend: () => Promise.resolve(true),
addUsername: () => Promise.resolve(ok(true)),
reportAbuse: () => Promise.resolve(ok(true)),
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/src/components/Discussion/Comments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export const Comments = ({

useEffect(() => {
void getPicks(shortUrl).then((result) => {
if (result.kind === 'error') {
if (!result.ok) {
console.error(result.error);
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { splitTheme } from '../../../.storybook/decorators/splitThemeDecorator';
import { ArticleDesign, ArticleDisplay, Pillar } from '../../lib/articleFormat';
import type { SignedInUser } from '../../lib/discussion';
import { ok } from '../../lib/result';
import { error, ok, type Result } from '../../lib/result';
import { palette as themePalette } from '../../palette';
import { RecommendationCount } from './RecommendationCount';

export default { title: 'Discussion/RecommendationCount' };

const commentResponseError = {
kind: 'error',
error: 'NetworkError',
} as const;
const commentResponseError = function <A>(): Promise<
Result<'NetworkError', A>
> {
return Promise.resolve(error('NetworkError'));
};

const aUser = {
kind: 'Reader',
Expand All @@ -28,8 +29,8 @@ const aUser = {
hasCommented: true,
},
},
onComment: () => Promise.resolve(commentResponseError),
onReply: () => Promise.resolve(commentResponseError),
onComment: commentResponseError,
onReply: commentResponseError,
onRecommend: () => Promise.resolve(true),
addUsername: () => Promise.resolve(ok(true)),
reportAbuse: () => Promise.resolve(ok(true)),
Expand Down
15 changes: 8 additions & 7 deletions dotcom-rendering/src/components/Discussion/TopPick.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { css } from '@emotion/react';
import { splitTheme } from '../../../.storybook/decorators/splitThemeDecorator';
import { ArticleDesign, ArticleDisplay, Pillar } from '../../lib/articleFormat';
import type { ReplyType, SignedInUser } from '../../lib/discussion';
import { ok } from '../../lib/result';
import { error, ok, type Result } from '../../lib/result';
import { TopPick } from './TopPick';

export default { component: TopPick, title: 'Discussion/TopPick' };
Expand Down Expand Up @@ -78,10 +78,11 @@ const contributorCommentWithShortBody: ReplyType = {
body: "<p>It's still there FrankDeFord - and thanks, I will pass that on</p>",
};

const commentResponseError = {
kind: 'error',
error: 'NetworkError',
} as const;
const commentResponseError = function <A>(): Promise<
Result<'NetworkError', A>
> {
return Promise.resolve(error('NetworkError'));
};

const aUser = {
kind: 'Reader',
Expand All @@ -99,8 +100,8 @@ const aUser = {
hasCommented: true,
},
},
onComment: () => Promise.resolve(commentResponseError),
onReply: () => Promise.resolve(commentResponseError),
onComment: commentResponseError,
onReply: commentResponseError,
onRecommend: () => Promise.resolve(true),
addUsername: () => Promise.resolve(ok(true)),
reportAbuse: () => Promise.resolve(ok(true)),
Expand Down
15 changes: 8 additions & 7 deletions dotcom-rendering/src/components/Discussion/TopPicks.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { splitTheme } from '../../../.storybook/decorators/splitThemeDecorator';
import { ArticleDesign, ArticleDisplay, Pillar } from '../../lib/articleFormat';
import type { ReplyType, SignedInUser } from '../../lib/discussion';
import { ok } from '../../lib/result';
import { error, ok, type Result } from '../../lib/result';
import { TopPicks } from './TopPicks';

export default { component: TopPicks, title: 'Discussion/TopPicks' };
Expand Down Expand Up @@ -57,10 +57,11 @@ const commentWithShortBody: ReplyType = {
body: "<p>It's still there FrankDeFord - and thanks, I will pass that on</p>",
};

const commentResponseError = {
kind: 'error',
error: 'NetworkError',
} as const;
const commentResponseError = function <A>(): Promise<
Result<'NetworkError', A>
> {
return Promise.resolve(error('NetworkError'));
};

const aUser = {
kind: 'Reader',
Expand All @@ -78,8 +79,8 @@ const aUser = {
hasCommented: true,
},
},
onComment: () => Promise.resolve(commentResponseError),
onReply: () => Promise.resolve(commentResponseError),
onComment: commentResponseError,
onReply: commentResponseError,
onRecommend: () => Promise.resolve(true),
addUsername: () => Promise.resolve(ok(true)),
reportAbuse: () => Promise.resolve(ok(true)),
Expand Down
8 changes: 4 additions & 4 deletions dotcom-rendering/src/components/DiscussionApps.importable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const onComment = async (
const result = parseCommentResponse(
JSON.parse(apiResponse.response),
);
if (result.kind === 'error') {
if (!result.ok) {
window.guardian.modules.sentry.reportError(
Error(`Failed parseCommentResponse: ${result.error}`),
'discussion',
Expand All @@ -58,7 +58,7 @@ const onReply = async (
const result = parseCommentResponse(
JSON.parse(apiResponse.response),
);
if (result.kind === 'error') {
if (!result.ok) {
window.guardian.modules.sentry.reportError(
Error(`Failed parseCommentResponse: ${result.error}`),
'discussion',
Expand All @@ -83,7 +83,7 @@ const onRecommend = async (commentId: string): Promise<boolean> => {
JSON.parse(discussionApiResponse.response),
);

return result.kind === 'ok';
return result.ok;
});
};

Expand Down Expand Up @@ -125,7 +125,7 @@ export const DiscussionApps = (props: Props) => {
JSON.parse(userProfile.response),
);

if (profileResult.kind !== 'ok') return setUser(undefined);
if (!profileResult.ok) return setUser(undefined);

setUser({
kind: 'Reader',
Expand Down
Loading
Loading