11import React , { useState } from "react" ;
22import styled from "styled-components" ;
3+ import { useToggle } from "react-use" ;
34import HowItWorks from "./HowItWorks" ;
45import PnkLogoAndTitle from "./PnkLogoAndTitle" ;
56import WhatDoINeed from "./WhatDoINeed" ;
7+ import Staking from "../Staking" ;
8+ import BinaryVoting from "../BinaryVoting" ;
9+ import RankedVoting from "../RankedVoting" ;
10+ import Appeal from "../Appeal" ;
11+ import JurorLevels from "../JurorLevels" ;
612import Template , { Title , ParagraphsContainer , LeftContentContainer } from "../Template" ;
713
814const StyledLabel = styled . label `
@@ -44,7 +50,12 @@ const leftPageContents = [
4450
4551const rightPageComponents = [ ( ) => < PnkLogoAndTitle /> , ( ) => < WhatDoINeed /> , ( ) => < HowItWorks /> ] ;
4652
47- const LeftContent : React . FC < { currentPage : number } > = ( { currentPage } ) => {
53+ const extractGuideName = ( linkText ) => linkText . split ( ". " ) [ 1 ] ;
54+
55+ const LeftContent : React . FC < { currentPage : number ; toggleMiniGuide : ( guideName : string ) => void } > = ( {
56+ currentPage,
57+ toggleMiniGuide,
58+ } ) => {
4859 const { title, paragraphs, links } = leftPageContents [ currentPage - 1 ] ;
4960
5061 return (
@@ -57,7 +68,9 @@ const LeftContent: React.FC<{ currentPage: number }> = ({ currentPage }) => {
5768 </ ParagraphsContainer >
5869 < LinksContainer >
5970 { links . map ( ( link , index ) => (
60- < StyledLabel key = { index } > { link } </ StyledLabel >
71+ < StyledLabel key = { index } onClick = { ( ) => toggleMiniGuide ( extractGuideName ( link ) ) } >
72+ { link }
73+ </ StyledLabel >
6174 ) ) }
6275 </ LinksContainer >
6376 </ LeftContentContainer >
@@ -76,17 +89,52 @@ interface IOnboarding {
7689
7790const Onboarding : React . FC < IOnboarding > = ( { toggleIsOnboardingMiniGuidesOpen } ) => {
7891 const [ currentPage , setCurrentPage ] = useState ( 1 ) ;
92+ const [ isStakingMiniGuideOpen , toggleStakingMiniGuide ] = useToggle ( false ) ;
93+ const [ isBinaryVotingMiniGuideOpen , toggleBinaryVotingMiniGuide ] = useToggle ( false ) ;
94+ const [ isRankedVotingMiniGuideOpen , toggleRankedVotingMiniGuide ] = useToggle ( false ) ;
95+ const [ isAppealMiniGuideOpen , toggleAppealMiniGuide ] = useToggle ( false ) ;
96+ const [ isJurorLevelsMiniGuideOpen , toggleJurorLevelsMiniGuide ] = useToggle ( false ) ;
97+
98+ const canCloseOnboarding =
99+ ! isStakingMiniGuideOpen &&
100+ ! isBinaryVotingMiniGuideOpen &&
101+ ! isRankedVotingMiniGuideOpen &&
102+ ! isAppealMiniGuideOpen &&
103+ ! isJurorLevelsMiniGuideOpen ;
104+
105+ const toggleMiniGuide = ( guideName : string ) => {
106+ if ( guideName === "Staking" ) {
107+ toggleStakingMiniGuide ( ) ;
108+ } else if ( guideName === "Binary Voting" ) {
109+ toggleBinaryVotingMiniGuide ( ) ;
110+ } else if ( guideName === "Ranked Voting" ) {
111+ toggleRankedVotingMiniGuide ( ) ;
112+ } else if ( guideName === "Appeal" ) {
113+ toggleAppealMiniGuide ( ) ;
114+ } else if ( guideName === "Juror Levels" ) {
115+ toggleJurorLevelsMiniGuide ( ) ;
116+ }
117+ } ;
79118
80119 return (
81- < Template
82- LeftContent = { < LeftContent currentPage = { currentPage } /> }
83- RightContent = { < RightContent currentPage = { currentPage } /> }
84- onClose = { toggleIsOnboardingMiniGuidesOpen }
85- currentPage = { currentPage }
86- setCurrentPage = { setCurrentPage }
87- numPages = { leftPageContents . length }
88- isOnboarding = { true }
89- />
120+ < >
121+ < Template
122+ LeftContent = { < LeftContent currentPage = { currentPage } toggleMiniGuide = { toggleMiniGuide } /> }
123+ RightContent = { < RightContent currentPage = { currentPage } /> }
124+ onClose = { toggleIsOnboardingMiniGuidesOpen }
125+ currentPage = { currentPage }
126+ setCurrentPage = { setCurrentPage }
127+ numPages = { leftPageContents . length }
128+ isOnboarding = { true }
129+ canClose = { canCloseOnboarding }
130+ />
131+
132+ { isStakingMiniGuideOpen && < Staking toggleMiniGuide = { toggleStakingMiniGuide } /> }
133+ { isBinaryVotingMiniGuideOpen && < BinaryVoting toggleMiniGuide = { toggleBinaryVotingMiniGuide } /> }
134+ { isRankedVotingMiniGuideOpen && < RankedVoting toggleMiniGuide = { toggleRankedVotingMiniGuide } /> }
135+ { isAppealMiniGuideOpen && < Appeal toggleMiniGuide = { toggleAppealMiniGuide } /> }
136+ { isJurorLevelsMiniGuideOpen && < JurorLevels toggleMiniGuide = { toggleJurorLevelsMiniGuide } /> }
137+ </ >
90138 ) ;
91139} ;
92140
0 commit comments