diff --git a/src/libs/ReportConnection.ts b/src/libs/ReportConnection.ts index a390a5cea2a9..f9f913d59beb 100644 --- a/src/libs/ReportConnection.ts +++ b/src/libs/ReportConnection.ts @@ -48,4 +48,24 @@ function getAllReportsLength() { return Object.keys(allReports ?? {}).length; } -export {getAllReports, getAllReportsNameMap, getAllReportsLength}; +function getReport(reportID: string) { + if (!reportID || !allReports) { + return; + } + return allReports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; +} + +function updateReportData(reportID: string, reportData?: Partial) { + const report = getReport(reportID); + + if (!allReports || !report || !report.reportID) { + return; + } + + allReports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] = { + ...report, + ...reportData, + }; +} + +export {getAllReports, getAllReportsNameMap, getAllReportsLength, updateReportData, getReport}; diff --git a/src/libs/actions/Task.ts b/src/libs/actions/Task.ts index c5a2442048fc..664bdb3779a6 100644 --- a/src/libs/actions/Task.ts +++ b/src/libs/actions/Task.ts @@ -312,6 +312,10 @@ function createTaskAndNavigate( API.write(WRITE_COMMANDS.CREATE_TASK, parameters, {optimisticData, successData, failureData}); + ReportConnection.updateReportData(parentReportID, { + lastReadTime: currentTime, + }); + if (!isCreatedUsingMarkdown) { clearOutTaskInfo(); Navigation.dismissModal(parentReportID); diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index 541c5d44c6b2..68cafaa2edf8 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'; @@ -210,6 +211,10 @@ function ReportActionsList({ ); const prevSortedVisibleReportActionsObjects = usePrevious(sortedVisibleReportActionsObjects); + const reportLastReadTime = useMemo(() => { + return ReportConnection.getReport(report.reportID)?.lastReadTime ?? report.lastReadTime ?? ''; + }, [report.reportID, report.lastReadTime]); + /** * The timestamp for the unread marker. * @@ -218,9 +223,9 @@ 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(reportLastReadTime); useEffect(() => { - setUnreadMarkerTime(report.lastReadTime ?? ''); + setUnreadMarkerTime(reportLastReadTime); // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps }, [report.reportID]);