Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Commit

Permalink
fix: 🐛 fix incorrect previous / next pages calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
filipowm committed Aug 3, 2020
1 parent b005982 commit 5ff87f0
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/components/Navigation/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,20 @@ const calculateNavigation = (edges) => {
};
};

function flat(acc, val) {
const parent = acc.concat(val.children);
const child = val.children.reduce(flat, []);
return parent.concat(child);
const flat = (parent, acc) => {
parent.children.forEach(child => {
acc.push(child);
flat(child, acc);
})
}

const calculateFlatNavigation = (edges) => {
const navigation = calculateNavigation(edges);
return navigation.children.reduce(flat, []);
const acc = [];
navigation.children.forEach(group => {
flat(group, acc)
})
return acc;;
};

export { getNavigationData, calculateNavigation, calculateFlatNavigation };

0 comments on commit 5ff87f0

Please sign in to comment.