Skip to content

Commit

Permalink
update options context and add comments to effects
Browse files Browse the repository at this point in the history
  • Loading branch information
TMisiukiewicz committed Apr 10, 2024
1 parent dd5ecde commit 143b1a4
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/components/OptionListContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ function OptionsListContextProvider({reports, children}: OptionsListProviderProp
const personalDetails = usePersonalDetails();
const prevReports = usePrevious(reports);

/**
* This effect is used to update the options list when a report is updated.
*/
useEffect(() => {
// there is no need to update the options if the options are not initialized
if (!areOptionsInitialized.current) {
Expand Down Expand Up @@ -74,19 +77,16 @@ function OptionsListContextProvider({reports, children}: OptionsListProviderProp
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [reports]);

/**
* This effect is used to add a new report option to the list of options when a new report is added to the collection.
*/
useEffect(() => {
if (!areOptionsInitialized.current || !reports) {
return;
}
const missingReportId = Object.keys(reports).find((key) => prevReports && !(key in prevReports));

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

const report = reports[missingReportId];

if (!report) {
const report = missingReportId ? reports[missingReportId] : null;
if (!missingReportId || !report) {
return;
}

Expand All @@ -99,6 +99,9 @@ function OptionsListContextProvider({reports, children}: OptionsListProviderProp
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [reports]);

/**
* This effect is used to update the options list when personal details change.
*/
useEffect(() => {
// there is no need to update the options if the options are not initialized
if (!areOptionsInitialized.current) {
Expand Down

0 comments on commit 143b1a4

Please sign in to comment.