From 3680a6081c1f9c6a862a419c7430d1bf96d01957 Mon Sep 17 00:00:00 2001 From: GandalfGwaihir Date: Wed, 17 Apr 2024 23:00:59 +0530 Subject: [PATCH 01/10] do not dismiss Status modal if it isn't open --- src/pages/settings/Profile/CustomStatus/StatusPage.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pages/settings/Profile/CustomStatus/StatusPage.tsx b/src/pages/settings/Profile/CustomStatus/StatusPage.tsx index 5dc1c1832d39..01ab8952ef1e 100644 --- a/src/pages/settings/Profile/CustomStatus/StatusPage.tsx +++ b/src/pages/settings/Profile/CustomStatus/StatusPage.tsx @@ -107,7 +107,10 @@ function StatusPage({draftStatus, currentUserPersonalDetails}: StatusPageProps) formRef.current?.resetForm({[INPUT_IDS.EMOJI_CODE]: ''}); InteractionManager.runAfterInteractions(() => { - navigateBackToPreviousScreen(); + // We only want to navigate back if the status RHP modal is still open + if (Navigation.isDisplayedInModal()) { + navigateBackToPreviousScreen(); + } }); }; From 2154ebd6ddff3feb8a8dfba7564e8cca22ea155e Mon Sep 17 00:00:00 2001 From: GandalfGwaihir Date: Wed, 17 Apr 2024 23:14:57 +0530 Subject: [PATCH 02/10] return early if the modal is not displayed --- src/pages/settings/Profile/CustomStatus/StatusPage.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pages/settings/Profile/CustomStatus/StatusPage.tsx b/src/pages/settings/Profile/CustomStatus/StatusPage.tsx index 01ab8952ef1e..56f63bb64ab7 100644 --- a/src/pages/settings/Profile/CustomStatus/StatusPage.tsx +++ b/src/pages/settings/Profile/CustomStatus/StatusPage.tsx @@ -108,7 +108,9 @@ function StatusPage({draftStatus, currentUserPersonalDetails}: StatusPageProps) InteractionManager.runAfterInteractions(() => { // We only want to navigate back if the status RHP modal is still open + console.log('We went outside'); if (Navigation.isDisplayedInModal()) { + console.log('We went inside'); navigateBackToPreviousScreen(); } }); From 6d24627b1198e39addb12f69dd82429425ff27ba Mon Sep 17 00:00:00 2001 From: GandalfGwaihir Date: Wed, 17 Apr 2024 23:16:54 +0530 Subject: [PATCH 03/10] return early if the modal is not displayed --- src/pages/settings/Profile/CustomStatus/StatusPage.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pages/settings/Profile/CustomStatus/StatusPage.tsx b/src/pages/settings/Profile/CustomStatus/StatusPage.tsx index 56f63bb64ab7..440bfc4ca2f4 100644 --- a/src/pages/settings/Profile/CustomStatus/StatusPage.tsx +++ b/src/pages/settings/Profile/CustomStatus/StatusPage.tsx @@ -108,12 +108,12 @@ function StatusPage({draftStatus, currentUserPersonalDetails}: StatusPageProps) InteractionManager.runAfterInteractions(() => { // We only want to navigate back if the status RHP modal is still open - console.log('We went outside'); - if (Navigation.isDisplayedInModal()) { - console.log('We went inside'); - navigateBackToPreviousScreen(); + if (!Navigation.isDisplayedInModal()) { + return; // Early return if not displayed in modal } - }); + + navigateBackToPreviousScreen(); + }); }; useEffect(() => setBrickRoadIndicator(isValidClearAfterDate() ? undefined : CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR), [isValidClearAfterDate]); From 7aad112ca2b25517644ecf83824021289992494e Mon Sep 17 00:00:00 2001 From: GandalfGwaihir Date: Wed, 17 Apr 2024 23:18:06 +0530 Subject: [PATCH 04/10] fix lint --- src/pages/settings/Profile/CustomStatus/StatusPage.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/settings/Profile/CustomStatus/StatusPage.tsx b/src/pages/settings/Profile/CustomStatus/StatusPage.tsx index 440bfc4ca2f4..4f79c2b5d006 100644 --- a/src/pages/settings/Profile/CustomStatus/StatusPage.tsx +++ b/src/pages/settings/Profile/CustomStatus/StatusPage.tsx @@ -111,9 +111,9 @@ function StatusPage({draftStatus, currentUserPersonalDetails}: StatusPageProps) if (!Navigation.isDisplayedInModal()) { return; // Early return if not displayed in modal } - + navigateBackToPreviousScreen(); - }); + }); }; useEffect(() => setBrickRoadIndicator(isValidClearAfterDate() ? undefined : CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR), [isValidClearAfterDate]); From 345af8104740a96bbbdccbc63a41cea350d269f2 Mon Sep 17 00:00:00 2001 From: GandalfGwaihir Date: Mon, 13 May 2024 19:41:16 +0530 Subject: [PATCH 05/10] use ref --- .../Profile/CustomStatus/StatusPage.tsx | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/pages/settings/Profile/CustomStatus/StatusPage.tsx b/src/pages/settings/Profile/CustomStatus/StatusPage.tsx index 4f79c2b5d006..35864fea8026 100644 --- a/src/pages/settings/Profile/CustomStatus/StatusPage.tsx +++ b/src/pages/settings/Profile/CustomStatus/StatusPage.tsx @@ -74,6 +74,22 @@ function StatusPage({draftStatus, currentUserPersonalDetails}: StatusPageProps) return DateUtils.isTimeAtLeastOneMinuteInFuture({dateTimeString: clearAfterTime}); }, [draftClearAfter, currentUserClearAfter]); + const navigateBackToPreviousScreenTask = useRef<{ + then: (onfulfilled?: () => any, onrejected?: () => any) => Promise; + done: (...args: any[]) => any; + cancel: () => void; + } | null>(null); + + useEffect(() => { + return () => { + if (!navigateBackToPreviousScreenTask.current) { + return; + } + + navigateBackToPreviousScreenTask.current.cancel(); + }; + }, []); + const navigateBackToPreviousScreen = useCallback(() => Navigation.goBack(), []); const updateStatus = useCallback( ({emojiCode, statusText}: FormOnyxValues) => { @@ -90,7 +106,7 @@ function StatusPage({draftStatus, currentUserPersonalDetails}: StatusPageProps) clearAfter: clearAfterTime !== CONST.CUSTOM_STATUS_TYPES.NEVER ? clearAfterTime : '', }); User.clearDraftCustomStatus(); - InteractionManager.runAfterInteractions(() => { + navigateBackToPreviousScreenTask.current = InteractionManager.runAfterInteractions(() => { navigateBackToPreviousScreen(); }); }, @@ -106,12 +122,7 @@ function StatusPage({draftStatus, currentUserPersonalDetails}: StatusPageProps) }); formRef.current?.resetForm({[INPUT_IDS.EMOJI_CODE]: ''}); - InteractionManager.runAfterInteractions(() => { - // We only want to navigate back if the status RHP modal is still open - if (!Navigation.isDisplayedInModal()) { - return; // Early return if not displayed in modal - } - + navigateBackToPreviousScreenTask.current = InteractionManager.runAfterInteractions(() => { navigateBackToPreviousScreen(); }); }; From 0e3cc3eb3efbc4a0e126cf495ffd062bdb97a0ab Mon Sep 17 00:00:00 2001 From: GandalfGwaihir Date: Fri, 17 May 2024 00:39:28 +0530 Subject: [PATCH 06/10] Assin type --- src/pages/settings/Profile/CustomStatus/StatusPage.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pages/settings/Profile/CustomStatus/StatusPage.tsx b/src/pages/settings/Profile/CustomStatus/StatusPage.tsx index 35864fea8026..de56b7a7735c 100644 --- a/src/pages/settings/Profile/CustomStatus/StatusPage.tsx +++ b/src/pages/settings/Profile/CustomStatus/StatusPage.tsx @@ -75,8 +75,11 @@ function StatusPage({draftStatus, currentUserPersonalDetails}: StatusPageProps) }, [draftClearAfter, currentUserClearAfter]); const navigateBackToPreviousScreenTask = useRef<{ - then: (onfulfilled?: () => any, onrejected?: () => any) => Promise; - done: (...args: any[]) => any; + then: ( + onfulfilled?: () => typeof InteractionManager.runAfterInteractions, + onrejected?: () => typeof InteractionManager.runAfterInteractions, + ) => Promise; + done: (...args: (typeof InteractionManager.runAfterInteractions)[]) => typeof InteractionManager.runAfterInteractions; cancel: () => void; } | null>(null); From 8926183e34b3ca139e66d93b881c7c057e3cdbde Mon Sep 17 00:00:00 2001 From: GandalfGwaihir Date: Fri, 17 May 2024 00:50:48 +0530 Subject: [PATCH 07/10] fix types --- .../settings/Profile/CustomStatus/StatusPage.tsx | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/pages/settings/Profile/CustomStatus/StatusPage.tsx b/src/pages/settings/Profile/CustomStatus/StatusPage.tsx index de56b7a7735c..596e829c04a1 100644 --- a/src/pages/settings/Profile/CustomStatus/StatusPage.tsx +++ b/src/pages/settings/Profile/CustomStatus/StatusPage.tsx @@ -79,18 +79,16 @@ function StatusPage({draftStatus, currentUserPersonalDetails}: StatusPageProps) onfulfilled?: () => typeof InteractionManager.runAfterInteractions, onrejected?: () => typeof InteractionManager.runAfterInteractions, ) => Promise; - done: (...args: (typeof InteractionManager.runAfterInteractions)[]) => typeof InteractionManager.runAfterInteractions; + done: (...args: Array) => typeof InteractionManager.runAfterInteractions; cancel: () => void; } | null>(null); useEffect(() => { - return () => { - if (!navigateBackToPreviousScreenTask.current) { - return; - } + if (!navigateBackToPreviousScreenTask.current) { + return; + } - navigateBackToPreviousScreenTask.current.cancel(); - }; + navigateBackToPreviousScreenTask.current.cancel(); }, []); const navigateBackToPreviousScreen = useCallback(() => Navigation.goBack(), []); From 0a2e77ea1488b8972a5543935401c3c254707d5f Mon Sep 17 00:00:00 2001 From: GandalfGwaihir Date: Tue, 21 May 2024 18:52:05 +0530 Subject: [PATCH 08/10] push useeffect changes --- src/pages/settings/Profile/CustomStatus/StatusPage.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pages/settings/Profile/CustomStatus/StatusPage.tsx b/src/pages/settings/Profile/CustomStatus/StatusPage.tsx index 596e829c04a1..26b5715b3705 100644 --- a/src/pages/settings/Profile/CustomStatus/StatusPage.tsx +++ b/src/pages/settings/Profile/CustomStatus/StatusPage.tsx @@ -84,11 +84,13 @@ function StatusPage({draftStatus, currentUserPersonalDetails}: StatusPageProps) } | null>(null); useEffect(() => { - if (!navigateBackToPreviousScreenTask.current) { - return; - } + return () => { + if (!navigateBackToPreviousScreenTask.current) { + return; + } - navigateBackToPreviousScreenTask.current.cancel(); + navigateBackToPreviousScreenTask.current.cancel(); + }; }, []); const navigateBackToPreviousScreen = useCallback(() => Navigation.goBack(), []); From f5108772d99391e9436ee73813b201ac4a23aa81 Mon Sep 17 00:00:00 2001 From: GandalfGwaihir Date: Wed, 22 May 2024 20:15:24 +0530 Subject: [PATCH 09/10] Fix lint --- src/pages/settings/Profile/CustomStatus/StatusPage.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/pages/settings/Profile/CustomStatus/StatusPage.tsx b/src/pages/settings/Profile/CustomStatus/StatusPage.tsx index 26b5715b3705..e373cdc7e7c4 100644 --- a/src/pages/settings/Profile/CustomStatus/StatusPage.tsx +++ b/src/pages/settings/Profile/CustomStatus/StatusPage.tsx @@ -83,15 +83,13 @@ function StatusPage({draftStatus, currentUserPersonalDetails}: StatusPageProps) cancel: () => void; } | null>(null); - useEffect(() => { - return () => { + useEffect(() => () => { if (!navigateBackToPreviousScreenTask.current) { return; } navigateBackToPreviousScreenTask.current.cancel(); - }; - }, []); + }, []); const navigateBackToPreviousScreen = useCallback(() => Navigation.goBack(), []); const updateStatus = useCallback( From f55c624d5ee8353a90a1562257a29345ae1b66a7 Mon Sep 17 00:00:00 2001 From: GandalfGwaihir Date: Wed, 22 May 2024 20:26:31 +0530 Subject: [PATCH 10/10] Fix prettier --- src/pages/settings/Profile/CustomStatus/StatusPage.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pages/settings/Profile/CustomStatus/StatusPage.tsx b/src/pages/settings/Profile/CustomStatus/StatusPage.tsx index e373cdc7e7c4..13c7ad92ec49 100644 --- a/src/pages/settings/Profile/CustomStatus/StatusPage.tsx +++ b/src/pages/settings/Profile/CustomStatus/StatusPage.tsx @@ -83,13 +83,16 @@ function StatusPage({draftStatus, currentUserPersonalDetails}: StatusPageProps) cancel: () => void; } | null>(null); - useEffect(() => () => { + useEffect( + () => () => { if (!navigateBackToPreviousScreenTask.current) { return; } navigateBackToPreviousScreenTask.current.cancel(); - }, []); + }, + [], + ); const navigateBackToPreviousScreen = useCallback(() => Navigation.goBack(), []); const updateStatus = useCallback(