Updating interviews list

- Sorting interviews alphabetically
- Building up interviews object with letter key
- Looping through each letter and listing intervies by that letter
- Adding scroll into view with letters nav
This commit is contained in:
Sharyn 2018-07-10 13:43:11 +02:00
parent 5dc9ee291b
commit a24ce0fd58
2 changed files with 117 additions and 29 deletions

View File

@ -3,36 +3,91 @@ import { PropTypes } from 'prop-types';
import Modal from '../../modal'; import Modal from '../../modal';
import './style.scss'; import './style.scss';
const InterviewsList = props => ( const InterviewsList = props => {
<div className="interviews-wrap">
<div className="mob-interviews-link"> // Sort interviews alphabetically
<span role="button" tabIndex="0" onClick={props.toggleInterviewsListModal}>Interviews ({ props.data.length })</span> {/* eslint-disable-line */} const sortedInterviews = props.data.sort((a, b) => { return a.name.localeCompare(b.name); });
<span role="button" tabIndex="0" onClick={props.toggleInterviewsListModal}>View</span> {/* eslint-disable-line */} const interviews = {};
</div>
<Modal // Build up interviews object with letter key
isModalOpen={props.isInterviewsListModalOpen} sortedInterviews.forEach(interview => {
closeModal={props.toggleInterviewsListModal} const firstLetter = interview.name.charAt(0);
modalOnMobileOnly if (typeof interviews[firstLetter] === 'undefined') {
> interviews[firstLetter] = [];
<div className="interviews-list"> }
<h4>Interviews ({ props.data.length })</h4> interviews[firstLetter].push(interview);
<ul> });
{ props.data.map(interview => (
// eslint-disable-next-line return (
<li <div className="interviews-wrap">
id={interview.id} <div className="mob-interviews-link">
key={interview.id} {/* eslint-disable-next-line */}
onClick={props.toggleSingleInterview} <span
> role="button"
{ interview.name } tabIndex="0"
</li> onClick={props.toggleInterviewsListModal}
)) >
} Interviews ({props.data.length})
</ul> </span>
{/* eslint-disable-next-line */}
<span
role="button"
tabIndex="0"
onClick={props.toggleInterviewsListModal}
>
View
</span>
</div> </div>
</Modal> <Modal
</div> isModalOpen={props.isInterviewsListModalOpen}
); closeModal={props.toggleInterviewsListModal}
modalOnMobileOnly
>
<React.Fragment>
<h4>Interviews ({ props.data.length })</h4>
<div className="interviews-nav-wrap">
<div className="interviews-list">
{
Object.keys(interviews).map(firstLetter => (
<div className="letter-block" key={firstLetter}>
<div id={firstLetter}>{ firstLetter }</div>
<ul>
{interviews[firstLetter].map(interview => (
// eslint-disable-next-line
<li
id={interview.id}
key={interview.id}
onClick={props.toggleSingleInterview}
>
{interview.name}
</li>
)
)}
</ul>
</div>
)
)
}
</div>
<div className="letters-nav">
{
Object.keys(interviews).map(firstLetter => (
<span
key={firstLetter}
onClick={() => { document.querySelector(`#${firstLetter}`).scrollIntoView({ behavior: 'smooth' }); }}
>
{ firstLetter }
</span>
)
)
}
</div>
</div>
</React.Fragment>
</Modal>
</div>
);
};
InterviewsList.propTypes = { InterviewsList.propTypes = {
isInterviewsListModalOpen: PropTypes.bool.isRequired, isInterviewsListModalOpen: PropTypes.bool.isRequired,

View File

@ -19,8 +19,28 @@
} }
} }
.interviews-nav-wrap {
display: flex;
justify-content: space-between;
justify-content: flex-end;
position: relative;
}
.interviews-list { .interviews-list {
@media (min-width: $desktop) {
position: absolute;
top: 0;
left: 0;
height: 100%;
overflow: auto;
width: 96%;
}
.letter-block {
padding-bottom: calculateRem(32);
}
li { li {
cursor: pointer; cursor: pointer;
outline: none; outline: none;
@ -30,3 +50,16 @@
} }
} }
} }
.letters-nav {
display: none;
@media (min-width: $desktop) {
display: flex;
flex-direction: column;
span {
cursor: pointer;
}
}
}