2018-05-08 22:22:35 +03:00
|
|
|
import React from 'react';
|
|
|
|
import remcalc from 'remcalc';
|
|
|
|
import styled from 'styled-components';
|
|
|
|
|
|
|
|
const BottomNav = styled.div`
|
|
|
|
display: flex;
|
|
|
|
justify-content: space-between;
|
|
|
|
margin: 36px 0;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const Link = styled.a`
|
|
|
|
color: #3b46cc;
|
|
|
|
font-size: 15px;
|
|
|
|
line-height: 24px;
|
|
|
|
text-decoration: none;
|
|
|
|
`;
|
|
|
|
|
2018-05-09 18:27:36 +03:00
|
|
|
const previousAndNextSections = data => {
|
|
|
|
const items = data.items;
|
|
|
|
const link = data.link;
|
|
|
|
const sectionNames = items.map(item => item.name);
|
2018-05-09 18:52:14 +03:00
|
|
|
const index =
|
|
|
|
data.link === '/' ? 0 : items.findIndex(item => item.name === link);
|
2018-05-09 18:27:36 +03:00
|
|
|
let ret = { prevSection: null, nextSection: null };
|
|
|
|
|
|
|
|
if (index > -1) {
|
|
|
|
ret = {
|
|
|
|
prevSection: index !== 0 ? sectionNames[index - 1] : null,
|
|
|
|
nextSection:
|
|
|
|
index < sectionNames.length - 1 ? sectionNames[index + 1] : null
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
items.map(section => {
|
|
|
|
if (section.components.length > 0 && section.components[0].slug) {
|
|
|
|
section.components.map(subSection => {
|
|
|
|
if (subSection.slug === link.toLowerCase()) {
|
|
|
|
ret = previousAndNextSections({ items, link: section.name });
|
|
|
|
}
|
|
|
|
return subSection;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return section;
|
|
|
|
});
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
2018-05-08 22:22:35 +03:00
|
|
|
export default props => {
|
2018-05-09 18:27:36 +03:00
|
|
|
const selectedIndex = previousAndNextSections({
|
|
|
|
items: props.items,
|
|
|
|
link: props.link
|
|
|
|
});
|
2018-05-08 22:22:35 +03:00
|
|
|
|
2018-05-09 18:27:36 +03:00
|
|
|
if (!props.items.length) {
|
2018-05-08 22:22:35 +03:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<BottomNav>
|
|
|
|
<div>
|
2018-05-09 18:27:36 +03:00
|
|
|
{selectedIndex.prevSection && (
|
|
|
|
<Link href={`/#!/${selectedIndex.prevSection}`}>
|
|
|
|
← {selectedIndex.prevSection}
|
2018-05-08 22:22:35 +03:00
|
|
|
</Link>
|
2018-05-09 18:27:36 +03:00
|
|
|
)}
|
2018-05-08 22:22:35 +03:00
|
|
|
</div>
|
|
|
|
<div>
|
2018-05-09 18:27:36 +03:00
|
|
|
{selectedIndex.nextSection && (
|
|
|
|
<Link href={`/#!/${selectedIndex.nextSection}`}>
|
|
|
|
{selectedIndex.nextSection} →
|
2018-05-08 22:22:35 +03:00
|
|
|
</Link>
|
2018-05-09 18:27:36 +03:00
|
|
|
)}
|
2018-05-08 22:22:35 +03:00
|
|
|
</div>
|
|
|
|
</BottomNav>
|
|
|
|
);
|
|
|
|
};
|