Skip to content

Commit

Permalink
refactor: use map insterad of reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
danipran committed May 7, 2024
1 parent 0fbb9c8 commit 5ba40b5
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/utils/hearingEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,29 +238,24 @@ export const parseCollection = (featureCollection) => {
export const prepareSection = (section) => ({
...section,
id: '',
images: section.images.reduce((images, image) => [...images, { ...image, id: '', reference_id: image.id }], []),
files: section.files.reduce(
(files, file) => [...files, { ...file, id: file.isNew ? file.id : '', reference_id: file.isNew ? '' : file.id }],
[],
),
questions: section.questions.reduce(
(questions, question) => [
...questions,
{
...question,
id: '',
options: question?.options.reduce((options, option) => [...options, { ...option, id: '' }], []),
},
],
[],
),
images: section.images.map((image) => ({ ...image, id: '', reference_id: image.id })),
files: section.files.map((file) => ({
...file,
id: file.isNew ? file.id : '',
reference_id: file.isNew ? '' : file.id,
})),
questions: section.questions.map((question) => ({
...question,
id: '',
options: question?.options.map((option) => ({ ...option, id: '' })),
})),
});

export const prepareHearingForSave = (hearing) => {
// Scrub ids from sections and their children
let preparedHearing = {
...hearing,
sections: hearing.sections.reduce((sections, section) => [...sections, prepareSection(section)], []),
sections: hearing.sections.map((section) => ({ ...prepareSection(section) })),
};

// Add geojson to cleanedHearing
Expand Down

0 comments on commit 5ba40b5

Please sign in to comment.