Skip to content

Commit f4f7f3d

Browse files
committed
refactor code
1 parent 9846326 commit f4f7f3d

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

src/hooks/usePriorityChange.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import usePrevious from './usePrevious';
77

88
function usePriorityMode() {
99
const [priorityMode] = useOnyx(ONYXKEYS.NVP_PRIORITY_MODE, {canBeMissing: true});
10-
const [allReportsDraftComment] = useOnyx(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT, {canBeMissing: true});
10+
const [allReportsWithDraftComments] = useOnyx(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT, {canBeMissing: true});
1111
const prevPriorityMode = usePrevious(priorityMode);
1212

1313
useEffect(() => {
@@ -16,8 +16,8 @@ function usePriorityMode() {
1616
}
1717
// When a user switches their priority mode away from #focus/GSD we need to call openApp
1818
// to fetch all their chats because #focus mode works with a subset of a user's chats.
19-
openApp(false, allReportsDraftComment);
20-
}, [priorityMode, allReportsDraftComment, prevPriorityMode]);
19+
openApp(false, allReportsWithDraftComments);
20+
}, [priorityMode, allReportsWithDraftComments, prevPriorityMode]);
2121
}
2222

2323
export default usePriorityMode;

src/libs/actions/App.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,12 @@ function getPolicyParamsForOpenOrReconnect(): Promise<PolicyParamsForOpenOrRecon
245245
/**
246246
* Returns the Onyx data that is used for both the OpenApp and ReconnectApp API commands.
247247
*/
248-
function getOnyxDataForOpenOrReconnect(isOpenApp = false, isFullReconnect = false, shouldKeepPublicRooms = false, allReportsDraftComment?: Record<string, string | undefined>): OnyxData {
248+
function getOnyxDataForOpenOrReconnect(
249+
isOpenApp = false,
250+
isFullReconnect = false,
251+
shouldKeepPublicRooms = false,
252+
allReportsWithDraftComments?: Record<string, string | undefined>,
253+
): OnyxData {
249254
const result: OnyxData = {
250255
optimisticData: [
251256
{
@@ -308,12 +313,12 @@ function getOnyxDataForOpenOrReconnect(isOpenApp = false, isFullReconnect = fals
308313

309314
// Find all reports that have a non-null draft comment and map them to their corresponding report objects from allReports
310315
// This ensures that any report with a draft comment is preserved in Onyx even if it doesn’t contain chat history
311-
const reportsHaveDraftComments = Object.entries(allReportsDraftComment ?? {})
316+
const reportsWithDraftComments = Object.entries(allReportsWithDraftComments ?? {})
312317
.filter(([, value]) => value !== null)
313318
.map(([key]) => key.replace(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT, ''))
314319
.map((reportID) => allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]);
315320

316-
reportsHaveDraftComments?.forEach((report) => {
321+
reportsWithDraftComments?.forEach((report) => {
317322
result.successData?.push({
318323
onyxMethod: Onyx.METHOD.MERGE,
319324
key: `${ONYXKEYS.COLLECTION.REPORT}${report?.reportID}`,
@@ -329,10 +334,10 @@ function getOnyxDataForOpenOrReconnect(isOpenApp = false, isFullReconnect = fals
329334
/**
330335
* Fetches data needed for app initialization
331336
*/
332-
function openApp(shouldKeepPublicRooms = false, allReportsDraftComment?: Record<string, string | undefined>) {
337+
function openApp(shouldKeepPublicRooms = false, allReportsWithDraftComments?: Record<string, string | undefined>) {
333338
return getPolicyParamsForOpenOrReconnect().then((policyParams: PolicyParamsForOpenOrReconnect) => {
334339
const params: OpenAppParams = {enablePriorityModeFilter: true, ...policyParams};
335-
return API.writeWithNoDuplicatesConflictAction(WRITE_COMMANDS.OPEN_APP, params, getOnyxDataForOpenOrReconnect(true, undefined, shouldKeepPublicRooms, allReportsDraftComment));
340+
return API.writeWithNoDuplicatesConflictAction(WRITE_COMMANDS.OPEN_APP, params, getOnyxDataForOpenOrReconnect(true, undefined, shouldKeepPublicRooms, allReportsWithDraftComments));
336341
});
337342
}
338343

0 commit comments

Comments
 (0)