From 96893ad5430bfc5afe97a0f5ae9f18961c6a5170 Mon Sep 17 00:00:00 2001 From: Gray Lewis Date: Wed, 8 Nov 2023 14:18:24 +0100 Subject: [PATCH 1/5] WIP --- .../ReportActionCompose/SuggestionMention.js | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/SuggestionMention.js b/src/pages/home/report/ReportActionCompose/SuggestionMention.js index 2ea2dd3345289..2e5b717511df0 100644 --- a/src/pages/home/report/ReportActionCompose/SuggestionMention.js +++ b/src/pages/home/report/ReportActionCompose/SuggestionMention.js @@ -198,13 +198,25 @@ function SuggestionMention({ const leftString = value.substring(0, suggestionEndIndex); const words = leftString.split(CONST.REGEX.SPACE_OR_EMOJI); const lastWord = _.last(words); + const secondToLastWord = words[words.length - 3]; let atSignIndex; + let suggestionWord + let prefix; + if (lastWord.startsWith('@')) { atSignIndex = leftString.lastIndexOf(lastWord); - } + suggestionWord = lastWord; - const prefix = lastWord.substring(1); + prefix = suggestionWord.substring(1); + } else if (secondToLastWord && secondToLastWord.startsWith('@')) { + atSignIndex = leftString.lastIndexOf(secondToLastWord); + suggestionWord = secondToLastWord + ' ' + lastWord; + + prefix = suggestionWord.substring(1); + } else { + prefix = lastWord.substring(1); + } const nextState = { suggestedMentions: [], @@ -212,10 +224,11 @@ function SuggestionMention({ mentionPrefix: prefix, }; - const isCursorBeforeTheMention = valueAfterTheCursor.startsWith(lastWord); + const isCursorBeforeTheMention = valueAfterTheCursor.startsWith(suggestionWord); - if (!isCursorBeforeTheMention && isMentionCode(lastWord)) { + if (!isCursorBeforeTheMention && isMentionCode(suggestionWord)) { const suggestions = getMentionOptions(personalDetails, prefix); + nextState.suggestedMentions = suggestions; nextState.shouldShowSuggestionMenu = !_.isEmpty(suggestions); } @@ -229,6 +242,7 @@ function SuggestionMention({ [getMentionOptions, personalDetails, resetSuggestions, setHighlightedMentionIndex, value, isComposerFocused], ); + useEffect(() => { if (value.length < previousValue.length) { // A workaround to not show the suggestions list when the user deletes a character before the mention. From 26fb266a917ffe26ae59af73b3962b177c416cd8 Mon Sep 17 00:00:00 2001 From: Gray Lewis Date: Thu, 16 Nov 2023 12:28:23 +0100 Subject: [PATCH 2/5] ready for PR --- .../home/report/ReportActionCompose/SuggestionMention.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/SuggestionMention.js b/src/pages/home/report/ReportActionCompose/SuggestionMention.js index 2e5b717511df0..f7e7c57a58bfb 100644 --- a/src/pages/home/report/ReportActionCompose/SuggestionMention.js +++ b/src/pages/home/report/ReportActionCompose/SuggestionMention.js @@ -204,14 +204,15 @@ function SuggestionMention({ let suggestionWord let prefix; + // Detect if the last two words contain a mention (two words are needed to detect a mention with a space in it) if (lastWord.startsWith('@')) { atSignIndex = leftString.lastIndexOf(lastWord); suggestionWord = lastWord; prefix = suggestionWord.substring(1); - } else if (secondToLastWord && secondToLastWord.startsWith('@')) { + } else if (secondToLastWord && secondToLastWord.startsWith('@') && secondToLastWord.length > 1) { atSignIndex = leftString.lastIndexOf(secondToLastWord); - suggestionWord = secondToLastWord + ' ' + lastWord; + suggestionWord = `${secondToLastWord} ${lastWord}`; prefix = suggestionWord.substring(1); } else { From 0573c6a7413a5e6cf55bfe07d53e61dc2c4a7d71 Mon Sep 17 00:00:00 2001 From: Gray Lewis Date: Thu, 16 Nov 2023 12:54:30 +0100 Subject: [PATCH 3/5] Update SuggestionMention.js --- src/pages/home/report/ReportActionCompose/SuggestionMention.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/home/report/ReportActionCompose/SuggestionMention.js b/src/pages/home/report/ReportActionCompose/SuggestionMention.js index f7e7c57a58bfb..63f67ae909d4d 100644 --- a/src/pages/home/report/ReportActionCompose/SuggestionMention.js +++ b/src/pages/home/report/ReportActionCompose/SuggestionMention.js @@ -243,7 +243,6 @@ function SuggestionMention({ [getMentionOptions, personalDetails, resetSuggestions, setHighlightedMentionIndex, value, isComposerFocused], ); - useEffect(() => { if (value.length < previousValue.length) { // A workaround to not show the suggestions list when the user deletes a character before the mention. From fa01cf2cf4f0e3237ed7f6c5c81f0abc60e06b70 Mon Sep 17 00:00:00 2001 From: Gray Lewis Date: Thu, 16 Nov 2023 13:06:53 +0100 Subject: [PATCH 4/5] linted --- ios/Podfile.lock | 6 +++--- .../home/report/ReportActionCompose/SuggestionMention.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 97143f53b8679..d94e36b0b3c97 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -234,8 +234,8 @@ PODS: - libwebp/demux - libwebp/webp (1.2.4) - lottie-ios (4.3.3) - - lottie-react-native (6.3.1): - - lottie-ios (~> 4.3.0) + - lottie-react-native (6.4.0): + - lottie-ios (~> 4.3.3) - React-Core - MapboxCommon (23.6.0) - MapboxCoreMaps (10.14.0): @@ -1203,7 +1203,7 @@ SPEC CHECKSUMS: libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913 libwebp: f62cb61d0a484ba548448a4bd52aabf150ff6eef lottie-ios: 25e7b2675dad5c3ddad369ac9baab03560c5bfdd - lottie-react-native: c9f1db4f4124dcce9f8159e65d8dc6e8bcb11fb4 + lottie-react-native: 3a3084faddd3891c276f23fd6e797b83f2021bbc MapboxCommon: 4a0251dd470ee37e7fadda8e285c01921a5e1eb0 MapboxCoreMaps: eb07203bbb0b1509395db5ab89cd3ad6c2e3c04c MapboxMaps: af50ec61a7eb3b032c3f7962c6bd671d93d2a209 diff --git a/src/pages/home/report/ReportActionCompose/SuggestionMention.js b/src/pages/home/report/ReportActionCompose/SuggestionMention.js index 63f67ae909d4d..a96a33573e056 100644 --- a/src/pages/home/report/ReportActionCompose/SuggestionMention.js +++ b/src/pages/home/report/ReportActionCompose/SuggestionMention.js @@ -198,10 +198,10 @@ function SuggestionMention({ const leftString = value.substring(0, suggestionEndIndex); const words = leftString.split(CONST.REGEX.SPACE_OR_EMOJI); const lastWord = _.last(words); - const secondToLastWord = words[words.length - 3]; + const secondToLastWord = words[words.length - 3]; let atSignIndex; - let suggestionWord + let suggestionWord; let prefix; // Detect if the last two words contain a mention (two words are needed to detect a mention with a space in it) From 9433f5c0c6ac196e3439bf9ac9ab09e39b0ffc6e Mon Sep 17 00:00:00 2001 From: Gray Lewis Date: Mon, 20 Nov 2023 10:34:49 +0100 Subject: [PATCH 5/5] reverting changes to this file --- ios/Podfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index d94e36b0b3c97..97143f53b8679 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -234,8 +234,8 @@ PODS: - libwebp/demux - libwebp/webp (1.2.4) - lottie-ios (4.3.3) - - lottie-react-native (6.4.0): - - lottie-ios (~> 4.3.3) + - lottie-react-native (6.3.1): + - lottie-ios (~> 4.3.0) - React-Core - MapboxCommon (23.6.0) - MapboxCoreMaps (10.14.0): @@ -1203,7 +1203,7 @@ SPEC CHECKSUMS: libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913 libwebp: f62cb61d0a484ba548448a4bd52aabf150ff6eef lottie-ios: 25e7b2675dad5c3ddad369ac9baab03560c5bfdd - lottie-react-native: 3a3084faddd3891c276f23fd6e797b83f2021bbc + lottie-react-native: c9f1db4f4124dcce9f8159e65d8dc6e8bcb11fb4 MapboxCommon: 4a0251dd470ee37e7fadda8e285c01921a5e1eb0 MapboxCoreMaps: eb07203bbb0b1509395db5ab89cd3ad6c2e3c04c MapboxMaps: af50ec61a7eb3b032c3f7962c6bd671d93d2a209