Skip to content

Commit

Permalink
Setting format view from localStorage.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasvaeth committed Dec 25, 2017
1 parent 8698533 commit 56ddfc1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion assets/css/app.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/app.bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cryptologg",
"version": "1.1.0",
"version": "1.1.1",
"description": "CryptoLogg only shows the price change of cryptocurrencies since the last time you checked. This is to discourage you from checking the values of your investments often.",
"main": "webpack.prod.js",
"homepage": "http://cryptologg.com",
Expand Down
28 changes: 19 additions & 9 deletions src/js/components/Crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ class Crypto extends Component {
}

componentDidMount() {
const currency = localStorage.getItem('currency');

if (currency !== null) {
this.setState({ currency: JSON.parse(currency) });
}

this.spotPrice(this.crypto);

document.addEventListener('visibilitychange', () => {
Expand All @@ -32,6 +38,10 @@ class Crypto extends Component {
});
}

componentDidUpdate() {
localStorage.setItem('currency', this.state.currency);
}

spotPrice(currency) {
axios.get(`https://min-api.cryptocompare.com/data/pricemulti?fsyms=${currency}&tsyms=USD`)
.then(response => {
Expand Down Expand Up @@ -92,7 +102,7 @@ class Crypto extends Component {
text = this.state.currency ? `–${toCurrency(changeValue)}` : `–${toPercentage(changeValue)}`;
} else {
emoji = getEmoji(neutralEmoji);
text = this.state.currency ? toCurrency(0) : '0%';
text = this.state.currency ? '$0.00' : '0%';
}

return this.cards(value, emoji, title, text);
Expand Down Expand Up @@ -124,14 +134,14 @@ class Crypto extends Component {
<div className="crypto__container">
{this.marketChange()}
</div>
<div className="crypto__format">
<span className={`crypto__button ${this.state.currency ? 'active' : ''}`} onClick={this.toggleCurrency}>
<span>$</span>
</span>
<span className={`crypto__button ${!this.state.currency ? 'active' : ''}`} onClick={this.toggleCurrency}>
<span>%</span>
</span>
</div>
</div>
<div className="crypto__format">
<span className={`crypto__button ${this.state.currency ? 'active' : ''}`} onClick={this.toggleCurrency}>
<span>$</span>
</span>
<span className={`crypto__button ${!this.state.currency ? 'active' : ''}`} onClick={this.toggleCurrency}>
<span>%</span>
</span>
</div>
</section>
);
Expand Down
1 change: 1 addition & 0 deletions src/scss/components/_crypto.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
display: block;

font-size: 1.5em;
cursor: pointer;
}

&__format {
Expand Down

0 comments on commit 56ddfc1

Please sign in to comment.