Commit 91d4cfcc authored by Turid Cecilie Dahl's avatar Turid Cecilie Dahl
Browse files

Minor fixes and cleanup

parent 358f6792
......@@ -15,6 +15,7 @@ class MiddlePart extends React.Component{
this.handleOptionChangeImage = this.handleOptionChangeImage.bind(this);
this.handleOptionChangeText = this.handleOptionChangeText.bind(this);
this.handleGetFav = this.handleGetFav.bind(this);
this.changeContent = this.changeContent.bind(this);
//State keeps track of which category of text, sound and image is selected
//Check if the user has stored anything, and if so then use it
if (sessionStorage.currentText && sessionStorage.currentIndex){
......@@ -36,7 +37,7 @@ class MiddlePart extends React.Component{
}
}
else{
//Nothing stored, first time on the website in that session
//Nothing stored, first time on the website in that session. Use default values
this.state = {
currentIndex: 0,
soundIndex: 'animals',
......@@ -44,7 +45,6 @@ class MiddlePart extends React.Component{
textIndex: 'clicheQuotes'
}
}
this.changeContent = this.changeContent.bind(this);
// Boolean variables to know when content should be changed,
// and when favorite collection should be displayed.
......@@ -74,7 +74,7 @@ class MiddlePart extends React.Component{
}
}
//Set the radio buttons to favorite combination
//Set the radio buttons to favorite combination with HTML Storage
handleGetFav(){
if(localStorage.favSound){
this.setState({
......@@ -240,7 +240,9 @@ class MiddlePart extends React.Component{
goToThirdSlide={this.goToThirdSlide}
goToFourthSlide={this.goToFourthSlide} />
</div>
<Sidebar soundIndex={this.state.soundIndex}
<Sidebar
currentIndex={this.state.currentIndex}
soundIndex={this.state.soundIndex}
imageIndex={this.state.imageIndex}
textIndex={this.state.textIndex}
handleOptionChangeSound={this.handleOptionChangeSound}
......
import React, {Component} from 'react';
//http://react.tips/radio-buttons-in-reactjs/
class Sidebar extends Component {
constructor(props){
......@@ -12,10 +11,11 @@ class Sidebar extends Component {
seeCombinationClickHandler(){
this.props.changeContent();
if (typeof(Storage) !== "undefined") {
sessionStorage.currentIndex = this.props.currentIndex
sessionStorage.currentSound = this.props.soundIndex
sessionStorage.currentImage = this.props.imageIndex
sessionStorage.currentText = this.props.textIndex
} else {
// Sorry! No Web Storage support..
}
}
......@@ -29,9 +29,9 @@ class Sidebar extends Component {
} else {
// Sorry! No Web Storage support..
}
console.log(localStorage.favImage)
}
//http://react.tips/radio-buttons-in-reactjs/
render() {
return (
<div>
......@@ -133,7 +133,7 @@ class Sidebar extends Component {
<button onClick={(e) => this.seeCombinationClickHandler(e)}>
See combination
</button>
<button onClick={(e) => this.saveFav(e)}>
<button onClick={this.saveFav}>
Save as favorite
</button>
<button onClick={this.props.handleGetFav}>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment