From 537ffc365eeaca7824ddb008eb470c6e912e9bad Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Thu, 9 Dec 2021 16:39:09 +0100 Subject: [PATCH] Marking progress on roadmap --- .../md-renderer/mdx-components/heading.tsx | 12 ++-- components/roadmap/content-drawer.tsx | 67 +++++++++++++++++-- lib/renderer/renderer.ts | 13 +++- lib/renderer/utils.ts | 4 ++ pages/[roadmap]/interactive.tsx | 17 +++-- pages/_app.tsx | 5 ++ 6 files changed, 97 insertions(+), 21 deletions(-) diff --git a/components/md-renderer/mdx-components/heading.tsx b/components/md-renderer/mdx-components/heading.tsx index 1bda10f03..ea94a5e40 100644 --- a/components/md-renderer/mdx-components/heading.tsx +++ b/components/md-renderer/mdx-components/heading.tsx @@ -70,12 +70,12 @@ const H6 = styled(H1).attrs({ as: 'h6' })` `; const Headings = { - h1: linkify(H1), - h2: linkify(H2), - h3: linkify(H3), - h4: linkify(H4), - h5: linkify(H5), - h6: linkify(H6) + h1: H1, + h2: H2, + h3: H3, + h4: H4, + h5: H5, + h6: H6 }; export default Headings; diff --git a/components/roadmap/content-drawer.tsx b/components/roadmap/content-drawer.tsx index 9d179809d..42b5b6c65 100644 --- a/components/roadmap/content-drawer.tsx +++ b/components/roadmap/content-drawer.tsx @@ -1,7 +1,8 @@ -import { Box, CloseButton } from '@chakra-ui/react'; +import { Box, Button, Flex, Text } from '@chakra-ui/react'; import { RemoveScroll } from 'react-remove-scroll'; import { RoadmapType } from '../../lib/roadmap'; import RoadmapGroup from '../../pages/[roadmap]/[group]'; +import { CheckIcon, CloseIcon, RepeatIcon } from '@chakra-ui/icons'; type ContentDrawerProps = { roadmap: RoadmapType; @@ -15,6 +16,8 @@ export function ContentDrawer(props: ContentDrawerProps) { return null; } + const isDone = localStorage.getItem(groupId) === 'done'; + return ( - + > + {!isDone && ( + + )} + {isDone && ( + + )} + + diff --git a/lib/renderer/renderer.ts b/lib/renderer/renderer.ts index 35c1afd30..5a495b750 100644 --- a/lib/renderer/renderer.ts +++ b/lib/renderer/renderer.ts @@ -1,4 +1,8 @@ -import { getRGBFromDecimalColor, makeSVGElement } from './utils'; +import { + getRGBFromDecimalColor, + makeSVGElement, + removeSortingInfo, +} from './utils'; import { ARROW_WIDTH, BORDER_WIDTH, @@ -257,12 +261,17 @@ export class Renderer { __group__(control: any, container: any) { const controlName = control?.properties?.controlName; + const groupId = removeSortingInfo(controlName); + const isDone = localStorage.getItem(groupId) === 'done'; let group = makeSVGElement( 'g', { ...(controlName - ? { class: 'clickable-group', 'data-group-id': controlName } + ? { + class: `clickable-group ${isDone ? 'done' : ''}`, + 'data-group-id': controlName, + } : {}), }, container diff --git a/lib/renderer/utils.ts b/lib/renderer/utils.ts index 2e98c8189..9618d5aca 100644 --- a/lib/renderer/utils.ts +++ b/lib/renderer/utils.ts @@ -1,3 +1,7 @@ +export function removeSortingInfo(groupId: string) { + return (groupId || '').replace(/^\d+-/, ''); +} + export function getRGBFromDecimalColor(color: number) { let red = (color >> 16) & 0xff; let green = (color >> 8) & 0xff; diff --git a/pages/[roadmap]/interactive.tsx b/pages/[roadmap]/interactive.tsx index 140c38b0c..c54a91b1e 100644 --- a/pages/[roadmap]/interactive.tsx +++ b/pages/[roadmap]/interactive.tsx @@ -12,6 +12,7 @@ import { RoadmapPageHeader } from '../../components/roadmap/roadmap-page-header' import { ContentDrawer } from '../../components/roadmap/content-drawer'; import { RoadmapError } from '../../components/roadmap/roadmap-error'; import { RoadmapLoader } from '../../components/roadmap/roadmap-loader'; +import { removeSortingInfo } from '../../lib/renderer/utils'; type RoadmapProps = { roadmap: RoadmapType; @@ -19,10 +20,6 @@ type RoadmapProps = { export function InteractiveRoadmapRenderer(props: RoadmapProps) { const { roadmap } = props; - if (!roadmap.jsonUrl) { - return null; - } - const { loading: isLoading, error: hasErrorLoading, get } = useFetch(); const roadmapRef = useRef(null); @@ -33,6 +30,10 @@ export function InteractiveRoadmapRenderer(props: RoadmapProps) { const [hasErrorRendering, setHasErrorRendering] = useState(false); useEffect(() => { + if (!roadmap.jsonUrl) { + return; + } + get(roadmap.jsonUrl) .then((roadmapJson) => { setRoadmapJson(roadmapJson); @@ -65,7 +66,7 @@ export function InteractiveRoadmapRenderer(props: RoadmapProps) { // e.g. 100-internet:how-does-the-internet-work // will be translated to `internet:how-does-the-internet-work` - setGroupId(groupId.replace(/^\d+-/, '')); + setGroupId(removeSortingInfo(groupId)); } window.addEventListener('keydown', keydownListener); @@ -104,8 +105,12 @@ export function InteractiveRoadmapRenderer(props: RoadmapProps) { }); }, [roadmapJson]); + if (!roadmap.jsonUrl) { + return null; + } + if (hasErrorLoading || hasErrorRendering) { - return + return ; } return ( diff --git a/pages/_app.tsx b/pages/_app.tsx index fcd7ac9c8..245a60b87 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -43,6 +43,11 @@ const GlobalStyles = css` &:hover > [fill="rgb(153,153,153)"] { fill: #646464; } &:hover > [fill="rgb(255,255,255)"] { fill: #d7d7d7; } } + + svg .done { + & rect { fill: #cbcbcb; } + & text { text-decoration: line-through; } + } `;