Fix random categories

parent e0b0c118
......@@ -43,8 +43,12 @@ class App extends React.Component {
audioCat: Math.floor((Math.random() * 3)),
},
sessionHistory: [],
sessionCounter: 0
sessionCounter: 0,
};
localStorage.setItem("Text", this.state.categorySelections.textCat);
localStorage.setItem("Image", this.state.categorySelections.imageCat);
localStorage.setItem("Audio", this.state.categorySelections.audioCat);
localStorage.setItem("artwork", this.state.artwork);
}
}
......@@ -103,11 +107,11 @@ class App extends React.Component {
let newCombination = JSON.parse(sessionStorage.getItem('combinationHistory'));
if (newCombination === null) {
console.log("###");
newCombination = [];
} else {
// Remove forward history if manually selecting new artwork or category
newCombination = newCombination.splice(0, this.state.sessionCounter);
newCombination = newCombination.splice(0, this.state.sessionCounter);
}
newCombination.push(
this.state.sessionCounter + "/" +
......@@ -122,10 +126,10 @@ class App extends React.Component {
sessionCounter: (oldState.sessionCounter + 1)
}));
};
sessionBack = () => {
if (this.state.sessionCounter <= 1) return;
this.setState(oldState => {
let dataAsArray = oldState.sessionHistory[this.state.sessionCounter - 2].split(";");
return {
......@@ -157,7 +161,7 @@ class App extends React.Component {
}
});
}
};
handleArtworkChange(artworkId) {
if (this.state.artwork === artworkId) return;
......@@ -228,12 +232,12 @@ class App extends React.Component {
categorySelections={categorySelections}/>
</div>
</div>
<SessionElement sessionHistory={sessionHistory}
sessionClicked={this.sessionClicked}
sessionIndex={this.state.sessionCounter}
backClicked={this.sessionBack}
fwdClicked={this.sessionFwd}
/>
<SessionElement sessionHistory={sessionHistory}
sessionClicked={this.sessionClicked}
sessionIndex={this.state.sessionCounter}
backClicked={this.sessionBack}
fwdClicked={this.sessionFwd}
/>
</div>
);
}
......
Markdown is supported
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