-
Notifications
You must be signed in to change notification settings - Fork 3.9k
add JS snippet to mark reports on a policy as read #38194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1d174aa
99010cc
06658eb
096f90d
6da0e23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // eslint-disable-next-line you-dont-need-lodash-underscore/each | ||
| import Onyx from 'react-native-onyx'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type {Report} from '@src/types/onyx'; | ||
| import * as ReportActionFile from './actions/Report'; | ||
| import * as ReportUtils from './ReportUtils'; | ||
|
|
||
| export default function markAllPolicyReportsAsRead(policyID: string) { | ||
| const connectionID = Onyx.connect({ | ||
| key: ONYXKEYS.COLLECTION.REPORT, | ||
| waitForCollectionCallback: true, | ||
| callback: (allReports) => { | ||
| if (!allReports) { | ||
| return; | ||
| } | ||
|
|
||
| let delay = 0; | ||
| Object.keys(allReports).forEach((key: string) => { | ||
| const report: Report | null | undefined = allReports[key]; | ||
| if (report?.policyID !== policyID || !ReportUtils.isUnread(report)) { | ||
| return; | ||
| } | ||
|
|
||
| setTimeout(() => { | ||
| ReportActionFile.readNewestAction(report?.reportID); | ||
| }, delay); | ||
|
|
||
| delay += 1000; | ||
|
Comment on lines
+24
to
+28
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👋 @marcaaron or @rlinoz Do you recall why we are using a timeout here? We are looking to add similar functionality to a keyboard shortcut and wanted to reuse same logic but the timeout is a problem as it will delay even optimistic actions. Is this done to prevent server flooding or something else?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, here is a slack thread for moving this logic to BE instead https://expensify.slack.com/archives/C01GTK53T8Q/p1746861626079909
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it's just to avoid hammering the server with requests since some users who requested this feature had thousands of reports. Though, I think we probably have solve that problem by now. |
||
| }); | ||
| Onyx.disconnect(connectionID); | ||
| }, | ||
| }); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.