diff --git a/package-lock.json b/package-lock.json index f03e24536..d64c9326f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34310,7 +34310,7 @@ }, "chalk": { "version": "1.1.3", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", "dev": true, "requires": { diff --git a/src/core/client/stream/tabs/Comments/Comment/ReplyCommentForm/ReplyCommentFormContainer.tsx b/src/core/client/stream/tabs/Comments/Comment/ReplyCommentForm/ReplyCommentFormContainer.tsx index 97929b6f4..44033b5c3 100644 --- a/src/core/client/stream/tabs/Comments/Comment/ReplyCommentForm/ReplyCommentFormContainer.tsx +++ b/src/core/client/stream/tabs/Comments/Comment/ReplyCommentForm/ReplyCommentFormContainer.tsx @@ -26,6 +26,7 @@ import { SubmitStatus, } from "../../helpers"; import RefreshSettingsFetch from "../../RefreshSettingsFetch"; +import { RTE_RESET_VALUE } from "../../RTE/RTE"; import ReplyEditSubmitStatus from "../ReplyEditSubmitStatus"; import { CreateCommentReplyMutation, @@ -155,7 +156,7 @@ export class ReplyCommentFormContainer extends Component { } // Reset errors whenever user clears the form. if (state.touched && state.touched.body && !state.values.body) { - form.reset({}); + form.reset({ body: RTE_RESET_VALUE }); } }; diff --git a/src/core/client/stream/tabs/Comments/RTE/RTE.tsx b/src/core/client/stream/tabs/Comments/RTE/RTE.tsx index e03ae87c1..14a6b11b9 100644 --- a/src/core/client/stream/tabs/Comments/RTE/RTE.tsx +++ b/src/core/client/stream/tabs/Comments/RTE/RTE.tsx @@ -24,6 +24,8 @@ import { PropTypesOf } from "coral-ui/types"; import styles from "./RTE.css"; +export const RTE_RESET_VALUE = "

"; + interface RTEFeatures { bold?: boolean; italic?: boolean; diff --git a/src/core/client/stream/tabs/Comments/Stream/PostCommentForm/PostCommentFormContainer.spec.tsx b/src/core/client/stream/tabs/Comments/Stream/PostCommentForm/PostCommentFormContainer.spec.tsx index 7c0710532..42e43cf6e 100644 --- a/src/core/client/stream/tabs/Comments/Stream/PostCommentForm/PostCommentFormContainer.spec.tsx +++ b/src/core/client/stream/tabs/Comments/Stream/PostCommentForm/PostCommentFormContainer.spec.tsx @@ -8,6 +8,7 @@ import { createPromisifiedStorage } from "coral-framework/lib/storage"; import { act, removeFragmentRefs, wait } from "coral-framework/testHelpers"; import { DeepPartial, PropTypesOf } from "coral-framework/types"; +import { RTE_RESET_VALUE } from "../../RTE/RTE"; import { PostCommentFormContainer } from "./PostCommentFormContainer"; const contextKey = "postCommentFormBody"; @@ -126,7 +127,7 @@ it("creates a comment", async () => { const createCommentStub = sinon.stub().returns({ edge: { node: {} } }); const form = { initialize: noop }; const formMock = sinon.mock(form); - formMock.expects("initialize").withArgs({}).once(); + formMock.expects("initialize").withArgs({ body: RTE_RESET_VALUE }).once(); const props = createDefaultProps({ createComment: createCommentStub, diff --git a/src/core/client/stream/tabs/Comments/Stream/PostCommentForm/PostCommentFormContainer.tsx b/src/core/client/stream/tabs/Comments/Stream/PostCommentForm/PostCommentFormContainer.tsx index 5ae9c9622..550fcebe2 100644 --- a/src/core/client/stream/tabs/Comments/Stream/PostCommentForm/PostCommentFormContainer.tsx +++ b/src/core/client/stream/tabs/Comments/Stream/PostCommentForm/PostCommentFormContainer.tsx @@ -34,6 +34,7 @@ import { SubmitStatus, } from "../../helpers"; import RefreshSettingsFetch from "../../RefreshSettingsFetch"; +import { RTE_RESET_VALUE } from "../../RTE/RTE"; import { CreateCommentMutation, withCreateCommentMutation, @@ -134,7 +135,7 @@ export class PostCommentFormContainer extends Component { }) ); if (submitStatus !== "RETRY") { - form.initialize({}); + form.initialize({ body: RTE_RESET_VALUE }); } this.setState({ submitStatus, nudge: true }); } catch (error) { @@ -163,14 +164,7 @@ export class PostCommentFormContainer extends Component { state, form ) => { - if ( - this.state.submitStatus && - state.dirty && - // This is required because the body is somehow being "dirtied" once the - // form has been reinitialized. - // FIXME: (wyattjoh) discover why when a comment is submitted, it eventually sets this as the body afterwards - state.values.body !== "

" - ) { + if (this.state.submitStatus && state.dirty) { this.setState({ submitStatus: null }); } if (state.values.body) { @@ -181,7 +175,7 @@ export class PostCommentFormContainer extends Component { // Reset errors whenever user clears the form. if (state.touched && state.touched.body && !state.values.body) { - form.reset({}); + form.reset({ body: RTE_RESET_VALUE }); } };