From 5ff87f07b1f36e7f7cdb3659f4bdd9e7fe99536d Mon Sep 17 00:00:00 2001 From: Mateusz Filipowicz Date: Mon, 3 Aug 2020 09:02:33 +0200 Subject: [PATCH] fix: :bug: fix incorrect previous / next pages calculation --- src/components/Navigation/Navigation.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/components/Navigation/Navigation.js b/src/components/Navigation/Navigation.js index bf5348b3..3be8e40d 100644 --- a/src/components/Navigation/Navigation.js +++ b/src/components/Navigation/Navigation.js @@ -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 };