Skip to content

Commit

Permalink
update options list when new new report is added to the list
Browse files Browse the repository at this point in the history
  • Loading branch information
TMisiukiewicz committed Apr 8, 2024
1 parent 7774f34 commit ceff19e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/components/OptionListContextProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {createContext, useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react';
import {withOnyx} from 'react-native-onyx';
import type {OnyxCollection} from 'react-native-onyx';
import usePrevious from '@hooks/usePrevious';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import type {OptionList} from '@libs/OptionsListUtils';
import * as ReportUtils from '@libs/ReportUtils';
Expand Down Expand Up @@ -42,7 +43,9 @@ function OptionsListContextProvider({reports, children}: OptionsListProviderProp
reports: [],
personalDetails: [],
});

const personalDetails = usePersonalDetails();
const prevReports = usePrevious(reports);

useEffect(() => {
// there is no need to update the options if the options are not initialized
Expand Down Expand Up @@ -71,6 +74,31 @@ function OptionsListContextProvider({reports, children}: OptionsListProviderProp
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [reports]);

useEffect(() => {
if (!areOptionsInitialized.current || !reports) {
return;
}
const missingReportId = Object.keys(reports).find((key) => prevReports && !(key in prevReports));

This comment has been minimized.

Copy link
@c3024

c3024 May 7, 2024

Creating a workspace creates three reports viz policy expense chat, admins room and announce room. But this finds only the first report missing which caused this issue here Expensify#40406


if (!missingReportId || !reports[missingReportId]) {
return;
}

const report = reports[missingReportId];

if (!report) {
return;
}

const reportOption = OptionsListUtils.createOptionFromReport(report, personalDetails);
setOptions((prevOptions) => {
const newOptions = {...prevOptions};
newOptions.reports.push(reportOption);
return newOptions;
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [reports]);

useEffect(() => {
// there is no need to update the options if the options are not initialized
if (!areOptionsInitialized.current) {
Expand Down

0 comments on commit ceff19e

Please sign in to comment.