From c824c4a858b9e659fc1ac8393764f18505d706e9 Mon Sep 17 00:00:00 2001 From: alunturner <56027671+alunturner@users.noreply.github.com> Date: Fri, 5 May 2023 10:11:56 +0100 Subject: [PATCH] Apply strictNullChecks to src/components/views/rooms/wysiwyg_composer/* (#10653) * update components folder * update useInitialContent --- .../rooms/wysiwyg_composer/components/EditionButtons.tsx | 8 ++++---- .../rooms/wysiwyg_composer/hooks/useInitialContent.ts | 9 ++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/components/views/rooms/wysiwyg_composer/components/EditionButtons.tsx b/src/components/views/rooms/wysiwyg_composer/components/EditionButtons.tsx index 34b0fef658..e7387e0fe2 100644 --- a/src/components/views/rooms/wysiwyg_composer/components/EditionButtons.tsx +++ b/src/components/views/rooms/wysiwyg_composer/components/EditionButtons.tsx @@ -14,14 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. */ -import React, { MouseEventHandler } from "react"; +import React from "react"; import { _t } from "../../../../../languageHandler"; -import AccessibleButton from "../../../elements/AccessibleButton"; +import AccessibleButton, { ButtonEvent } from "../../../elements/AccessibleButton"; interface EditionButtonsProps { - onCancelClick: MouseEventHandler; - onSaveClick: MouseEventHandler; + onCancelClick: (e: ButtonEvent) => void; + onSaveClick: (e: ButtonEvent) => void; isSaveDisabled?: boolean; } diff --git a/src/components/views/rooms/wysiwyg_composer/hooks/useInitialContent.ts b/src/components/views/rooms/wysiwyg_composer/hooks/useInitialContent.ts index 1bed0f0c74..4312814269 100644 --- a/src/components/views/rooms/wysiwyg_composer/hooks/useInitialContent.ts +++ b/src/components/views/rooms/wysiwyg_composer/hooks/useInitialContent.ts @@ -40,11 +40,14 @@ export function parseEditorStateTransfer( ): string { const partCreator = new CommandPartCreator(room, mxClient); - let parts: Part[]; + let parts: (Part | undefined)[] = []; if (editorStateTransfer.hasEditorState()) { // if restoring state from a previous editor, // restore serialized parts from the state - parts = editorStateTransfer.getSerializedParts().map((p) => partCreator.deserializePart(p)); + const serializedParts = editorStateTransfer.getSerializedParts(); + if (serializedParts !== null) { + parts = serializedParts.map((p) => partCreator.deserializePart(p)); + } } else { // otherwise, either restore serialized parts from localStorage or parse the body of the event // TODO local storage @@ -59,7 +62,7 @@ export function parseEditorStateTransfer( }); } - return parts.reduce((content, part) => content + part.text, ""); + return parts.reduce((content, part) => content + part?.text, ""); // Todo local storage // this.saveStoredEditorState(); }