From 79c2f6117f1b68743952d4ee0a82a95c6e4a7cde Mon Sep 17 00:00:00 2001 From: Steven KKC Date: Mon, 25 Sep 2023 02:23:51 -0400 Subject: [PATCH 01/14] fix new tab opens when downloading offline --- src/components/AttachmentModal.js | 3 ++- src/pages/home/report/ContextMenu/ContextMenuActions.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/AttachmentModal.js b/src/components/AttachmentModal.js index 3f89f4032061..6464c18b727c 100755 --- a/src/components/AttachmentModal.js +++ b/src/components/AttachmentModal.js @@ -30,6 +30,7 @@ import useWindowDimensions from '../hooks/useWindowDimensions'; import Navigation from '../libs/Navigation/Navigation'; import ROUTES from '../ROUTES'; import useNativeDriver from '../libs/useNativeDriver'; +import * as NetworkStore from '../libs/Network/NetworkStore'; /** * Modal render prop component that exposes modal launching triggers that can be used @@ -350,7 +351,7 @@ function AttachmentModal(props) { downloadAttachment(source)} shouldShowCloseButton={!props.isSmallScreenWidth} shouldShowBackButton={props.isSmallScreenWidth} diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 2a65bc2e67ab..3a7bfeec684d 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -25,6 +25,7 @@ import * as Task from '../../../../libs/actions/Task'; import * as Localize from '../../../../libs/Localize'; import * as TransactionUtils from '../../../../libs/TransactionUtils'; import * as CurrencyUtils from '../../../../libs/CurrencyUtils'; +import * as NetworkStore from '../../../../libs/Network/NetworkStore'; /** * Gets the HTML version of the message in an action. @@ -101,7 +102,7 @@ export default [ shouldShow: (type, reportAction) => { const isAttachment = ReportActionsUtils.isReportActionAttachment(reportAction); const messageHtml = lodashGet(reportAction, ['message', 0, 'html']); - return isAttachment && messageHtml !== CONST.ATTACHMENT_UPLOADING_MESSAGE_HTML && reportAction.reportActionID && !ReportActionsUtils.isMessageDeleted(reportAction); + return isAttachment && messageHtml !== CONST.ATTACHMENT_UPLOADING_MESSAGE_HTML && reportAction.reportActionID && !ReportActionsUtils.isMessageDeleted(reportAction) && !NetworkStore.isOffline(); }, onPress: (closePopover, {reportAction}) => { const message = _.last(lodashGet(reportAction, 'message', [{}])); From 8d12ce33ef2385c2ca6a70cb5f9595563921b4f9 Mon Sep 17 00:00:00 2001 From: Steven KKC Date: Mon, 25 Sep 2023 02:48:32 -0400 Subject: [PATCH 02/14] fix lint error --- src/pages/home/report/ContextMenu/ContextMenuActions.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 3a7bfeec684d..8504ee036a0a 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -102,7 +102,13 @@ export default [ shouldShow: (type, reportAction) => { const isAttachment = ReportActionsUtils.isReportActionAttachment(reportAction); const messageHtml = lodashGet(reportAction, ['message', 0, 'html']); - return isAttachment && messageHtml !== CONST.ATTACHMENT_UPLOADING_MESSAGE_HTML && reportAction.reportActionID && !ReportActionsUtils.isMessageDeleted(reportAction) && !NetworkStore.isOffline(); + return ( + isAttachment && + messageHtml !== CONST.ATTACHMENT_UPLOADING_MESSAGE_HTML && + reportAction.reportActionID && + !ReportActionsUtils.isMessageDeleted(reportAction) && + !NetworkStore.isOffline() + ); }, onPress: (closePopover, {reportAction}) => { const message = _.last(lodashGet(reportAction, 'message', [{}])); From fb1dde82dc4f24022f1b5ad2d448d0bfa49d4963 Mon Sep 17 00:00:00 2001 From: Steven Maksym <131836113+StevenKKC@users.noreply.github.com> Date: Mon, 25 Sep 2023 19:26:38 -0400 Subject: [PATCH 03/14] use network hook --- .../home/report/ContextMenu/ContextMenuActions.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 8504ee036a0a..5eefe6a486d0 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -25,7 +25,7 @@ import * as Task from '../../../../libs/actions/Task'; import * as Localize from '../../../../libs/Localize'; import * as TransactionUtils from '../../../../libs/TransactionUtils'; import * as CurrencyUtils from '../../../../libs/CurrencyUtils'; -import * as NetworkStore from '../../../../libs/Network/NetworkStore'; +import useNetwork from '../../../../hooks/useNetwork'; /** * Gets the HTML version of the message in an action. @@ -44,6 +44,8 @@ const CONTEXT_MENU_TYPES = { REPORT: 'REPORT', }; +const {isOffline} = useNetwork(); + // A list of all the context actions in this menu. export default [ { @@ -102,13 +104,7 @@ export default [ shouldShow: (type, reportAction) => { const isAttachment = ReportActionsUtils.isReportActionAttachment(reportAction); const messageHtml = lodashGet(reportAction, ['message', 0, 'html']); - return ( - isAttachment && - messageHtml !== CONST.ATTACHMENT_UPLOADING_MESSAGE_HTML && - reportAction.reportActionID && - !ReportActionsUtils.isMessageDeleted(reportAction) && - !NetworkStore.isOffline() - ); + return isAttachment && messageHtml !== CONST.ATTACHMENT_UPLOADING_MESSAGE_HTML && reportAction.reportActionID && !ReportActionsUtils.isMessageDeleted(reportAction) && !isOffline; }, onPress: (closePopover, {reportAction}) => { const message = _.last(lodashGet(reportAction, 'message', [{}])); From d717a24ceec835f5488745acdbda9ae5cb6781ae Mon Sep 17 00:00:00 2001 From: Steven Maksym <131836113+StevenKKC@users.noreply.github.com> Date: Tue, 26 Sep 2023 02:01:57 -0400 Subject: [PATCH 04/14] Revert wrong update --- .../home/report/ContextMenu/ContextMenuActions.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 5eefe6a486d0..8504ee036a0a 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -25,7 +25,7 @@ import * as Task from '../../../../libs/actions/Task'; import * as Localize from '../../../../libs/Localize'; import * as TransactionUtils from '../../../../libs/TransactionUtils'; import * as CurrencyUtils from '../../../../libs/CurrencyUtils'; -import useNetwork from '../../../../hooks/useNetwork'; +import * as NetworkStore from '../../../../libs/Network/NetworkStore'; /** * Gets the HTML version of the message in an action. @@ -44,8 +44,6 @@ const CONTEXT_MENU_TYPES = { REPORT: 'REPORT', }; -const {isOffline} = useNetwork(); - // A list of all the context actions in this menu. export default [ { @@ -104,7 +102,13 @@ export default [ shouldShow: (type, reportAction) => { const isAttachment = ReportActionsUtils.isReportActionAttachment(reportAction); const messageHtml = lodashGet(reportAction, ['message', 0, 'html']); - return isAttachment && messageHtml !== CONST.ATTACHMENT_UPLOADING_MESSAGE_HTML && reportAction.reportActionID && !ReportActionsUtils.isMessageDeleted(reportAction) && !isOffline; + return ( + isAttachment && + messageHtml !== CONST.ATTACHMENT_UPLOADING_MESSAGE_HTML && + reportAction.reportActionID && + !ReportActionsUtils.isMessageDeleted(reportAction) && + !NetworkStore.isOffline() + ); }, onPress: (closePopover, {reportAction}) => { const message = _.last(lodashGet(reportAction, 'message', [{}])); From 71acc4fb0a534b8de1aca1bb23e818410f1cf4a5 Mon Sep 17 00:00:00 2001 From: Steven Maksym <131836113+StevenKKC@users.noreply.github.com> Date: Tue, 26 Sep 2023 02:07:49 -0400 Subject: [PATCH 05/14] use network hook - (2) --- src/components/AttachmentModal.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/AttachmentModal.js b/src/components/AttachmentModal.js index 6464c18b727c..d643cd647709 100755 --- a/src/components/AttachmentModal.js +++ b/src/components/AttachmentModal.js @@ -30,7 +30,7 @@ import useWindowDimensions from '../hooks/useWindowDimensions'; import Navigation from '../libs/Navigation/Navigation'; import ROUTES from '../ROUTES'; import useNativeDriver from '../libs/useNativeDriver'; -import * as NetworkStore from '../libs/Network/NetworkStore'; +import useNetwork from '../hooks/useNetwork'; /** * Modal render prop component that exposes modal launching triggers that can be used @@ -122,6 +122,7 @@ function AttachmentModal(props) { : undefined, ); const {translate} = useLocalize(); + const {isOffline} = useNetwork(); const onCarouselAttachmentChange = props.onCarouselAttachmentChange; @@ -351,7 +352,7 @@ function AttachmentModal(props) { downloadAttachment(source)} shouldShowCloseButton={!props.isSmallScreenWidth} shouldShowBackButton={props.isSmallScreenWidth} From 34a60f05ddf3b16e0c589bb49f53c15d5c2bc6a3 Mon Sep 17 00:00:00 2001 From: Steven Maksym <131836113+StevenKKC@users.noreply.github.com> Date: Tue, 26 Sep 2023 15:57:34 -0400 Subject: [PATCH 06/14] fix lint error --- src/pages/home/report/ContextMenu/ContextMenuActions.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 857ee8eb7f55..81f13e2caa37 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -22,9 +22,6 @@ import MiniQuickEmojiReactions from '../../../../components/Reactions/MiniQuickE import Navigation from '../../../../libs/Navigation/Navigation'; import ROUTES from '../../../../ROUTES'; import * as Task from '../../../../libs/actions/Task'; -import * as Localize from '../../../../libs/Localize'; -import * as TransactionUtils from '../../../../libs/TransactionUtils'; -import * as CurrencyUtils from '../../../../libs/CurrencyUtils'; import * as NetworkStore from '../../../../libs/Network/NetworkStore'; /** From 8adaa11601a01a3afa1a3e9417e617778c74217c Mon Sep 17 00:00:00 2001 From: Steven Maksym <131836113+StevenKKC@users.noreply.github.com> Date: Tue, 26 Sep 2023 16:34:37 -0400 Subject: [PATCH 07/14] Update BaseReportActionContextMenu.js --- .../home/report/ContextMenu/BaseReportActionContextMenu.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js index fc56b3b1fac9..86197e979a4d 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js @@ -18,6 +18,7 @@ import ONYXKEYS from '../../../../ONYXKEYS'; import CONST from '../../../../CONST'; import useArrowKeyFocusManager from '../../../../hooks/useArrowKeyFocusManager'; import useKeyboardShortcut from '../../../../hooks/useKeyboardShortcut'; +import useNetwork from '../../../../hooks/useNetwork'; const propTypes = { /** String representing the context menu type [LINK, REPORT_ACTION] which controls context menu choices */ @@ -51,6 +52,7 @@ function BaseReportActionContextMenu(props) { const menuItemRefs = useRef({}); const [shouldKeepOpen, setShouldKeepOpen] = useState(false); const wrapperStyle = getReportActionContextMenuStyles(props.isMini, props.isSmallScreenWidth); + const {isOffline} = useNetwork(); const reportAction = useMemo(() => { if (_.isEmpty(props.reportActions) || props.reportActionID === '0') { @@ -60,7 +62,7 @@ function BaseReportActionContextMenu(props) { }, [props.reportActions, props.reportActionID]); const shouldShowFilter = (contextAction) => - contextAction.shouldShow(props.type, reportAction, props.isArchivedRoom, props.betas, props.anchor, props.isChronosReport, props.reportID, props.isPinnedChat, props.isUnreadChat); + contextAction.shouldShow(props.type, reportAction, props.isArchivedRoom, props.betas, props.anchor, props.isChronosReport, props.reportID, props.isPinnedChat, props.isUnreadChat, isOffline); const shouldEnableArrowNavigation = !props.isMini && (props.isVisible || shouldKeepOpen); const filteredContextMenuActions = _.filter(ContextMenuActions, shouldShowFilter); From 6d306125f0725b6c7f21db8858ce436ff8d5fd46 Mon Sep 17 00:00:00 2001 From: Steven Maksym <131836113+StevenKKC@users.noreply.github.com> Date: Tue, 26 Sep 2023 17:04:47 -0400 Subject: [PATCH 08/14] Update src/pages/home/report/ContextMenu/ContextMenuActions.js Co-authored-by: Fedi Rajhi --- src/pages/home/report/ContextMenu/ContextMenuActions.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 81f13e2caa37..10fe86a96378 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -22,7 +22,6 @@ import MiniQuickEmojiReactions from '../../../../components/Reactions/MiniQuickE import Navigation from '../../../../libs/Navigation/Navigation'; import ROUTES from '../../../../ROUTES'; import * as Task from '../../../../libs/actions/Task'; -import * as NetworkStore from '../../../../libs/Network/NetworkStore'; /** * Gets the HTML version of the message in an action. From c3f3b7265cf4b8435f2c1f68162c977a7c38995f Mon Sep 17 00:00:00 2001 From: Steven Maksym <131836113+StevenKKC@users.noreply.github.com> Date: Tue, 26 Sep 2023 17:05:10 -0400 Subject: [PATCH 09/14] Update src/pages/home/report/ContextMenu/ContextMenuActions.js Co-authored-by: Fedi Rajhi --- src/pages/home/report/ContextMenu/ContextMenuActions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 10fe86a96378..9e0ede1e1180 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -95,7 +95,7 @@ export default [ icon: Expensicons.Download, successTextTranslateKey: 'common.download', successIcon: Expensicons.Download, - shouldShow: (type, reportAction) => { + shouldShow: (type, reportAction, isArchivedRoom, betas, anchor, isChronosReport, reportID, isPinnedChat, isUnreadChat, isOffline) => { const isAttachment = ReportActionsUtils.isReportActionAttachment(reportAction); const messageHtml = lodashGet(reportAction, ['message', 0, 'html']); return ( From aa8b4a27f4eb7be7e52cce82ebfd177dc4ad4e58 Mon Sep 17 00:00:00 2001 From: Steven Maksym <131836113+StevenKKC@users.noreply.github.com> Date: Tue, 26 Sep 2023 17:05:31 -0400 Subject: [PATCH 10/14] Update src/pages/home/report/ContextMenu/ContextMenuActions.js Co-authored-by: Fedi Rajhi --- src/pages/home/report/ContextMenu/ContextMenuActions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 9e0ede1e1180..38c715eb9f22 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -103,7 +103,7 @@ export default [ messageHtml !== CONST.ATTACHMENT_UPLOADING_MESSAGE_HTML && reportAction.reportActionID && !ReportActionsUtils.isMessageDeleted(reportAction) && - !NetworkStore.isOffline() + !isOffline ); }, onPress: (closePopover, {reportAction}) => { From 760ee57cd5e10d7a6bbc9fee5ca05609e3621606 Mon Sep 17 00:00:00 2001 From: Steven Maksym <131836113+StevenKKC@users.noreply.github.com> Date: Tue, 26 Sep 2023 17:26:08 -0400 Subject: [PATCH 11/14] Update ContextMenuActions.js --- src/pages/home/report/ContextMenu/ContextMenuActions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 38c715eb9f22..c87326f07435 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -95,7 +95,7 @@ export default [ icon: Expensicons.Download, successTextTranslateKey: 'common.download', successIcon: Expensicons.Download, - shouldShow: (type, reportAction, isArchivedRoom, betas, anchor, isChronosReport, reportID, isPinnedChat, isUnreadChat, isOffline) => { + shouldShow: (type, reportAction, isOffline) => { const isAttachment = ReportActionsUtils.isReportActionAttachment(reportAction); const messageHtml = lodashGet(reportAction, ['message', 0, 'html']); return ( From 3167756b29ac21d7b2b66a423f994f698d089c3f Mon Sep 17 00:00:00 2001 From: Steven Maksym <131836113+StevenKKC@users.noreply.github.com> Date: Tue, 26 Sep 2023 17:40:44 -0400 Subject: [PATCH 12/14] Update src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js Co-authored-by: Fedi Rajhi --- .../ContextMenu/BaseReportActionContextMenu.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js index 86197e979a4d..91fe38784e9c 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js @@ -62,7 +62,18 @@ function BaseReportActionContextMenu(props) { }, [props.reportActions, props.reportActionID]); const shouldShowFilter = (contextAction) => - contextAction.shouldShow(props.type, reportAction, props.isArchivedRoom, props.betas, props.anchor, props.isChronosReport, props.reportID, props.isPinnedChat, props.isUnreadChat, isOffline); + contextAction.shouldShow( + props.type, + reportAction, + props.isArchivedRoom, + props.betas, + props.anchor, + props.isChronosReport, + props.reportID, + props.isPinnedChat, + props.isUnreadChat, + isOffline, + ); const shouldEnableArrowNavigation = !props.isMini && (props.isVisible || shouldKeepOpen); const filteredContextMenuActions = _.filter(ContextMenuActions, shouldShowFilter); From e792362de4909e7ddbbe32e88f3b762a725c5453 Mon Sep 17 00:00:00 2001 From: Steven Maksym <131836113+StevenKKC@users.noreply.github.com> Date: Tue, 26 Sep 2023 17:41:04 -0400 Subject: [PATCH 13/14] Update src/pages/home/report/ContextMenu/ContextMenuActions.js Co-authored-by: Fedi Rajhi --- src/pages/home/report/ContextMenu/ContextMenuActions.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index c87326f07435..67c805b2eb75 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -98,13 +98,7 @@ export default [ shouldShow: (type, reportAction, isOffline) => { const isAttachment = ReportActionsUtils.isReportActionAttachment(reportAction); const messageHtml = lodashGet(reportAction, ['message', 0, 'html']); - return ( - isAttachment && - messageHtml !== CONST.ATTACHMENT_UPLOADING_MESSAGE_HTML && - reportAction.reportActionID && - !ReportActionsUtils.isMessageDeleted(reportAction) && - !isOffline - ); + return isAttachment && messageHtml !== CONST.ATTACHMENT_UPLOADING_MESSAGE_HTML && reportAction.reportActionID && !ReportActionsUtils.isMessageDeleted(reportAction) && !isOffline; }, onPress: (closePopover, {reportAction}) => { const message = _.last(lodashGet(reportAction, 'message', [{}])); From 629cb5310090b3eb19c396aca9f475fcd5954bde Mon Sep 17 00:00:00 2001 From: Steven Maksym <131836113+StevenKKC@users.noreply.github.com> Date: Tue, 26 Sep 2023 17:45:26 -0400 Subject: [PATCH 14/14] Update src/pages/home/report/ContextMenu/ContextMenuActions.js Co-authored-by: Fedi Rajhi --- src/pages/home/report/ContextMenu/ContextMenuActions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 67c805b2eb75..0607404c6f66 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -95,7 +95,7 @@ export default [ icon: Expensicons.Download, successTextTranslateKey: 'common.download', successIcon: Expensicons.Download, - shouldShow: (type, reportAction, isOffline) => { + shouldShow: (type, reportAction, isArchivedRoom, betas, anchor, isChronosReport, reportID, isPinnedChat, isUnreadChat, isOffline) => { const isAttachment = ReportActionsUtils.isReportActionAttachment(reportAction); const messageHtml = lodashGet(reportAction, ['message', 0, 'html']); return isAttachment && messageHtml !== CONST.ATTACHMENT_UPLOADING_MESSAGE_HTML && reportAction.reportActionID && !ReportActionsUtils.isMessageDeleted(reportAction) && !isOffline;