From 7e9d477bc90da3fdc4225afd3efe6e37680477dd Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Fri, 1 Nov 2019 02:27:06 +0400 Subject: [PATCH] Roadmap summary section --- components/roadmap-summary/index.js | 7 ++++++- lib/roadmap.js | 5 ++++- pages/[fallback]/index.js | 2 +- pages/roadmaps/[roadmap]/index.js | 5 +++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/components/roadmap-summary/index.js b/components/roadmap-summary/index.js index 775281c7c..6fa74137c 100644 --- a/components/roadmap-summary/index.js +++ b/components/roadmap-summary/index.js @@ -12,6 +12,11 @@ import { VersionList, } from './style'; +const isActiveRoadmap = (loadedVersion, roadmapVersion) => ( + (loadedVersion === roadmapVersion) || + (loadedVersion === 'latest' && parseInt(roadmapVersion, 10) === (new Date()).getFullYear()) +); + const RoadmapSummary = ({ roadmap }) => (
@@ -21,7 +26,7 @@ const RoadmapSummary = ({ roadmap }) => ( { (roadmap.versions || []).map(versionItem => ( { versionItem } Version )) } diff --git a/lib/roadmap.js b/lib/roadmap.js index c3af27142..c4078fa53 100644 --- a/lib/roadmap.js +++ b/lib/roadmap.js @@ -19,7 +19,10 @@ export const getRequestedRoadmap = req => { legacyUrlWithoutVersion, ]; - const foundRoadmap = roadmaps.find(roadmap => urlToSlugList.includes(roadmap.slug)) || {}; + const foundRoadmap = roadmaps.find(roadmap => urlToSlugList.includes(roadmap.slug)); + if (!foundRoadmap) { + return null; + } return { ...foundRoadmap, diff --git a/pages/[fallback]/index.js b/pages/[fallback]/index.js index 3dc355bed..6880a9214 100644 --- a/pages/[fallback]/index.js +++ b/pages/[fallback]/index.js @@ -9,7 +9,7 @@ const OldRoadmap = ({ roadmap }) => { return } - return ; + return ; }; OldRoadmap.getInitialProps = serverOnlyProps(({ req }) => { diff --git a/pages/roadmaps/[roadmap]/index.js b/pages/roadmaps/[roadmap]/index.js index d020a9e3f..53a410fee 100644 --- a/pages/roadmaps/[roadmap]/index.js +++ b/pages/roadmaps/[roadmap]/index.js @@ -1,3 +1,4 @@ +import Error from 'next/error'; import DefaultLayout from '../../../layouts/default'; import { serverOnlyProps } from '../../../lib/server'; import PageHeader from '../../../components/page-header'; @@ -6,6 +7,10 @@ import { getRequestedRoadmap } from '../../../lib/roadmap'; import RoadmapSummary from '../../../components/roadmap-summary'; const Roadmap = ({ roadmap }) => { + if (!roadmap) { + return + } + return (