Don't show stale news if there are no news

This commit is contained in:
Ilya Ig. Petrov 2017-06-08 18:58:05 +05:00
parent c1b28ea916
commit 532b0b969f

View File

@ -57,7 +57,6 @@ export default function getApp(theState) {
const uiComDate = 'ui-last-comment-date'; const uiComDate = 'ui-last-comment-date';
const uiComEtag = 'ui-last-comments-etag'; const uiComEtag = 'ui-last-comments-etag';
const uiLastNewsArr = 'ui-last-news-arr';
const statusFromHash = this.state.hashParams.get('status'); const statusFromHash = this.state.hashParams.get('status');
if (statusFromHash) { if (statusFromHash) {
@ -106,18 +105,13 @@ export default function getApp(theState) {
} }
if (error) { if (error) {
return; // Let user see the error message and contemplate. return; // Let the user see the error message and contemplate.
} }
const ifNews = (() => { const ifNews = (() => {
if (!(comments && comments.length)) { if (!(comments && comments.length)) {
const json = localStorage[uiLastNewsArr]; // Don't show stale news here.
const news = json && JSON.parse(json);
if (news) {
this.setNewsStatusTo(news);
return true;
}
return false; return false;
} }
@ -139,13 +133,12 @@ export default function getApp(theState) {
return false; return false;
} }
localStorage[uiComDate] = minDate; localStorage[uiComDate] = minDate;
localStorage[uiLastNewsArr] = JSON.stringify(news);
this.setNewsStatusTo(news); this.setNewsStatusTo(news);
return true; return true;
})(); })();
if (!ifNews) { if (!ifNews) {
this.setStatusTo('Ничего нового.'); this.setStatusTo('Хорошего настроения Вам!');
} }
} }