1
- import React , { useState } from 'react'
2
- import { Link , useLocation , useNavigate } from 'react-router-dom'
3
- import { Button , Modal } from 'react-bootstrap'
4
- import { CustomTooltip } from "@remix-ui/helper"
1
+ import React from 'react'
2
+ import { Link , useLocation , useNavigate } from 'react-router-dom'
3
+ import { Dropdown } from 'react-bootstrap'
5
4
import './index.scss'
6
5
7
- function BackButton ( { entity} : any ) {
8
- const navigate = useNavigate ( )
6
+ function BackButton ( { entity } : any ) {
9
7
const location = useLocation ( )
10
- const [ show , setShow ] = useState ( false )
11
8
const isDetailPage = location . pathname === '/detail'
9
+
12
10
const queryParams = new URLSearchParams ( location . search )
13
11
const stepId = Number ( queryParams . get ( 'stepId' ) )
14
- const nextStep = entity && entity . steps [ stepId + 1 ]
15
- const previousStep = entity && entity . steps [ stepId - 1 ]
12
+ const currentStep = entity ?. steps ?. [ stepId ]
13
+
14
+ const tutorialId = entity ?. id || queryParams . get ( 'id' )
16
15
17
16
return (
18
- < nav className = "navbar navbar-light bg-light d-flex justify-content-between pt-1 pb-1 ps-1" >
19
- < ul className = "d-flex nav me-auto" >
20
- < li className = "nav-item" >
21
- < div
22
- className = "btn back"
23
- onClick = { ( ) => {
24
- setShow ( true )
25
- } }
26
- role = "button"
27
- >
28
- < CustomTooltip
29
- placement = { "right" }
30
- tooltipId = "learnethHomeIconTooltip"
31
- tooltipText = 'Leave tutorial'
32
- >
33
- < i className = "fas fa-home ps-1" />
34
- </ CustomTooltip >
35
- </ div >
36
- </ li >
37
- { isDetailPage && (
38
- < li className = "nav-item" >
39
- < CustomTooltip placement = "right" tooltipId = "learnethBarsIconTooltip" tooltipText = 'Tutorial menu' >
40
- < Link className = "btn" to = { `/list?id=${ entity . id } ` } onClick = { ( ) => ( window as any ) . _paq . push ( [ 'trackEvent' , 'learneth' , 'back_to_menu_step' , entity && entity . name ] ) } >
41
- < i className = "fas fa-bars" />
42
- </ Link >
43
- </ CustomTooltip >
44
- </ li >
17
+ < div className = "learneth-top-nav p-2" >
18
+ < div className = "d-flex justify-content-between align-items-center" >
19
+ < Link to = "/home" className = "btn nav-button d-flex align-items-center" >
20
+ < i className = "fas fa-chevron-left" > </ i >
21
+ < span > Tutorials list</ span >
22
+ </ Link >
23
+
24
+ { isDetailPage && entity ?. steps && (
25
+ < Dropdown >
26
+ < Dropdown . Toggle className = "btn nav-button d-flex align-items-center" id = "syllabus-dropdown" >
27
+ < i className = "fas fa-list-ul me-2" > </ i >
28
+ < span > Syllabus</ span >
29
+ </ Dropdown . Toggle >
30
+
31
+ < Dropdown . Menu className = "syllabus-dropdown-menu" >
32
+ < div className = "px-3 pt-2 pb-1 d-flex justify-content-between" >
33
+ < h6 className = "fw-bold mb-0" > Syllabus</ h6 >
34
+ < span className = "small text-muted" > { entity . steps . length } chapters</ span >
35
+ </ div >
36
+ < Dropdown . Divider />
37
+ { entity . steps . map ( ( step : any , index : number ) => (
38
+ < Dropdown . Item as = { Link } to = { `/detail?id=${ entity . id } &stepId=${ index } ` } key = { index } className = "syllabus-item" >
39
+ < i className = "far fa-file-alt me-2" > </ i >
40
+ < span > { step . name } </ span >
41
+ </ Dropdown . Item >
42
+ ) ) }
43
+ </ Dropdown . Menu >
44
+ </ Dropdown >
45
45
) }
46
- </ ul >
47
- { isDetailPage && (
48
- < form className = "form d-flex" >
49
- { stepId > 0 && (
50
- < Link to = { `/detail?id=${ entity . id } &stepId=${ stepId - 1 } ` } onClick = { ( ) => ( window as any ) . _paq . push ( [ 'trackEvent' , 'learneth' , 'previous_step' , `${ entity . name } /${ previousStep && previousStep . name } ` ] ) } >
51
- < i className = "fas fa-chevron-left pe-1" />
46
+ </ div >
47
+
48
+ { isDetailPage && currentStep && (
49
+ < >
50
+ < hr className = "nav-divider my-2" />
51
+ < div className = "chapter-nav d-flex justify-content-between align-items-center" >
52
+ < Link
53
+ to = { `/detail?id=${ entity . id } &stepId=${ stepId - 1 } ` }
54
+ className = { `btn chapter-arrow ${ stepId === 0 ? 'disabled' : '' } ` }
55
+ >
56
+ < i className = "fas fa-chevron-left" > </ i >
52
57
</ Link >
53
- ) }
54
- { stepId + 1 } /{ entity && < div className = "" > { entity . steps . length } </ div > }
55
- { stepId < entity . steps . length - 1 && (
56
- < Link to = { `/detail?id=${ entity . id } &stepId=${ stepId + 1 } ` } onClick = { ( ) => ( window as any ) . _paq . push ( [ 'trackEvent' , 'learneth' , 'next_step' , `${ entity . name } /${ nextStep && nextStep . name } ` ] ) } >
57
- < i className = "fas fa-chevron-right ps-1 pe-1" />
58
+
59
+ < div className = "text-center" >
60
+ < div className = "chapter-title" > { currentStep . name } </ div >
61
+ < div className = "chapter-pagination small text-muted" >
62
+ { stepId + 1 } / { entity . steps . length }
63
+ </ div >
64
+ </ div >
65
+
66
+ < Link
67
+ to = { `/detail?id=${ entity . id } &stepId=${ stepId + 1 } ` }
68
+ className = { `btn chapter-arrow ${ stepId >= entity . steps . length - 1 ? 'disabled' : '' } ` }
69
+ >
70
+ < i className = "fas fa-chevron-right" > </ i >
58
71
</ Link >
59
- ) }
60
- </ form >
72
+ </ div >
73
+ </ >
61
74
) }
62
- < Modal
63
- show = { show }
64
- onHide = { ( ) => {
65
- setShow ( false )
66
- } }
67
- >
68
- < Modal . Header closeButton >
69
- < Modal . Title > Leave tutorial</ Modal . Title >
70
- </ Modal . Header >
71
- < Modal . Body > Are you sure you want to leave the tutorial?</ Modal . Body >
72
- < Modal . Footer >
73
- < Button
74
- variant = "secondary"
75
- onClick = { ( ) => {
76
- setShow ( false )
77
- } }
78
- >
79
- No
80
- </ Button >
81
- < Button
82
- variant = "success"
83
- onClick = { ( ) => {
84
- setShow ( false )
85
- navigate ( '/home' ) ;
86
- ( window as any ) . _paq . push ( [ 'trackEvent' , 'learneth' , 'leave_tutorial' , entity && entity . name ] )
87
- } }
88
- >
89
- Yes
90
- </ Button >
91
- </ Modal . Footer >
92
- </ Modal >
93
- </ nav >
75
+ </ div >
94
76
)
95
77
}
96
78
97
- export default BackButton
79
+ export default BackButton
0 commit comments