diff --git a/client/main.js b/client/main.js index 7a969d8c95..db28dec2c1 100644 --- a/client/main.js +++ b/client/main.js @@ -124,6 +124,28 @@ main = (function(main, global) { Mousetrap.bind('g c', toggleMainChat); }); + function localStorageIO(item = '', input = null) { + if (input) { + try { + input = typeof input === 'string' ? input : JSON.stringify(input); + } catch (e) { + // Do Nothing + } + localStorage.setItem(item, input); + return input; + } else { + let data = localStorage.getItem(item); + try { + data = JSON.parse(data); + } catch (e) { + // Do Nothing + } + return data; + } + } + + main.localStorageIO = localStorageIO; + return main; }(main, window)); @@ -621,29 +643,26 @@ $(document).ready(function() { }).done((resp) => { cb(resp); }); + $('#dismissBill').on('click', (e) => { + const elemData + = e.target.parentNode.parentNode.children; + + const res + = elemData[Object.keys(elemData).filter((key)=> { + return elemData[key].id === 'billContent'; + + })[0]].innerHTML; + + main.localStorageIO('lastBillBoardSeen', res); + }); } function handleNewBillBoard(message) { - const seen = typeof localStorage.getItem('billboardSeen') !== "undefined" ? localStorage.getItem('billboardSeen') : 'false'; - let old = typeof localStorage.getItem('billboard') !== "undefined" ? localStorage.getItem('billboard') : 'false'; - if(seen !== 'true') { - old = null; - } - if(message.data !== old) { - if(!message.err) { - $('#billContent').text(message.data); - localStorage.setItem('billboard', message.data) - } else { - console.error(message.err); - } + if (main.localStorageIO('lastBillBoardSeen') !== message.data) { + $('#billContent').text(message.data); + $('#billBoard').fadeIn(); } } getCurrentBillBoard(handleNewBillBoard); - - $('#dismissBill').on('click', () => { - console.log("test"); - localStorage.setItem('billboardSeen', 'true'); - }); - }); diff --git a/server/boot/randomAPIs.js b/server/boot/randomAPIs.js index 66c44d1331..39dccaf24b 100644 --- a/server/boot/randomAPIs.js +++ b/server/boot/randomAPIs.js @@ -85,21 +85,44 @@ module.exports = function(app) { } function billBoard(req, res) { - if(req.user && typeof req.user.currentChallenge.challengeId !== "undefined"){ - BillBoard.findOne({}, function(err, data){ - if(err){ - res.send({err: {type: "Error", message: "Database Error"}, data: null}); + if ( + req.user + && typeof req.user.currentChallenge.challengeId !== 'undefined' + ) { + BillBoard.findOne({}, function(err, data) { + if (err) { + res.send({ + err: { + type: 'Error', + message: 'Database Error' + }, + data: null + }); } else { if (data.active) { - res.send({err: null, data: data.message}); + res.send({ + err: null, + data: data.message + }); } else { - res.send({err: {type: "warning", message: "Bill Board is not active"}, data: null}); + res.send({ + err: { + type: 'warning', + message: 'Bill Board is not active' + }, + data: null + }); } } }); - } - else { - res.send({err: {type: "warning", message: "User Not Signed In"}, data: null}); + } else { + res.send({ + err: { + type: 'warning', + message: 'User Not Signed In' + }, + data: null + }); } } diff --git a/server/views/partials/flash.jade b/server/views/partials/flash.jade index 2888e97d6c..a84ab6145b 100644 --- a/server/views/partials/flash.jade +++ b/server/views/partials/flash.jade @@ -20,7 +20,7 @@ div!= success.msg .row.flashMessage .col-xs-12 - .alert.alert-success.fade.in + #billBoard.alert.alert-success.fade.in(style="display: none;") button.close(type='button', data-dismiss='alert') span.ion-close-circled#dismissBill #billContent \ No newline at end of file