From 3afe1b81c5165502ea7fdeec673c50d0a5569a11 Mon Sep 17 00:00:00 2001 From: daledah Date: Mon, 21 Oct 2024 17:54:56 +0700 Subject: [PATCH 1/8] fix: make consistent behavior of displaying green line for assign task --- src/libs/ReportConnection.ts | 11 ++++++++++- src/libs/actions/Task.ts | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportConnection.ts b/src/libs/ReportConnection.ts index a390a5cea2a9..47da3921c7c0 100644 --- a/src/libs/ReportConnection.ts +++ b/src/libs/ReportConnection.ts @@ -48,4 +48,13 @@ function getAllReportsLength() { return Object.keys(allReports ?? {}).length; } -export {getAllReports, getAllReportsNameMap, getAllReportsLength}; +function updateReportLastReadTime(reportID: string, lastReadTime?: string) { + if (!allReports || !allReports[reportID]) { + return; + } + allReports[reportID] = { + ...allReports[reportID], + lastReadTime, + }; +} +export {getAllReports, getAllReportsNameMap, getAllReportsLength, updateReportLastReadTime}; diff --git a/src/libs/actions/Task.ts b/src/libs/actions/Task.ts index c5a2442048fc..43f45792376e 100644 --- a/src/libs/actions/Task.ts +++ b/src/libs/actions/Task.ts @@ -312,6 +312,8 @@ function createTaskAndNavigate( API.write(WRITE_COMMANDS.CREATE_TASK, parameters, {optimisticData, successData, failureData}); + ReportConnection.updateReportLastReadTime(parentReportID, currentTime); + if (!isCreatedUsingMarkdown) { clearOutTaskInfo(); Navigation.dismissModal(parentReportID); From 326332ef78eefe53dc48c3145e40f1928cd0ba51 Mon Sep 17 00:00:00 2001 From: daledah Date: Mon, 21 Oct 2024 18:20:49 +0700 Subject: [PATCH 2/8] fix: typecheck --- src/libs/ReportConnection.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportConnection.ts b/src/libs/ReportConnection.ts index 47da3921c7c0..7110f6ef3f22 100644 --- a/src/libs/ReportConnection.ts +++ b/src/libs/ReportConnection.ts @@ -49,11 +49,14 @@ function getAllReportsLength() { } function updateReportLastReadTime(reportID: string, lastReadTime?: string) { - if (!allReports || !allReports[reportID]) { + const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; + + if (!allReports || !report || !report.reportID) { return; } - allReports[reportID] = { - ...allReports[reportID], + + allReports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] = { + ...report, lastReadTime, }; } From 6054ad5d087c11f5905f0557ab14aaaf82cfa4da Mon Sep 17 00:00:00 2001 From: daledah Date: Tue, 22 Oct 2024 10:49:36 +0700 Subject: [PATCH 3/8] fix: update function --- src/libs/ReportConnection.ts | 6 +++--- src/libs/actions/Task.ts | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportConnection.ts b/src/libs/ReportConnection.ts index 7110f6ef3f22..523bc2ad5429 100644 --- a/src/libs/ReportConnection.ts +++ b/src/libs/ReportConnection.ts @@ -48,7 +48,7 @@ function getAllReportsLength() { return Object.keys(allReports ?? {}).length; } -function updateReportLastReadTime(reportID: string, lastReadTime?: string) { +function updateReportData(reportID: string, reportData?: Partial) { const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; if (!allReports || !report || !report.reportID) { @@ -57,7 +57,7 @@ function updateReportLastReadTime(reportID: string, lastReadTime?: string) { allReports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] = { ...report, - lastReadTime, + ...reportData, }; } -export {getAllReports, getAllReportsNameMap, getAllReportsLength, updateReportLastReadTime}; +export {getAllReports, getAllReportsNameMap, getAllReportsLength, updateReportData}; diff --git a/src/libs/actions/Task.ts b/src/libs/actions/Task.ts index 43f45792376e..664bdb3779a6 100644 --- a/src/libs/actions/Task.ts +++ b/src/libs/actions/Task.ts @@ -312,7 +312,9 @@ function createTaskAndNavigate( API.write(WRITE_COMMANDS.CREATE_TASK, parameters, {optimisticData, successData, failureData}); - ReportConnection.updateReportLastReadTime(parentReportID, currentTime); + ReportConnection.updateReportData(parentReportID, { + lastReadTime: currentTime, + }); if (!isCreatedUsingMarkdown) { clearOutTaskInfo(); From 7447a12ad7623f2aa0b6a682a666746718e84226 Mon Sep 17 00:00:00 2001 From: daledah Date: Wed, 30 Oct 2024 17:59:34 +0700 Subject: [PATCH 4/8] fix: marker appears briefly on ios --- src/libs/ReportConnection.ts | 10 +++++++++- src/libs/actions/Task.ts | 2 +- src/pages/home/report/ReportActionsList.tsx | 3 ++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportConnection.ts b/src/libs/ReportConnection.ts index 523bc2ad5429..d9f73f487774 100644 --- a/src/libs/ReportConnection.ts +++ b/src/libs/ReportConnection.ts @@ -60,4 +60,12 @@ function updateReportData(reportID: string, reportData?: Partial) { ...reportData, }; } -export {getAllReports, getAllReportsNameMap, getAllReportsLength, updateReportData}; + +function getReport(reportID: string) { + if (!reportID || !allReports) { + return; + } + return allReports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; +} + +export {getAllReports, getAllReportsNameMap, getAllReportsLength, updateReportData, getReport}; diff --git a/src/libs/actions/Task.ts b/src/libs/actions/Task.ts index 664bdb3779a6..1d53b22f7b9f 100644 --- a/src/libs/actions/Task.ts +++ b/src/libs/actions/Task.ts @@ -126,7 +126,7 @@ function createTaskAndNavigate( const optimisticAddCommentReport = ReportUtils.buildOptimisticTaskCommentReportAction(taskReportID, title, assigneeAccountID, `task for ${title}`, parentReportID); optimisticTaskReport.parentReportActionID = optimisticAddCommentReport.reportAction.reportActionID; - const currentTime = DateUtils.getDBTimeWithSkew(); + const currentTime = DateUtils.getDBTimeWithSkew(Date.now() + CONST.ANIMATED_TRANSITION); const lastCommentText = ReportUtils.formatReportLastMessageText(ReportActionsUtils.getReportActionText(optimisticAddCommentReport.reportAction)); const parentReport = ReportUtils.getReport(parentReportID); const optimisticParentReport = { diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index 541c5d44c6b2..e1ca7f4b1f23 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -22,6 +22,7 @@ import useWindowDimensions from '@hooks/useWindowDimensions'; import DateUtils from '@libs/DateUtils'; import Navigation from '@libs/Navigation/Navigation'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; +import * as ReportConnection from '@libs/ReportConnection'; import * as ReportUtils from '@libs/ReportUtils'; import Visibility from '@libs/Visibility'; import type {AuthScreensParamList} from '@navigation/types'; @@ -218,7 +219,7 @@ function ReportActionsList({ * - marks a message as read/unread * - reads a new message as it is received */ - const [unreadMarkerTime, setUnreadMarkerTime] = useState(report.lastReadTime ?? ''); + const [unreadMarkerTime, setUnreadMarkerTime] = useState(ReportConnection.getReport(report.reportID)?.lastReadTime ?? ''); useEffect(() => { setUnreadMarkerTime(report.lastReadTime ?? ''); From a8cc00e0c3c5c582dc1b5b97e00e9d25dcfd1a45 Mon Sep 17 00:00:00 2001 From: daledah Date: Thu, 31 Oct 2024 17:21:55 +0700 Subject: [PATCH 5/8] fix: apply suggested changes --- src/libs/actions/Task.ts | 2 +- src/pages/home/report/ReportActionsList.tsx | 17 ++++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/libs/actions/Task.ts b/src/libs/actions/Task.ts index 1d53b22f7b9f..664bdb3779a6 100644 --- a/src/libs/actions/Task.ts +++ b/src/libs/actions/Task.ts @@ -126,7 +126,7 @@ function createTaskAndNavigate( const optimisticAddCommentReport = ReportUtils.buildOptimisticTaskCommentReportAction(taskReportID, title, assigneeAccountID, `task for ${title}`, parentReportID); optimisticTaskReport.parentReportActionID = optimisticAddCommentReport.reportAction.reportActionID; - const currentTime = DateUtils.getDBTimeWithSkew(Date.now() + CONST.ANIMATED_TRANSITION); + const currentTime = DateUtils.getDBTimeWithSkew(); const lastCommentText = ReportUtils.formatReportLastMessageText(ReportActionsUtils.getReportActionText(optimisticAddCommentReport.reportAction)); const parentReport = ReportUtils.getReport(parentReportID); const optimisticParentReport = { diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index e1ca7f4b1f23..3470c7a4ce05 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -211,20 +211,15 @@ function ReportActionsList({ ); const prevSortedVisibleReportActionsObjects = usePrevious(sortedVisibleReportActionsObjects); - /** - * The timestamp for the unread marker. - * - * This should ONLY be updated when the user - * - switches reports - * - marks a message as read/unread - * - reads a new message as it is received - */ - const [unreadMarkerTime, setUnreadMarkerTime] = useState(ReportConnection.getReport(report.reportID)?.lastReadTime ?? ''); + const reportLastReadTime = useMemo(() => { + return ReportConnection.getReport(report.reportID)?.lastReadTime ?? report.lastReadTime ?? ''; + }, [report.reportID, report.lastReadTime]); + const [unreadMarkerTime, setUnreadMarkerTime] = useState(reportLastReadTime); useEffect(() => { - setUnreadMarkerTime(report.lastReadTime ?? ''); + setUnreadMarkerTime(reportLastReadTime); // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps - }, [report.reportID]); + }, [reportLastReadTime]); const prevUnreadMarkerReportActionID = useRef(null); /** From f3968e6dc34876f311e58be387282cc99296800d Mon Sep 17 00:00:00 2001 From: daledah Date: Thu, 31 Oct 2024 17:23:31 +0700 Subject: [PATCH 6/8] fix: change effect deps --- src/pages/home/report/ReportActionsList.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index 3470c7a4ce05..1de3db1baa37 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -219,7 +219,7 @@ function ReportActionsList({ setUnreadMarkerTime(reportLastReadTime); // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps - }, [reportLastReadTime]); + }, [report.reportID]); const prevUnreadMarkerReportActionID = useRef(null); /** From 320df1c2306bedb76cf6afe8330fb113302ea266 Mon Sep 17 00:00:00 2001 From: daledah Date: Thu, 31 Oct 2024 17:27:38 +0700 Subject: [PATCH 7/8] fix: keep comment --- src/pages/home/report/ReportActionsList.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index 1de3db1baa37..68cafaa2edf8 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -214,6 +214,15 @@ function ReportActionsList({ const reportLastReadTime = useMemo(() => { return ReportConnection.getReport(report.reportID)?.lastReadTime ?? report.lastReadTime ?? ''; }, [report.reportID, report.lastReadTime]); + + /** + * The timestamp for the unread marker. + * + * This should ONLY be updated when the user + * - switches reports + * - marks a message as read/unread + * - reads a new message as it is received + */ const [unreadMarkerTime, setUnreadMarkerTime] = useState(reportLastReadTime); useEffect(() => { setUnreadMarkerTime(reportLastReadTime); From 597886a6c5a9059b4f11d5f51059c4bbd83c0194 Mon Sep 17 00:00:00 2001 From: daledah Date: Fri, 1 Nov 2024 10:14:54 +0700 Subject: [PATCH 8/8] fix: use getReport --- src/libs/ReportConnection.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libs/ReportConnection.ts b/src/libs/ReportConnection.ts index d9f73f487774..f9f913d59beb 100644 --- a/src/libs/ReportConnection.ts +++ b/src/libs/ReportConnection.ts @@ -48,8 +48,15 @@ function getAllReportsLength() { return Object.keys(allReports ?? {}).length; } +function getReport(reportID: string) { + if (!reportID || !allReports) { + return; + } + return allReports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; +} + function updateReportData(reportID: string, reportData?: Partial) { - const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; + const report = getReport(reportID); if (!allReports || !report || !report.reportID) { return; @@ -61,11 +68,4 @@ function updateReportData(reportID: string, reportData?: Partial) { }; } -function getReport(reportID: string) { - if (!reportID || !allReports) { - return; - } - return allReports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; -} - export {getAllReports, getAllReportsNameMap, getAllReportsLength, updateReportData, getReport};