= ({
viewer,
settings,
}) => {
+ const emitShowEditUsernameDialog = useViewerEvent(
+ ShowEditUsernameDialogEvent
+ );
const [showEditForm, setShowEditForm] = useState(false);
const [showSuccessMessage, setShowSuccessMessage] = useState(false);
const toggleEditForm = useCallback(() => {
+ if (!showEditForm) {
+ emitShowEditUsernameDialog();
+ }
setShowEditForm(!showEditForm);
}, [setShowEditForm, showEditForm]);
const updateUsername = useMutation(UpdateUsernameMutation);
diff --git a/src/core/client/stream/tabs/Profile/Settings/ChangeUsername/UpdateUsernameMutation.tsx b/src/core/client/stream/tabs/Profile/Settings/ChangeUsername/UpdateUsernameMutation.tsx
index 282e6a038..09fce39f1 100644
--- a/src/core/client/stream/tabs/Profile/Settings/ChangeUsername/UpdateUsernameMutation.tsx
+++ b/src/core/client/stream/tabs/Profile/Settings/ChangeUsername/UpdateUsernameMutation.tsx
@@ -9,58 +9,78 @@ import {
} from "coral-framework/lib/relay";
import { UpdateUsernameMutation as MutationTypes } from "coral-stream/__generated__/UpdateUsernameMutation.graphql";
+import { ChangeUsernameEvent } from "coral-stream/events";
let clientMutationId = 0;
const UpdateUsernameMutation = createMutation(
"updateUsername",
- (environment: Environment, input: MutationInput
) =>
- commitMutationPromiseNormalized(environment, {
- mutation: graphql`
- mutation UpdateUsernameMutation($input: UpdateUsernameInput!) {
- updateUsername(input: $input) {
- clientMutationId
- user {
- username
- status {
- username {
- history {
- username
- createdAt
+ async (
+ environment: Environment,
+ input: MutationInput,
+ { eventEmitter }
+ ) => {
+ const changeUsernameEvent = ChangeUsernameEvent.begin(eventEmitter, {
+ oldUsername: getViewer(environment)!.username!,
+ newUsername: input.username,
+ });
+ try {
+ const result = await commitMutationPromiseNormalized(
+ environment,
+ {
+ mutation: graphql`
+ mutation UpdateUsernameMutation($input: UpdateUsernameInput!) {
+ updateUsername(input: $input) {
+ clientMutationId
+ user {
+ username
+ status {
+ username {
+ history {
+ username
+ createdAt
+ }
+ }
}
}
}
}
- }
- }
- `,
- variables: {
- input: {
- ...input,
- clientMutationId: (clientMutationId++).toString(),
- },
- },
- optimisticResponse: {
- updateUsername: {
- clientMutationId: (clientMutationId++).toString(),
- user: {
- id: getViewer(environment)!.id,
- username: input.username,
- status: {
- username: {
- // FIXME: (tessalt) merge in existing history
- history: [
- {
- username: input.username,
- createdAt: Date.now(),
+ `,
+ variables: {
+ input: {
+ ...input,
+ clientMutationId: (clientMutationId++).toString(),
+ },
+ },
+ optimisticResponse: {
+ updateUsername: {
+ clientMutationId: (clientMutationId++).toString(),
+ user: {
+ id: getViewer(environment)!.id,
+ username: input.username,
+ status: {
+ username: {
+ // FIXME: (tessalt) merge in existing history
+ history: [
+ {
+ username: input.username,
+ createdAt: Date.now(),
+ },
+ ],
},
- ],
+ },
},
},
},
- },
- },
- })
+ }
+ );
+ changeUsernameEvent.success();
+ return result;
+ } catch (error) {
+ changeUsernameEvent.error({ message: error.message, code: error.code });
+ throw error;
+ }
+ }
);
export default UpdateUsernameMutation;
diff --git a/src/core/client/stream/tabs/Profile/Settings/DeleteAccount/Pages/RequestAccountDeletionMutation.tsx b/src/core/client/stream/tabs/Profile/Settings/DeleteAccount/Pages/RequestAccountDeletionMutation.tsx
index 21b37d4e1..9f8873f3c 100644
--- a/src/core/client/stream/tabs/Profile/Settings/DeleteAccount/Pages/RequestAccountDeletionMutation.tsx
+++ b/src/core/client/stream/tabs/Profile/Settings/DeleteAccount/Pages/RequestAccountDeletionMutation.tsx
@@ -9,6 +9,7 @@ import {
createMutation,
MutationInput,
} from "coral-framework/lib/relay";
+import { RequestAccountDeletionEvent } from "coral-stream/events";
import { RequestAccountDeletionMutation as MutationTypes } from "coral-stream/__generated__/RequestAccountDeletionMutation.graphql";
@@ -16,39 +17,58 @@ let clientMutationId = 0;
const RequestAccountDeletionMutation = createMutation(
"requestAccountDeletion",
- (environment: Environment, input: MutationInput) =>
- commitMutationPromiseNormalized(environment, {
- mutation: graphql`
- mutation RequestAccountDeletionMutation(
- $input: RequestAccountDeletionInput!
- ) {
- requestAccountDeletion(input: $input) {
- user {
- scheduledDeletionDate
+ async (
+ environment: Environment,
+ input: MutationInput,
+ { eventEmitter }
+ ) => {
+ const requestAccountDeletionEvent = RequestAccountDeletionEvent.begin(
+ eventEmitter
+ );
+ try {
+ const result = await commitMutationPromiseNormalized(
+ environment,
+ {
+ mutation: graphql`
+ mutation RequestAccountDeletionMutation(
+ $input: RequestAccountDeletionInput!
+ ) {
+ requestAccountDeletion(input: $input) {
+ user {
+ scheduledDeletionDate
+ }
+ clientMutationId
+ }
}
- clientMutationId
- }
+ `,
+ variables: {
+ input: {
+ ...input,
+ clientMutationId: (clientMutationId++).toString(),
+ },
+ },
+ optimisticUpdater: store => {
+ const viewer = getViewer(environment)!;
+ const deletionDate = DateTime.fromJSDate(new Date())
+ .plus({ days: SCHEDULED_DELETION_TIMESPAN_DAYS })
+ .toISO();
+ const viewerProxy = store.get(viewer.id);
+ if (viewerProxy !== null) {
+ viewerProxy.setValue(deletionDate, "scheduledDeletionDate");
+ }
+ },
}
- `,
- variables: {
- input: {
- ...input,
- clientMutationId: (clientMutationId++).toString(),
- },
- },
- optimisticUpdater: store => {
- const viewer = getViewer(environment)!;
-
- const deletionDate = DateTime.fromJSDate(new Date())
- .plus({ days: SCHEDULED_DELETION_TIMESPAN_DAYS })
- .toISO();
-
- const viewerProxy = store.get(viewer.id);
- if (viewerProxy !== null) {
- viewerProxy.setValue(deletionDate, "scheduledDeletionDate");
- }
- },
- })
+ );
+ requestAccountDeletionEvent.success();
+ return result;
+ } catch (error) {
+ requestAccountDeletionEvent.error({
+ message: error.message,
+ code: error.code,
+ });
+ throw error;
+ }
+ }
);
export default RequestAccountDeletionMutation;
diff --git a/src/core/client/stream/tabs/Profile/Settings/IgnoreUserSettingsContainer.tsx b/src/core/client/stream/tabs/Profile/Settings/IgnoreUserSettingsContainer.tsx
index b89b04256..5b6778750 100644
--- a/src/core/client/stream/tabs/Profile/Settings/IgnoreUserSettingsContainer.tsx
+++ b/src/core/client/stream/tabs/Profile/Settings/IgnoreUserSettingsContainer.tsx
@@ -2,8 +2,10 @@ import { Localized } from "fluent-react/compat";
import React, { FunctionComponent, useCallback, useState } from "react";
import { graphql } from "react-relay";
+import { useViewerEvent } from "coral-framework/lib/events";
import { useMutation, withFragmentContainer } from "coral-framework/lib/relay";
import CLASSES from "coral-stream/classes";
+import { ShowIgnoreUserdDialogEvent } from "coral-stream/events";
import {
Button,
Flex,
@@ -24,12 +26,15 @@ interface Props {
}
const IgnoreUserSettingsContainer: FunctionComponent = ({ viewer }) => {
+ const emitShow = useViewerEvent(ShowIgnoreUserdDialogEvent);
const removeUserIgnore = useMutation(RemoveUserIgnoreMutation);
const [showManage, setShowManage] = useState(false);
- const toggleManage = useCallback(() => setShowManage(!showManage), [
- showManage,
- setShowManage,
- ]);
+ const toggleManage = useCallback(() => {
+ if (!showManage) {
+ emitShow();
+ }
+ setShowManage(!showManage);
+ }, [showManage, setShowManage]);
return (
) =>
- commitMutationPromiseNormalized
(environment, {
- mutation: graphql`
- mutation RemoveUserIgnoreMutation($input: RemoveUserIgnoreInput!) {
- removeUserIgnore(input: $input) {
- clientMutationId
- }
+ async (
+ environment: Environment,
+ input: MutationInput,
+ { eventEmitter }: CoralContext
+ ) => {
+ const removeUserIgnore = RemoveUserIgnoreEvent.begin(eventEmitter, {
+ userID: input.userID,
+ });
+ try {
+ const result = await commitMutationPromiseNormalized(
+ environment,
+ {
+ mutation: graphql`
+ mutation RemoveUserIgnoreMutation($input: RemoveUserIgnoreInput!) {
+ removeUserIgnore(input: $input) {
+ clientMutationId
+ }
+ }
+ `,
+ variables: {
+ input: {
+ ...input,
+ clientMutationId: (clientMutationId++).toString(),
+ },
+ },
+ updater: store => {
+ const viewer = getViewer(environment)!;
+ const viewerProxy = store.get(viewer.id)!;
+ const removeIgnoredUserRecords = viewerProxy.getLinkedRecords(
+ "ignoredUsers"
+ );
+ if (removeIgnoredUserRecords) {
+ viewerProxy.setLinkedRecords(
+ removeIgnoredUserRecords.filter(
+ r => r!.getValue("id") !== input.userID
+ ),
+ "ignoredUsers"
+ );
+ }
+ },
}
- `,
- variables: {
- input: {
- ...input,
- clientMutationId: (clientMutationId++).toString(),
- },
- },
- updater: store => {
- const viewer = getViewer(environment)!;
- const viewerProxy = store.get(viewer.id)!;
- const removeIgnoredUserRecords = viewerProxy.getLinkedRecords(
- "ignoredUsers"
- );
- if (removeIgnoredUserRecords) {
- viewerProxy.setLinkedRecords(
- removeIgnoredUserRecords.filter(
- r => r!.getValue("id") !== input.userID
- ),
- "ignoredUsers"
- );
- }
- },
- })
+ );
+ removeUserIgnore.success();
+ return result;
+ } catch (error) {
+ removeUserIgnore.error({ message: error.message, code: error.code });
+ throw error;
+ }
+ }
);
export default RemoveUserIgnoreMutation;
diff --git a/src/core/client/stream/tabs/Profile/Settings/RequestCommentsDownloadMutation.ts b/src/core/client/stream/tabs/Profile/Settings/RequestCommentsDownloadMutation.ts
index fc1fc6771..4c2da42e1 100644
--- a/src/core/client/stream/tabs/Profile/Settings/RequestCommentsDownloadMutation.ts
+++ b/src/core/client/stream/tabs/Profile/Settings/RequestCommentsDownloadMutation.ts
@@ -7,6 +7,7 @@ import {
createMutation,
MutationInput,
} from "coral-framework/lib/relay";
+import { RequestDownloadCommentHistoryEvent } from "coral-stream/events";
import { RequestCommentsDownloadMutation as MutationTypes } from "coral-stream/__generated__/RequestCommentsDownloadMutation.graphql";
@@ -14,7 +15,11 @@ let clientMutationId = 0;
const RequestCommentsDownloadMutation = createMutation(
"requestCommentsDownload",
- (environment: Environment, input: MutationInput) => {
+ async (
+ environment: Environment,
+ input: MutationInput,
+ { eventEmitter }
+ ) => {
const updater = (store: RecordSourceSelectorProxy) => {
const viewer = getViewer(environment)!;
const user = store.get(viewer.id);
@@ -24,26 +29,41 @@ const RequestCommentsDownloadMutation = createMutation(
user.setValue(now.toISOString(), "lastDownloadedAt");
}
};
-
- return commitMutationPromiseNormalized(environment, {
- mutation: graphql`
- mutation RequestCommentsDownloadMutation(
- $input: RequestCommentsDownloadInput!
- ) {
- requestCommentsDownload(input: $input) {
- clientMutationId
- }
+ const requestDownloadCommentHistoryEvent = RequestDownloadCommentHistoryEvent.begin(
+ eventEmitter
+ );
+ try {
+ const result = await commitMutationPromiseNormalized(
+ environment,
+ {
+ mutation: graphql`
+ mutation RequestCommentsDownloadMutation(
+ $input: RequestCommentsDownloadInput!
+ ) {
+ requestCommentsDownload(input: $input) {
+ clientMutationId
+ }
+ }
+ `,
+ variables: {
+ input: {
+ ...input,
+ clientMutationId: (clientMutationId++).toString(),
+ },
+ },
+ optimisticUpdater: updater,
+ updater,
}
- `,
- variables: {
- input: {
- ...input,
- clientMutationId: (clientMutationId++).toString(),
- },
- },
- optimisticUpdater: updater,
- updater,
- });
+ );
+ requestDownloadCommentHistoryEvent.success();
+ return result;
+ } catch (error) {
+ requestDownloadCommentHistoryEvent.error({
+ message: error.message,
+ code: error.code,
+ });
+ throw error;
+ }
}
);
diff --git a/src/core/client/stream/tabs/Profile/Settings/UpdateNotificationSettingsMutation.ts b/src/core/client/stream/tabs/Profile/Settings/UpdateNotificationSettingsMutation.ts
index afca329dd..25a23e925 100644
--- a/src/core/client/stream/tabs/Profile/Settings/UpdateNotificationSettingsMutation.ts
+++ b/src/core/client/stream/tabs/Profile/Settings/UpdateNotificationSettingsMutation.ts
@@ -1,11 +1,13 @@
import { graphql } from "react-relay";
import { Environment } from "relay-runtime";
+import { CoralContext } from "coral-framework/lib/bootstrap";
import {
commitMutationPromiseNormalized,
createMutation,
MutationInput,
} from "coral-framework/lib/relay";
+import { UpdateNotificationSettingsEvent } from "coral-stream/events";
import { UpdateNotificationSettingsMutation as MutationTypes } from "coral-stream/__generated__/UpdateNotificationSettingsMutation.graphql";
@@ -13,34 +15,62 @@ let clientMutationId = 0;
const UpdateNotificationSettingsMutation = createMutation(
"updateNotificationSettings",
- (environment: Environment, input: MutationInput) =>
- commitMutationPromiseNormalized(environment, {
- mutation: graphql`
- mutation UpdateNotificationSettingsMutation(
- $input: UpdateNotificationSettingsInput!
- ) {
- updateNotificationSettings(input: $input) {
- user {
- id
- notifications {
- onReply
- onFeatured
- onStaffReplies
- onModeration
- digestFrequency
+ async (
+ environment: Environment,
+ input: MutationInput,
+ { eventEmitter }: CoralContext
+ ) => {
+ const updateNofitificationSettings = UpdateNotificationSettingsEvent.begin(
+ eventEmitter,
+ {
+ digestFrequency: input.digestFrequency,
+ onFeatured: input.onFeatured,
+ onModeration: input.onModeration,
+ onStaffReplies: input.onStaffReplies,
+ onReply: input.onReply,
+ }
+ );
+ try {
+ const result = await commitMutationPromiseNormalized(
+ environment,
+ {
+ mutation: graphql`
+ mutation UpdateNotificationSettingsMutation(
+ $input: UpdateNotificationSettingsInput!
+ ) {
+ updateNotificationSettings(input: $input) {
+ user {
+ id
+ notifications {
+ onReply
+ onFeatured
+ onStaffReplies
+ onModeration
+ digestFrequency
+ }
+ }
+ clientMutationId
}
}
- clientMutationId
- }
+ `,
+ variables: {
+ input: {
+ ...input,
+ clientMutationId: (clientMutationId++).toString(),
+ },
+ },
}
- `,
- variables: {
- input: {
- ...input,
- clientMutationId: (clientMutationId++).toString(),
- },
- },
- })
+ );
+ updateNofitificationSettings.success();
+ return result;
+ } catch (error) {
+ updateNofitificationSettings.error({
+ message: error.message,
+ code: error.code,
+ });
+ throw error;
+ }
+ }
);
export default UpdateNotificationSettingsMutation;
diff --git a/src/core/client/stream/tabs/Profile/Settings/UpdatePasswordMutation.tsx b/src/core/client/stream/tabs/Profile/Settings/UpdatePasswordMutation.tsx
index d9a8671b7..fba518537 100644
--- a/src/core/client/stream/tabs/Profile/Settings/UpdatePasswordMutation.tsx
+++ b/src/core/client/stream/tabs/Profile/Settings/UpdatePasswordMutation.tsx
@@ -6,6 +6,7 @@ import {
createMutation,
MutationInput,
} from "coral-framework/lib/relay";
+import { ChangePasswordEvent } from "coral-stream/events";
import { UpdatePasswordMutation as MutationTypes } from "coral-stream/__generated__/UpdatePasswordMutation.graphql";
@@ -13,22 +14,38 @@ let clientMutationId = 0;
const UpdatePasswordMutation = createMutation(
"updatePassword",
- (environment: Environment, input: MutationInput) =>
- commitMutationPromiseNormalized(environment, {
- mutation: graphql`
- mutation UpdatePasswordMutation($input: UpdatePasswordInput!) {
- updatePassword(input: $input) {
- clientMutationId
- }
+ async (
+ environment: Environment,
+ input: MutationInput,
+ { eventEmitter }
+ ) => {
+ const changePasswordEvent = ChangePasswordEvent.begin(eventEmitter);
+ try {
+ const result = await commitMutationPromiseNormalized(
+ environment,
+ {
+ mutation: graphql`
+ mutation UpdatePasswordMutation($input: UpdatePasswordInput!) {
+ updatePassword(input: $input) {
+ clientMutationId
+ }
+ }
+ `,
+ variables: {
+ input: {
+ ...input,
+ clientMutationId: (clientMutationId++).toString(),
+ },
+ },
}
- `,
- variables: {
- input: {
- ...input,
- clientMutationId: (clientMutationId++).toString(),
- },
- },
- })
+ );
+ changePasswordEvent.success();
+ return result;
+ } catch (error) {
+ changePasswordEvent.error({ message: error.message, code: error.code });
+ throw error;
+ }
+ }
);
export default UpdatePasswordMutation;
diff --git a/src/core/client/stream/test/comments/featured/__snapshots__/renderFeaturedStream.spec.tsx.snap b/src/core/client/stream/test/comments/featured/__snapshots__/renderFeaturedStream.spec.tsx.snap
index 7aa0df686..c6c31dd23 100644
--- a/src/core/client/stream/test/comments/featured/__snapshots__/renderFeaturedStream.spec.tsx.snap
+++ b/src/core/client/stream/test/comments/featured/__snapshots__/renderFeaturedStream.spec.tsx.snap
@@ -86,6 +86,8 @@ exports[`renders comment stream 1`] = `