2018-07-06 11:45:36 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { PropTypes } from 'prop-types';
|
2018-07-17 13:07:27 +00:00
|
|
|
import Parser from 'html-react-parser';
|
2018-07-06 11:45:36 +00:00
|
|
|
import Modal from '../../modal';
|
2018-07-17 13:07:27 +00:00
|
|
|
import getConfig from 'next/config';
|
2018-07-06 11:45:36 +00:00
|
|
|
import './style.scss';
|
|
|
|
|
2018-07-17 13:07:27 +00:00
|
|
|
const { publicRuntimeConfig } = getConfig();
|
|
|
|
|
2018-07-11 09:17:11 +00:00
|
|
|
class InterviewsList extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2018-07-10 11:43:11 +00:00
|
|
|
|
2018-07-11 09:17:11 +00:00
|
|
|
this.state = {
|
|
|
|
activeLetter: 'A',
|
|
|
|
};
|
|
|
|
}
|
2018-07-10 14:25:52 +00:00
|
|
|
|
2018-07-11 09:17:11 +00:00
|
|
|
render() {
|
|
|
|
const { activeLetter } = this.state;
|
2018-07-10 14:25:52 +00:00
|
|
|
|
2018-07-11 09:17:11 +00:00
|
|
|
// Sort interviews alphabetically
|
|
|
|
const sortedInterviews = this.props.data.sort((a, b) => a.name.localeCompare(b.name));
|
|
|
|
const interviews = {};
|
2018-07-10 11:43:11 +00:00
|
|
|
|
2018-07-11 09:17:11 +00:00
|
|
|
// Build up interviews object with letter key
|
|
|
|
sortedInterviews.forEach((interview) => {
|
|
|
|
const firstLetter = interview.name.charAt(0);
|
|
|
|
|
|
|
|
if (typeof interviews[firstLetter] === 'undefined') {
|
|
|
|
interviews[firstLetter] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
interviews[firstLetter].push(interview);
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="interviews-wrap">
|
|
|
|
<div className="mob-interviews-link">
|
2018-07-11 09:29:48 +00:00
|
|
|
<button onClick={this.props.toggleInterviewsListModal}>
|
2018-07-17 13:07:27 +00:00
|
|
|
<span>Interviews ({this.props.data.length})</span>
|
2018-07-11 09:29:48 +00:00
|
|
|
</button>
|
|
|
|
<button onClick={this.props.toggleInterviewsListModal}>
|
2018-07-17 13:07:27 +00:00
|
|
|
<span>View</span> <img src={`${publicRuntimeConfig.subDirPath}/static/img/right-chevron-icon.svg`} alt="right chevron icon" />
|
2018-07-11 09:29:48 +00:00
|
|
|
</button>
|
2018-07-11 09:17:11 +00:00
|
|
|
</div>
|
|
|
|
<Modal
|
|
|
|
isModalOpen={this.props.isInterviewsListModalOpen}
|
|
|
|
closeModal={this.props.toggleInterviewsListModal}
|
|
|
|
modalOnMobileOnly
|
2018-07-10 11:43:11 +00:00
|
|
|
>
|
2018-07-11 09:17:11 +00:00
|
|
|
<React.Fragment>
|
2018-07-17 13:07:27 +00:00
|
|
|
<h4>Interviews</h4>
|
2018-07-11 09:17:11 +00:00
|
|
|
<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 => (
|
|
|
|
<li
|
|
|
|
id={interview.id}
|
|
|
|
key={interview.id}
|
|
|
|
>
|
2018-07-11 09:29:48 +00:00
|
|
|
<button onClick={this.props.toggleSingleInterview}>
|
2018-07-17 13:07:27 +00:00
|
|
|
{ Parser(interview.name) }
|
2018-07-11 09:29:48 +00:00
|
|
|
</button>
|
2018-07-11 09:17:11 +00:00
|
|
|
</li>
|
2018-07-10 12:25:23 +00:00
|
|
|
))
|
2018-07-11 09:17:11 +00:00
|
|
|
}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
<div className="letters-nav">
|
|
|
|
{
|
|
|
|
Object.keys(interviews).map(firstLetter => (
|
|
|
|
<button
|
|
|
|
key={firstLetter}
|
|
|
|
onClick={() => {
|
|
|
|
document.querySelector(`#${firstLetter}`).scrollIntoView({ behavior: 'smooth' });
|
2018-07-11 09:29:48 +00:00
|
|
|
this.setState({ activeLetter: firstLetter });
|
2018-07-11 09:17:11 +00:00
|
|
|
}}
|
|
|
|
className={activeLetter === firstLetter ? 'active' : ''}
|
|
|
|
>
|
|
|
|
{ firstLetter }
|
|
|
|
</button>
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</div>
|
2018-07-10 11:43:11 +00:00
|
|
|
</div>
|
2018-07-11 09:17:11 +00:00
|
|
|
</React.Fragment>
|
|
|
|
</Modal>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2018-07-11 09:29:48 +00:00
|
|
|
}
|
2018-07-06 11:45:36 +00:00
|
|
|
|
|
|
|
InterviewsList.propTypes = {
|
|
|
|
isInterviewsListModalOpen: PropTypes.bool.isRequired,
|
2018-07-09 14:29:38 +00:00
|
|
|
data: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
|
2018-07-10 12:25:23 +00:00
|
|
|
toggleSingleInterview: PropTypes.func.isRequired, /* eslint-disable-line */
|
2018-07-06 11:45:36 +00:00
|
|
|
toggleInterviewsListModal: PropTypes.func.isRequired,
|
2018-07-06 12:36:22 +00:00
|
|
|
};
|
2018-07-06 11:45:36 +00:00
|
|
|
|
|
|
|
export default InterviewsList;
|