From e9cdc56ea85f994f2a8765b0c79535b1e4583f92 Mon Sep 17 00:00:00 2001 From: Filip Solecki Date: Mon, 15 Jan 2024 13:34:24 +0100 Subject: [PATCH 1/5] Migrate Remaining Group 3 to TS --- ...ocusManager.js => ComposerFocusManager.ts} | 2 +- ...{SuggestionUtils.js => SuggestionUtils.ts} | 23 ++++++++----------- 2 files changed, 11 insertions(+), 14 deletions(-) rename src/libs/{ComposerFocusManager.js => ComposerFocusManager.ts} (86%) rename src/libs/{SuggestionUtils.js => SuggestionUtils.ts} (72%) diff --git a/src/libs/ComposerFocusManager.js b/src/libs/ComposerFocusManager.ts similarity index 86% rename from src/libs/ComposerFocusManager.js rename to src/libs/ComposerFocusManager.ts index 569e165da962..4b7037e6e2c5 100644 --- a/src/libs/ComposerFocusManager.js +++ b/src/libs/ComposerFocusManager.ts @@ -1,5 +1,5 @@ let isReadyToFocusPromise = Promise.resolve(); -let resolveIsReadyToFocus; +let resolveIsReadyToFocus: (value: void | PromiseLike) => void; function resetReadyToFocus() { isReadyToFocusPromise = new Promise((resolve) => { diff --git a/src/libs/SuggestionUtils.js b/src/libs/SuggestionUtils.ts similarity index 72% rename from src/libs/SuggestionUtils.js rename to src/libs/SuggestionUtils.ts index 45641ebb5a0f..261dcbf39edc 100644 --- a/src/libs/SuggestionUtils.js +++ b/src/libs/SuggestionUtils.ts @@ -2,11 +2,10 @@ import CONST from '@src/CONST'; /** * Return the max available index for arrow manager. - * @param {Number} numRows - * @param {Boolean} isAutoSuggestionPickerLarge - * @returns {Number} + * @param numRows + * @param isAutoSuggestionPickerLarge */ -function getMaxArrowIndex(numRows, isAutoSuggestionPickerLarge) { +function getMaxArrowIndex(numRows: number, isAutoSuggestionPickerLarge: boolean): number { // rowCount is number of emoji/mention suggestions. For small screen we can fit 3 items // and for large we show up to 20 items for mentions/emojis const rowCount = isAutoSuggestionPickerLarge @@ -19,21 +18,19 @@ function getMaxArrowIndex(numRows, isAutoSuggestionPickerLarge) { /** * Trims first character of the string if it is a space - * @param {String} str - * @returns {String} + * @param str */ -function trimLeadingSpace(str) { - return str.slice(0, 1) === ' ' ? str.slice(1) : str; +function trimLeadingSpace(str: string): string { + return str.startsWith(' ') ? str.slice(1) : str; } /** * Checks if space is available to render large suggestion menu - * @param {Number} listHeight - * @param {Number} composerHeight - * @param {Number} totalSuggestions - * @returns {Boolean} + * @param listHeight + * @param composerHeight + * @param totalSuggestions */ -function hasEnoughSpaceForLargeSuggestionMenu(listHeight, composerHeight, totalSuggestions) { +function hasEnoughSpaceForLargeSuggestionMenu(listHeight: number, composerHeight: number, totalSuggestions: number): boolean { const maxSuggestions = CONST.AUTO_COMPLETE_SUGGESTER.MAX_AMOUNT_OF_VISIBLE_SUGGESTIONS_IN_CONTAINER; const chatFooterHeight = CONST.CHAT_FOOTER_SECONDARY_ROW_HEIGHT + 2 * CONST.CHAT_FOOTER_SECONDARY_ROW_PADDING; const availableHeight = listHeight - composerHeight - chatFooterHeight; From 7880016e9f2b1ee53752f2f7879bf2ffd8bea2bc Mon Sep 17 00:00:00 2001 From: Filip Solecki Date: Mon, 15 Jan 2024 13:45:38 +0100 Subject: [PATCH 2/5] Add empty lines --- src/libs/ComposerFocusManager.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libs/ComposerFocusManager.ts b/src/libs/ComposerFocusManager.ts index 4b7037e6e2c5..0dfb0d97dac3 100644 --- a/src/libs/ComposerFocusManager.ts +++ b/src/libs/ComposerFocusManager.ts @@ -6,12 +6,14 @@ function resetReadyToFocus() { resolveIsReadyToFocus = resolve; }); } + function setReadyToFocus() { if (!resolveIsReadyToFocus) { return; } resolveIsReadyToFocus(); } + function isReadyToFocus() { return isReadyToFocusPromise; } From 10fba1290fe181304f8528bfc18ab9345351747a Mon Sep 17 00:00:00 2001 From: Filip Solecki Date: Mon, 15 Jan 2024 13:49:57 +0100 Subject: [PATCH 3/5] Add return type for isReadyToFocus --- src/libs/ComposerFocusManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ComposerFocusManager.ts b/src/libs/ComposerFocusManager.ts index 0dfb0d97dac3..b66bbe92599e 100644 --- a/src/libs/ComposerFocusManager.ts +++ b/src/libs/ComposerFocusManager.ts @@ -14,7 +14,7 @@ function setReadyToFocus() { resolveIsReadyToFocus(); } -function isReadyToFocus() { +function isReadyToFocus(): Promise { return isReadyToFocusPromise; } From 7f2ac3fac47e9181699bd7915556122c73375112 Mon Sep 17 00:00:00 2001 From: Filip Solecki Date: Mon, 15 Jan 2024 13:53:58 +0100 Subject: [PATCH 4/5] Remove params with no descriptions --- src/libs/SuggestionUtils.ts | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/libs/SuggestionUtils.ts b/src/libs/SuggestionUtils.ts index 261dcbf39edc..213a2a9e49f1 100644 --- a/src/libs/SuggestionUtils.ts +++ b/src/libs/SuggestionUtils.ts @@ -1,10 +1,6 @@ import CONST from '@src/CONST'; -/** - * Return the max available index for arrow manager. - * @param numRows - * @param isAutoSuggestionPickerLarge - */ +/** Return the max available index for arrow manager. */ function getMaxArrowIndex(numRows: number, isAutoSuggestionPickerLarge: boolean): number { // rowCount is number of emoji/mention suggestions. For small screen we can fit 3 items // and for large we show up to 20 items for mentions/emojis @@ -16,20 +12,12 @@ function getMaxArrowIndex(numRows: number, isAutoSuggestionPickerLarge: boolean) return rowCount - 1; } -/** - * Trims first character of the string if it is a space - * @param str - */ +/** Trims first character of the string if it is a space */ function trimLeadingSpace(str: string): string { return str.startsWith(' ') ? str.slice(1) : str; } -/** - * Checks if space is available to render large suggestion menu - * @param listHeight - * @param composerHeight - * @param totalSuggestions - */ +/** Checks if space is available to render large suggestion menu */ function hasEnoughSpaceForLargeSuggestionMenu(listHeight: number, composerHeight: number, totalSuggestions: number): boolean { const maxSuggestions = CONST.AUTO_COMPLETE_SUGGESTER.MAX_AMOUNT_OF_VISIBLE_SUGGESTIONS_IN_CONTAINER; const chatFooterHeight = CONST.CHAT_FOOTER_SECONDARY_ROW_HEIGHT + 2 * CONST.CHAT_FOOTER_SECONDARY_ROW_PADDING; From fe4fd495e59e083a6d42cca64e11f0a1de5dafa4 Mon Sep 17 00:00:00 2001 From: Filip Solecki Date: Tue, 23 Jan 2024 20:58:50 +0100 Subject: [PATCH 5/5] Requested review changes --- src/libs/SuggestionUtils.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libs/SuggestionUtils.ts b/src/libs/SuggestionUtils.ts index a51acbdab579..96379ce49ef3 100644 --- a/src/libs/SuggestionUtils.ts +++ b/src/libs/SuggestionUtils.ts @@ -1,10 +1,14 @@ import CONST from '@src/CONST'; -/** Trims first character of the string if it is a space */ +/** + * Trims first character of the string if it is a space + */ function trimLeadingSpace(str: string): string { return str.startsWith(' ') ? str.slice(1) : str; } -/** Checks if space is available to render large suggestion menu */ +/** + * Checks if space is available to render large suggestion menu + */ function hasEnoughSpaceForLargeSuggestionMenu(listHeight: number, composerHeight: number, totalSuggestions: number): boolean { const maxSuggestions = CONST.AUTO_COMPLETE_SUGGESTER.MAX_AMOUNT_OF_VISIBLE_SUGGESTIONS_IN_CONTAINER; const chatFooterHeight = CONST.CHAT_FOOTER_SECONDARY_ROW_HEIGHT + 2 * CONST.CHAT_FOOTER_SECONDARY_ROW_PADDING;