Files
developer-roadmap/components/detailed-roadmap/index.js

124 lines
4.2 KiB
JavaScript
Raw Normal View History

2019-11-30 18:12:07 +04:00
import { useState } from 'react';
import classNames from 'classnames';
2019-11-30 17:07:50 +04:00
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
2019-11-30 17:15:56 +04:00
import { faFacebookSquare, faTwitterSquare, faRedditSquare, faGithubSquare } from '@fortawesome/free-brands-svg-icons'
2019-12-01 23:51:23 +04:00
import {
PageHeader,
RoadmapMeta,
ShareRoadmap,
Sidebar,
Summary,
SummaryContainer,
MobileNavHeader,
SidebarButton,
MobileSidebar,
MobileSidebarWrap,
PageTitle,
PageDetail
} from './style';
2019-11-30 18:12:07 +04:00
import { faBars } from '@fortawesome/free-solid-svg-icons'
2019-11-30 17:07:50 +04:00
import { getFacebookShareUrl } from 'lib/url';
import { ShareIcon } from 'components/share-icon';
2019-11-30 17:15:56 +04:00
import { getRedditShareUrl, getTwitterShareUrl } from 'lib/url';
import siteConfig from "storage/site";
2019-12-01 17:06:53 +04:00
import MdRenderer from '../md-renderer';
2019-11-30 10:00:44 +04:00
2019-11-30 14:33:22 +04:00
const DetailedRoadmap = ({ roadmap }) => {
2019-11-30 18:12:07 +04:00
const [menuActive, setMenuState] = useState(false);
2019-12-01 15:01:22 +04:00
const {
sidebar = {},
2019-12-01 15:46:13 +04:00
page: currentPage = {},
author = {}
2019-12-01 15:01:22 +04:00
} = roadmap;
2019-11-30 18:12:07 +04:00
2019-12-01 15:01:22 +04:00
const roadmapPages = Object.keys(sidebar || {}).map(groupTitle => {
2019-12-01 15:49:13 +04:00
if (groupTitle.startsWith('_')) {
return;
}
return (
<div className='links-group'>
<h3>{ groupTitle }</h3>
<ul>
2019-12-01 15:01:22 +04:00
{ sidebar[groupTitle].map(page => {
2019-12-01 16:16:45 +04:00
const isActivePage = page.url === currentPage.url;
// e.g. /frontend should mark `/frontend/summary` as active
const isSummaryPage = page.url === `${currentPage.url}/summary`;
return (
2019-12-01 16:16:45 +04:00
<li className={classNames({ active: isActivePage || isSummaryPage })}>
<a href={ page.url }>
<span className="bullet"></span>
{ page.title }
</a>
</li>
);
2019-11-30 17:07:50 +04:00
}) }
</ul>
</div>
);
});
2019-12-01 17:06:53 +04:00
const filePath = currentPage.path.replace(/^\//, '');
const RoadmapContent = require(`../../storage/${filePath}`).default;
return (
2019-11-30 17:07:50 +04:00
<SummaryContainer>
<PageHeader className="border-top border-bottom text-center text-md-left">
<div className="container d-flex align-items-center flex-column flex-md-row">
<RoadmapMeta>
<h3>{ roadmap.title }</h3>
2019-12-01 15:46:13 +04:00
<p>
Roadmap contributed by <a href={ author.url } target="_blank">{ author.name }</a>
{ roadmap.contributorsCount > 1 && ` and <a href="${roadmap.contributorsUrl}">${roadmap.contributorsCount} others</a>`}</p>
2019-11-30 17:07:50 +04:00
</RoadmapMeta>
<ShareRoadmap className="mt-2 mt-md-0">
2019-11-30 17:15:56 +04:00
<ShareIcon href={ siteConfig.url.repo } target="_blank">
<FontAwesomeIcon icon={ faGithubSquare } />
</ShareIcon>
2019-11-30 17:07:50 +04:00
<ShareIcon href={ getFacebookShareUrl({ text: roadmap.title, url: roadmap.url }) } target="_blank">
<FontAwesomeIcon icon={ faFacebookSquare } />
</ShareIcon>
<ShareIcon href={ getTwitterShareUrl({ text: roadmap.title, url: roadmap.url }) } target="_blank">
<FontAwesomeIcon icon={ faTwitterSquare } />
</ShareIcon>
<ShareIcon href={ getRedditShareUrl({ text: roadmap.title, url: roadmap.url }) } target="_blank">
<FontAwesomeIcon icon={ faRedditSquare } />
</ShareIcon>
</ShareRoadmap>
</div>
</PageHeader>
2019-11-30 18:12:07 +04:00
<MobileNavHeader className="border-bottom d-block d-md-none">
<div className="container">
<SidebarButton onClick={() => setMenuState((prevMenuActive) => !prevMenuActive)}>
<FontAwesomeIcon icon={ faBars } />
2019-12-01 15:01:22 +04:00
{ currentPage.title }
2019-11-30 18:12:07 +04:00
</SidebarButton>
</div>
<MobileSidebarWrap className={classNames({ visible: menuActive })}>
<div className="container">
<MobileSidebar>
{ roadmapPages }
</MobileSidebar>
</div>
</MobileSidebarWrap>
</MobileNavHeader>
2019-11-30 17:07:50 +04:00
<Summary className="container">
2019-11-30 18:12:07 +04:00
<Sidebar className="sidebar d-none d-md-block">
2019-11-30 17:07:50 +04:00
{ roadmapPages }
</Sidebar>
2019-12-01 23:51:23 +04:00
<PageDetail>
<PageTitle>{ currentPage.title }</PageTitle>
2019-12-01 17:06:53 +04:00
<MdRenderer>
<RoadmapContent />
</MdRenderer>
2019-12-01 23:51:23 +04:00
</PageDetail>
</Summary>
</SummaryContainer>
)
};
2019-11-30 14:33:22 +04:00
export default DetailedRoadmap;