Skip to content

Commit

Permalink
Add section progress to new interview
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Dec 5, 2024
1 parent f972fd5 commit 9712b74
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 50 deletions.
86 changes: 36 additions & 50 deletions rdmo/projects/assets/js/interview/components/sidebar/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ import classNames from 'classnames'

import Html from 'rdmo/core/assets/js/components/Html'

const Navigation = ({ currentPage, navigation, help, fetchPage }) => {

const handleClick = (event, pageId) => {
event.preventDefault()
fetchPage(pageId)
}
import NavigationLink from './NavigationLink'

const Navigation = ({ currentPage, navigation, help, fetchPage }) => {
return (
<>
<h2>{gettext('Navigation')}</h2>
Expand All @@ -19,51 +15,41 @@ const Navigation = ({ currentPage, navigation, help, fetchPage }) => {
<ul className="list-unstyled interview-navigation">
{
navigation.map((section, sectionIndex) => (
<li key={sectionIndex}>
<a href={`/projects/12/interview/${section.first}/`} onClick={event => handleClick(event, section.first)}>
{section.title}
</a>
{
section.pages && (
<ul className="list-unstyled">
{
section.pages.map((page, pageIndex) => {
const label = interpolate(gettext('(%s of %s)'), [page.count, page.total])

return (
<li key={pageIndex} className={classNames({'active': currentPage ? page.id == currentPage.id : false})}>
{
page.show ? (
<a href={`/projects/12/interview/${page.id}/`} onClick={event => handleClick(event, page.id)}>
<span>{page.title}</span>
{
page.count > 0 && page.count == page.total && (
<span>
{' '}<i className="fa fa-check" aria-hidden="true"></i>
</span>
)
}
{
page.count > 0 && page.count != page.total && (
<>
{' '}<span>{label}</span>
</>
)
}
</a>
) : (
<span className="text-muted">{page.title}</span>
)
}
</li>
<li key={sectionIndex}>
<NavigationLink
element={section}
href={`/projects/12/interview/${section.first}/`}
onClick={() => fetchPage(section.first)}
/>
{
section.pages && (
<ul className="list-unstyled">
{
section.pages.map((page, pageIndex) => (
<li key={pageIndex} className={classNames({
'active': currentPage ? page.id == currentPage.id : false})
}>
{
page.show ? (
<NavigationLink
element={page}
href={`/projects/12/interview/${page.id}/`}
onClick={() => fetchPage(page.id)}
/>
) : (
<span className="text-muted">{page.title}</span>
)
}
</li>
)
)
})
}
</ul>
)
}
</li>
))
}
</ul>
)
}
</li>
)
)
}
</ul>
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react'
import PropTypes from 'prop-types'

const NavigationLink = ({ element, href, onClick }) => {

const label = interpolate(gettext('(%s of %s)'), [element.count, element.total])

const handleClick = (event,) => {
event.preventDefault()
onClick()
}

return (
<a href={href} onClick={handleClick}>
{element.title}
{
element.count > 0 && element.count == element.total && (
<span>
{' '}<i className="fa fa-check" aria-hidden="true"></i>
</span>
)
}
{
element.count > 0 && element.count != element.total && (
<>
{' '}<span>{label}</span>
</>
)
}
</a>
)
}

NavigationLink.propTypes = {
element: PropTypes.object.isRequired,
href: PropTypes.string.isRequired,
onClick: PropTypes.func.isRequired
}

export default NavigationLink

0 comments on commit 9712b74

Please sign in to comment.