Added comments
This commit is contained in:
parent
7943330fa9
commit
2f238865cb
|
|
@ -7,6 +7,8 @@ import Topic from './subcomponents/Topic';
|
||||||
class Intro extends React.Component {
|
class Intro extends React.Component {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
// Defaults for the state
|
||||||
this.state = {
|
this.state = {
|
||||||
start: false,
|
start: false,
|
||||||
prev: 'previous',
|
prev: 'previous',
|
||||||
|
|
@ -20,46 +22,66 @@ class Intro extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleKey = (e) => {
|
handleKey = (e) => {
|
||||||
|
/**
|
||||||
|
* handleKey - Handle key events and hand off to handleInput
|
||||||
|
*/
|
||||||
switch(e.key) {
|
switch(e.key) {
|
||||||
case "ArrowUp":
|
case "ArrowUp": // If received an up Arrow
|
||||||
this.handleInput('up');
|
this.handleInput('up');
|
||||||
break;
|
break;
|
||||||
case "ArrowDown":
|
case "ArrowDown": // If received a down Arrow
|
||||||
this.handleInput('down')
|
this.handleInput('down')
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleInput = (input) => {
|
handleInput = (input) => {
|
||||||
console.log(this.state.prevLoc);
|
/**
|
||||||
console.log(this.state.currLoc)
|
* handleInput - handle input events. A majority of the functionality is to scroll through Intro topics
|
||||||
console.log(this.state.nextLoc)
|
*/
|
||||||
|
|
||||||
|
// Up Arrow
|
||||||
if (input === "up" && this.state.currLoc > 0) {
|
if (input === "up" && this.state.currLoc > 0) {
|
||||||
|
|
||||||
|
// Activate animation going to next topic
|
||||||
this.setState({
|
this.setState({
|
||||||
prev: 'current',
|
prev: 'current',
|
||||||
curr: 'next',
|
curr: 'next',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Wait 500 ms until the transition is finished
|
||||||
setTimeout(()=>{
|
setTimeout(()=>{
|
||||||
|
// Once timeout finishes, place topics in correct location without transition
|
||||||
this.setState({
|
this.setState({
|
||||||
prev: 'previous notrans',
|
prev: 'previous notrans',
|
||||||
curr: 'current notrans',
|
curr: 'current notrans',
|
||||||
prevLoc: this.state.prevLoc-1,
|
prevLoc: this.state.prevLoc-1, // Move correct topics into necessary divs
|
||||||
currLoc: this.state.currLoc-1,
|
currLoc: this.state.currLoc-1,
|
||||||
nextLoc: this.state.nextLoc-1,
|
nextLoc: this.state.nextLoc-1,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// wait another 20 ms to
|
||||||
setTimeout(()=>{
|
setTimeout(()=>{
|
||||||
this.setState({
|
this.setState({ // remove notrans from each div
|
||||||
prev: 'previous',
|
prev: 'previous',
|
||||||
curr: 'current',
|
curr: 'current',
|
||||||
});
|
});
|
||||||
|
|
||||||
}, 20);
|
}, 20);
|
||||||
|
|
||||||
}, 500);
|
}, 500);
|
||||||
} else if (input === "down" && this.state.nextLoc < this.topics.length) {
|
} else if (input === "down" && this.state.nextLoc < this.topics.length) {
|
||||||
|
// Activate transition going to previous topic
|
||||||
this.setState({
|
this.setState({
|
||||||
curr: 'previous',
|
curr: 'previous',
|
||||||
next: 'current'
|
next: 'current'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// wait 500 ms before placing all topics into correct divs
|
||||||
setTimeout(()=>{
|
setTimeout(()=>{
|
||||||
|
// move all topics into correct divs
|
||||||
this.setState({
|
this.setState({
|
||||||
curr: 'current notrans',
|
curr: 'current notrans',
|
||||||
next: 'next notrans',
|
next: 'next notrans',
|
||||||
|
|
@ -67,6 +89,8 @@ class Intro extends React.Component {
|
||||||
currLoc: this.state.currLoc+1,
|
currLoc: this.state.currLoc+1,
|
||||||
nextLoc: this.state.nextLoc+1,
|
nextLoc: this.state.nextLoc+1,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// wait 20ms and remove notrans
|
||||||
setTimeout(()=>{
|
setTimeout(()=>{
|
||||||
this.setState({
|
this.setState({
|
||||||
curr: 'current',
|
curr: 'current',
|
||||||
|
|
@ -82,6 +106,21 @@ class Intro extends React.Component {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
setTimeout(()=>{ // At the start, wait 100ms and enable intro
|
||||||
|
this.setState({
|
||||||
|
start: true,
|
||||||
|
});
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
document.title = "Introduction"; // Set document title
|
||||||
|
|
||||||
|
// Hide the navigation
|
||||||
|
this.props.hideNavigation();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Topics to display in intro
|
||||||
topics = [
|
topics = [
|
||||||
<Topic title="Studied at Marist College" background="img/marist.webp">
|
<Topic title="Studied at Marist College" background="img/marist.webp">
|
||||||
<a href="https://www.marist.edu/">Marist.edu</a>
|
<a href="https://www.marist.edu/">Marist.edu</a>
|
||||||
|
|
@ -95,6 +134,7 @@ class Intro extends React.Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
||||||
|
// Render page
|
||||||
return (
|
return (
|
||||||
<div onKeyDown={this.handleKey} tabIndex="0" className={this.state.start ? 'intro start':'intro'}>
|
<div onKeyDown={this.handleKey} tabIndex="0" className={this.state.start ? 'intro start':'intro'}>
|
||||||
<div id="previous" className={this.state.prev}>
|
<div id="previous" className={this.state.prev}>
|
||||||
|
|
@ -109,19 +149,6 @@ class Intro extends React.Component {
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
setTimeout(()=>{
|
|
||||||
this.setState({
|
|
||||||
start: true,
|
|
||||||
});
|
|
||||||
}, 100);
|
|
||||||
|
|
||||||
document.title = "Introduction";
|
|
||||||
|
|
||||||
this.props.hideNavigation();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = (state) => {
|
const mapStateToProps = (state) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue