From f4ee383deaf5091771eee52d8f4eb311e9ebc6c0 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 2 Jan 2025 09:58:22 +0000 Subject: [PATCH] Iterate --- platforms/web/lib/useComposerModel.ts | 2 +- platforms/web/lib/useFormattingFunctions.ts | 45 ++++++++++--------- .../web/lib/useListeners/useListeners.ts | 6 +-- .../web/lib/useWysiwyg.undo-redo.test.tsx | 3 +- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/platforms/web/lib/useComposerModel.ts b/platforms/web/lib/useComposerModel.ts index 0a9bdc5a9..cda16234b 100644 --- a/platforms/web/lib/useComposerModel.ts +++ b/platforms/web/lib/useComposerModel.ts @@ -84,7 +84,7 @@ export function useComposerModel( modelContent.length, ); } - } catch (e) { + } catch { // if the initialisation fails, due to a parsing failure of the html, fallback to an empty composer contentModel = new_composer_model(); } diff --git a/platforms/web/lib/useFormattingFunctions.ts b/platforms/web/lib/useFormattingFunctions.ts index c2dd8003e..6e813814e 100644 --- a/platforms/web/lib/useFormattingFunctions.ts +++ b/platforms/web/lib/useFormattingFunctions.ts @@ -35,43 +35,44 @@ export function useFormattingFunctions( | SuggestionEvent['data'] | AtRoomSuggestionEvent['data'], ): void => { - editorRef.current && + if (editorRef.current) { sendWysiwygInputEvent( editorRef.current, blockType, undefined, data, ); + } }; return { - bold: () => sendEvent('formatBold'), - italic: () => sendEvent('formatItalic'), - strikeThrough: () => sendEvent('formatStrikeThrough'), - underline: () => sendEvent('formatUnderline'), - undo: () => sendEvent('historyUndo'), - redo: () => sendEvent('historyRedo'), - orderedList: () => sendEvent('insertOrderedList'), - unorderedList: () => sendEvent('insertUnorderedList'), - inlineCode: () => sendEvent('formatInlineCode'), - clear: () => sendEvent('clear'), - insertText: (text: string) => sendEvent('insertText', text), - link: (url: string, text?: string) => + bold: (): void => sendEvent('formatBold'), + italic: (): void => sendEvent('formatItalic'), + strikeThrough: (): void => sendEvent('formatStrikeThrough'), + underline: (): void => sendEvent('formatUnderline'), + undo: (): void => sendEvent('historyUndo'), + redo: (): void => sendEvent('historyRedo'), + orderedList: (): void => sendEvent('insertOrderedList'), + unorderedList: (): void => sendEvent('insertUnorderedList'), + inlineCode: (): void => sendEvent('formatInlineCode'), + clear: (): void => sendEvent('clear'), + insertText: (text: string): void => sendEvent('insertText', text), + link: (url: string, text?: string): void => sendEvent('insertLink', { url, text }), - removeLinks: () => sendEvent('removeLinks'), - getLink: () => + removeLinks: (): void => sendEvent('removeLinks'), + getLink: (): string => composerModel?.get_link_action()?.edit_link?.url || '', - codeBlock: () => sendEvent('insertCodeBlock'), - quote: () => sendEvent('insertQuote'), - indent: () => sendEvent('formatIndent'), - unindent: () => sendEvent('formatOutdent'), + codeBlock: (): void => sendEvent('insertCodeBlock'), + quote: (): void => sendEvent('insertQuote'), + indent: (): void => sendEvent('formatIndent'), + unindent: (): void => sendEvent('formatOutdent'), mention: ( url: string, text: string, attributes: AllowedMentionAttributes, - ) => sendEvent('insertSuggestion', { url, text, attributes }), - command: (text: string) => sendEvent('insertCommand', text), - mentionAtRoom: (attributes: AllowedMentionAttributes) => + ): void => sendEvent('insertSuggestion', { url, text, attributes }), + command: (text: string): void => sendEvent('insertCommand', text), + mentionAtRoom: (attributes: AllowedMentionAttributes): void => sendEvent('insertAtRoomSuggestion', { attributes }), }; }, [editorRef, composerModel]); diff --git a/platforms/web/lib/useListeners/useListeners.ts b/platforms/web/lib/useListeners/useListeners.ts index 028f6b6d7..2193d8527 100644 --- a/platforms/web/lib/useListeners/useListeners.ts +++ b/platforms/web/lib/useListeners/useListeners.ts @@ -114,7 +114,7 @@ export function useListeners( plainTextContentRef.current = composerModel.get_content_as_plain_text(); } - } catch (e) { + } catch { onError(plainTextContentRef.current); } }; @@ -188,7 +188,7 @@ export function useListeners( } plainTextContentRef.current = composerModel.get_content_as_plain_text(); - } catch (e) { + } catch { onError(plainTextContentRef.current); } }; @@ -216,7 +216,7 @@ export function useListeners( setAreListenersReady(true); - return () => { + return (): void => { setAreListenersReady(false); editorNode.removeEventListener('input', onInput); editorNode.removeEventListener('paste', onPaste); diff --git a/platforms/web/lib/useWysiwyg.undo-redo.test.tsx b/platforms/web/lib/useWysiwyg.undo-redo.test.tsx index ae4c5e237..3991d059d 100644 --- a/platforms/web/lib/useWysiwyg.undo-redo.test.tsx +++ b/platforms/web/lib/useWysiwyg.undo-redo.test.tsx @@ -6,9 +6,8 @@ SPDX-License-Identifier: AGPL-3.0-only Please see LICENSE in the repository root for full details. */ -import { fireEvent, render, screen, waitFor } from '@testing-library/react'; +import { fireEvent, render, screen, waitFor, act } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import { act } from 'react-dom/test-utils'; import { Editor } from './testUtils/Editor';