mirror of
https://github.com/wassname/talk.git
synced 2026-07-13 17:45:56 +08:00
[CORL-420] Upgrade Relay (#2346)
* chore: upgrade Relay * fix: fix errors * fix: snapshot * fix: relay prefix * fix: fragment spec error
This commit is contained in:
@@ -16,9 +16,6 @@ exports[`init local state 1`] = `
|
||||
\\"accessTokenExp\\": null,
|
||||
\\"accessTokenJTI\\": null,
|
||||
\\"loggedIn\\": false,
|
||||
\\"network\\": {
|
||||
\\"__ref\\": \\"client:root.local.network\\"
|
||||
},
|
||||
\\"defaultStreamOrderBy\\": \\"CREATED_AT_DESC\\",
|
||||
\\"authPopup\\": {
|
||||
\\"__ref\\": \\"client:root.local.authPopup\\"
|
||||
@@ -26,11 +23,6 @@ exports[`init local state 1`] = `
|
||||
\\"activeTab\\": \\"COMMENTS\\",
|
||||
\\"profileTab\\": \\"MY_COMMENTS\\"
|
||||
},
|
||||
\\"client:root.local.network\\": {
|
||||
\\"__id\\": \\"client:root.local.network\\",
|
||||
\\"__typename\\": \\"Network\\",
|
||||
\\"isOffline\\": false
|
||||
},
|
||||
\\"client:root.local.authPopup\\": {
|
||||
\\"__id\\": \\"client:root.local.authPopup\\",
|
||||
\\"__typename\\": \\"AuthPopup\\",
|
||||
|
||||
+2
-1
@@ -48,6 +48,7 @@ interface State {
|
||||
|
||||
export class EditCommentFormContainer extends Component<Props, State> {
|
||||
private expiredTimer: any;
|
||||
private intitialValues = { body: this.props.comment.body || "" };
|
||||
|
||||
public state: State = {
|
||||
initialized: false,
|
||||
@@ -129,7 +130,7 @@ export class EditCommentFormContainer extends Component<Props, State> {
|
||||
<EditCommentForm
|
||||
id={this.props.comment.id}
|
||||
onSubmit={this.handleOnSubmit}
|
||||
initialValues={{ body: this.props.comment.body || "" }}
|
||||
initialValues={this.intitialValues}
|
||||
onCancel={this.handleOnCancelOrClose}
|
||||
onClose={this.handleOnCancelOrClose}
|
||||
rteRef={this.handleRTERef}
|
||||
|
||||
+18
-5
@@ -5,10 +5,13 @@ import { Environment } from "relay-runtime";
|
||||
import {
|
||||
commitMutationPromiseNormalized,
|
||||
createMutationContainer,
|
||||
lookup,
|
||||
MutationInput,
|
||||
MutationResponsePromise,
|
||||
} from "coral-framework/lib/relay";
|
||||
|
||||
import { CoralContext } from "coral-framework/lib/bootstrap";
|
||||
import { GQLComment } from "coral-framework/schema";
|
||||
import { EditCommentMutation as MutationTypes } from "coral-stream/__generated__/EditCommentMutation.graphql";
|
||||
|
||||
export type EditCommentInput = MutationInput<MutationTypes>;
|
||||
@@ -33,7 +36,11 @@ const mutation = graphql`
|
||||
|
||||
let clientMutationId = 0;
|
||||
|
||||
function commit(environment: Environment, input: EditCommentInput) {
|
||||
function commit(
|
||||
environment: Environment,
|
||||
input: EditCommentInput,
|
||||
{ uuidGenerator }: CoralContext
|
||||
) {
|
||||
return commitMutationPromiseNormalized<MutationTypes>(environment, {
|
||||
mutation,
|
||||
variables: {
|
||||
@@ -44,10 +51,16 @@ function commit(environment: Environment, input: EditCommentInput) {
|
||||
},
|
||||
optimisticResponse: {
|
||||
editComment: {
|
||||
id: input.commentID,
|
||||
body: input.body,
|
||||
editing: {
|
||||
edited: true,
|
||||
comment: {
|
||||
id: input.commentID,
|
||||
body: input.body,
|
||||
status: lookup<GQLComment>(environment, input.commentID)!.status,
|
||||
revision: {
|
||||
id: uuidGenerator(),
|
||||
},
|
||||
editing: {
|
||||
edited: true,
|
||||
},
|
||||
},
|
||||
clientMutationId: (clientMutationId++).toString(),
|
||||
},
|
||||
|
||||
+4
-1
@@ -6,6 +6,7 @@ import {
|
||||
createMutation,
|
||||
MutationInput,
|
||||
} from "coral-framework/lib/relay";
|
||||
import { GQLCOMMENT_STATUS } from "coral-framework/schema";
|
||||
import { ApproveCommentMutation as MutationTypes } from "coral-stream/__generated__/ApproveCommentMutation.graphql";
|
||||
|
||||
let clientMutationId = 0;
|
||||
@@ -27,8 +28,10 @@ const ApproveCommentMutation = createMutation(
|
||||
optimisticResponse: {
|
||||
approveComment: {
|
||||
comment: {
|
||||
status: "APPROVED",
|
||||
id: input.commentID,
|
||||
status: GQLCOMMENT_STATUS.APPROVED,
|
||||
},
|
||||
clientMutationId: clientMutationId.toString(),
|
||||
},
|
||||
},
|
||||
variables: {
|
||||
|
||||
+4
-1
@@ -6,6 +6,7 @@ import {
|
||||
createMutation,
|
||||
MutationInput,
|
||||
} from "coral-framework/lib/relay";
|
||||
import { GQLCOMMENT_STATUS } from "coral-framework/schema";
|
||||
import { RejectCommentMutation as MutationTypes } from "coral-stream/__generated__/RejectCommentMutation.graphql";
|
||||
|
||||
let clientMutationId = 0;
|
||||
@@ -27,8 +28,10 @@ const RejectCommentMutation = createMutation(
|
||||
optimisticResponse: {
|
||||
rejectComment: {
|
||||
comment: {
|
||||
status: "REJECTED",
|
||||
id: input.commentID,
|
||||
status: GQLCOMMENT_STATUS.REJECTED,
|
||||
},
|
||||
clientMutationId: clientMutationId.toString(),
|
||||
},
|
||||
},
|
||||
variables: {
|
||||
|
||||
+5
@@ -5,10 +5,12 @@ import { Environment } from "relay-runtime";
|
||||
import {
|
||||
commitMutationPromiseNormalized,
|
||||
createMutationContainer,
|
||||
lookup,
|
||||
MutationInput,
|
||||
MutationResponsePromise,
|
||||
} from "coral-framework/lib/relay";
|
||||
|
||||
import { GQLComment } from "coral-framework/schema";
|
||||
import { CreateCommentReactionMutation as MutationTypes } from "coral-stream/__generated__/CreateCommentReactionMutation.graphql";
|
||||
|
||||
export type CreateCommentReactionInput = MutationInput<MutationTypes>;
|
||||
@@ -47,6 +49,9 @@ function commit(environment: Environment, input: CreateCommentReactionInput) {
|
||||
viewerActionPresence: {
|
||||
reaction: true,
|
||||
},
|
||||
revision: {
|
||||
id: lookup<GQLComment>(environment, input.commentID)!.revision.id,
|
||||
},
|
||||
actionCounts: {
|
||||
reaction: {
|
||||
total: currentCount + 1,
|
||||
|
||||
+5
@@ -5,10 +5,12 @@ import { Environment } from "relay-runtime";
|
||||
import {
|
||||
commitMutationPromiseNormalized,
|
||||
createMutationContainer,
|
||||
lookup,
|
||||
MutationInput,
|
||||
MutationResponsePromise,
|
||||
} from "coral-framework/lib/relay";
|
||||
|
||||
import { GQLComment } from "coral-framework/schema";
|
||||
import { RemoveCommentReactionMutation as MutationTypes } from "coral-stream/__generated__/RemoveCommentReactionMutation.graphql";
|
||||
|
||||
export type RemoveCommentReactionInput = MutationInput<MutationTypes>;
|
||||
@@ -46,6 +48,9 @@ function commit(environment: Environment, input: RemoveCommentReactionInput) {
|
||||
viewerActionPresence: {
|
||||
reaction: false,
|
||||
},
|
||||
revision: {
|
||||
id: lookup<GQLComment>(environment, input.commentID)!.revision.id,
|
||||
},
|
||||
actionCounts: {
|
||||
reaction: {
|
||||
total: currentCount - 1,
|
||||
|
||||
+30
-3
@@ -16,9 +16,10 @@ import {
|
||||
MutationInput,
|
||||
MutationResponsePromise,
|
||||
} from "coral-framework/lib/relay";
|
||||
import { GQLStory, GQLUSER_ROLE } from "coral-framework/schema";
|
||||
import { GQLComment, GQLStory, GQLUSER_ROLE } from "coral-framework/schema";
|
||||
import { CreateCommentReplyMutation as MutationTypes } from "coral-stream/__generated__/CreateCommentReplyMutation.graphql";
|
||||
|
||||
import { pick } from "lodash";
|
||||
import {
|
||||
incrementStoryCommentCounts,
|
||||
isVisible,
|
||||
@@ -108,6 +109,9 @@ graphql`
|
||||
moderation
|
||||
}
|
||||
}
|
||||
`;
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
graphql`
|
||||
fragment CreateCommentReplyMutation_viewer on User {
|
||||
role
|
||||
}
|
||||
@@ -135,6 +139,7 @@ function commit(
|
||||
input: CreateCommentReplyInput,
|
||||
{ uuidGenerator, relayEnvironment }: CoralContext
|
||||
) {
|
||||
const parentComment = lookup<GQLComment>(environment, input.parentID)!;
|
||||
const viewer = getViewer(environment)!;
|
||||
const currentDate = new Date().toISOString();
|
||||
const id = uuidGenerator();
|
||||
@@ -172,17 +177,39 @@ function commit(
|
||||
author: {
|
||||
id: viewer.id,
|
||||
username: viewer.username,
|
||||
createdAt: viewer.createdAt,
|
||||
},
|
||||
body: input.body,
|
||||
revision: {
|
||||
id: uuidGenerator(),
|
||||
},
|
||||
parent: {
|
||||
id: parentComment.id,
|
||||
author: parentComment.author
|
||||
? pick(parentComment.author, "username", "id")
|
||||
: null,
|
||||
},
|
||||
editing: {
|
||||
editableUntil: new Date(Date.now() + 10000),
|
||||
editableUntil: new Date(Date.now() + 10000).toISOString(),
|
||||
edited: false,
|
||||
},
|
||||
actionCounts: {
|
||||
reaction: {
|
||||
total: 0,
|
||||
},
|
||||
},
|
||||
tags: [],
|
||||
tags: roleIsAtLeast(viewer.role, GQLUSER_ROLE.STAFF)
|
||||
? [{ name: "Staff" }]
|
||||
: [],
|
||||
viewerActionPresence: {
|
||||
reaction: false,
|
||||
dontAgree: false,
|
||||
flag: false,
|
||||
},
|
||||
replies: {
|
||||
edges: [],
|
||||
pageInfo: { endCursor: null, hasNextPage: false },
|
||||
},
|
||||
},
|
||||
},
|
||||
clientMutationId: (clientMutationId++).toString(),
|
||||
|
||||
+29
-9
@@ -74,15 +74,18 @@ function addCommentToStory(
|
||||
|
||||
/** These are needed to be included when querying for the stream. */
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
graphql`
|
||||
fragment CreateCommentMutation_viewer on User {
|
||||
role
|
||||
}
|
||||
`;
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
graphql`
|
||||
fragment CreateCommentMutation_story on Story {
|
||||
settings {
|
||||
moderation
|
||||
}
|
||||
}
|
||||
fragment CreateCommentMutation_viewer on User {
|
||||
role
|
||||
}
|
||||
`;
|
||||
/** end */
|
||||
|
||||
@@ -108,7 +111,7 @@ function commit(
|
||||
input: CreateCommentInput,
|
||||
{ uuidGenerator, relayEnvironment }: CoralContext
|
||||
) {
|
||||
const me = getViewer(environment)!;
|
||||
const viewer = getViewer(environment)!;
|
||||
const currentDate = new Date().toISOString();
|
||||
const id = uuidGenerator();
|
||||
|
||||
@@ -120,7 +123,7 @@ function commit(
|
||||
|
||||
// TODO: Generate and use schema types.
|
||||
const expectPremoderation =
|
||||
!roleIsAtLeast(me.role, GQLUSER_ROLE.STAFF) &&
|
||||
!roleIsAtLeast(viewer.role, GQLUSER_ROLE.STAFF) &&
|
||||
storySettings.moderation === "PRE";
|
||||
|
||||
return commitMutationPromiseNormalized<MutationTypes>(environment, {
|
||||
@@ -142,19 +145,36 @@ function commit(
|
||||
createdAt: currentDate,
|
||||
status: "NONE",
|
||||
author: {
|
||||
id: me.id,
|
||||
username: me.username,
|
||||
id: viewer.id,
|
||||
username: viewer.username,
|
||||
createdAt: viewer.createdAt,
|
||||
},
|
||||
revision: {
|
||||
id: uuidGenerator(),
|
||||
},
|
||||
parent: null,
|
||||
body: input.body,
|
||||
editing: {
|
||||
editableUntil: new Date(Date.now() + 10000),
|
||||
editableUntil: new Date(Date.now() + 10000).toISOString(),
|
||||
edited: false,
|
||||
},
|
||||
actionCounts: {
|
||||
reaction: {
|
||||
total: 0,
|
||||
},
|
||||
},
|
||||
tags: [],
|
||||
tags: roleIsAtLeast(viewer.role, GQLUSER_ROLE.STAFF)
|
||||
? [{ name: "Staff" }]
|
||||
: [],
|
||||
viewerActionPresence: {
|
||||
reaction: false,
|
||||
dontAgree: false,
|
||||
flag: false,
|
||||
},
|
||||
replies: {
|
||||
edges: [],
|
||||
pageInfo: { endCursor: null, hasNextPage: false },
|
||||
},
|
||||
},
|
||||
},
|
||||
clientMutationId: (clientMutationId++).toString(),
|
||||
|
||||
+27
@@ -478,6 +478,33 @@ exports[`post a reply: optimistic response 1`] = `
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
className="Comment-subBar"
|
||||
>
|
||||
<div
|
||||
className="Flex-root Flex-flex Flex-alignCenter"
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className="Icon-root Icon-sm InReplyTo-icon"
|
||||
>
|
||||
reply
|
||||
</span>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<span
|
||||
className="Typography-root Typography-timestamp Typography-colorTextPrimary InReplyTo-inReplyTo"
|
||||
>
|
||||
In reply to
|
||||
<span
|
||||
className="Typography-root Typography-heading5 Typography-colorTextPrimary InReplyTo-username"
|
||||
>
|
||||
Markus
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
className="HorizontalGutter-root HorizontalGutter-full"
|
||||
>
|
||||
|
||||
@@ -463,6 +463,33 @@ exports[`post a reply: optimistic response 1`] = `
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
className="Comment-subBar"
|
||||
>
|
||||
<div
|
||||
className="Flex-root Flex-flex Flex-alignCenter"
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className="Icon-root Icon-sm InReplyTo-icon"
|
||||
>
|
||||
reply
|
||||
</span>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<span
|
||||
className="Typography-root Typography-timestamp Typography-colorTextPrimary InReplyTo-inReplyTo"
|
||||
>
|
||||
In reply to
|
||||
<span
|
||||
className="Typography-root Typography-heading5 Typography-colorTextPrimary InReplyTo-username"
|
||||
>
|
||||
Markus
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
className="HorizontalGutter-root HorizontalGutter-full"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user