From edb55c8e2a107cca91de6a62404586fdea66d87f Mon Sep 17 00:00:00 2001 From: Jon Ziebell Date: Tue, 31 Dec 2019 08:23:12 -0500 Subject: [PATCH] Fixed #208 - Can't link Patreon account if you've closed the banner. Made it possible from the beestat menu; also added a link to the support page on the documentation and reworded some stuff. --- js/component/card/patreon.js | 2 +- js/component/header.js | 7 + .../{patreon_hide.js => enjoy_beestat.js} | 299 +++++++++--------- js/js.php | 2 +- 4 files changed, 159 insertions(+), 151 deletions(-) rename js/component/modal/{patreon_hide.js => enjoy_beestat.js} (65%) diff --git a/js/component/card/patreon.js b/js/component/card/patreon.js index 89bc8d6..aafa332 100644 --- a/js/component/card/patreon.js +++ b/js/component/card/patreon.js @@ -41,7 +41,7 @@ beestat.component.card.patreon.prototype.decorate_top_right_ = function(parent) .set_text_color('#fff') .set_background_hover_color(beestat.style.color.green.light) .addEventListener('click', function() { - (new beestat.component.modal.patreon_hide()).render(); + (new beestat.component.modal.enjoy_beestat()).render(); }) .render(parent); }; diff --git a/js/component/header.js b/js/component/header.js index 06c9158..9f194f5 100644 --- a/js/component/header.js +++ b/js/component/header.js @@ -153,6 +153,13 @@ beestat.component.header.prototype.decorate_ = function(parent) { (new beestat.component.modal.download_data()).render(); })); + menu.add_menu_item(new beestat.component.menu_item() + .set_text('Link Patreon') + .set_icon('patreon') + .set_callback(function() { + (new beestat.component.modal.enjoy_beestat()).render(); + })); + menu.add_menu_item(new beestat.component.menu_item() .set_text('Log Out') .set_icon('exit_to_app') diff --git a/js/component/modal/patreon_hide.js b/js/component/modal/enjoy_beestat.js similarity index 65% rename from js/component/modal/patreon_hide.js rename to js/component/modal/enjoy_beestat.js index 189edee..dde924d 100644 --- a/js/component/modal/patreon_hide.js +++ b/js/component/modal/enjoy_beestat.js @@ -1,149 +1,150 @@ -/** - * Options for hiding the patreon card. - */ -beestat.component.modal.patreon_hide = function() { - beestat.component.modal.apply(this, arguments); -}; -beestat.extend(beestat.component.modal.patreon_hide, beestat.component.modal); - -beestat.component.modal.patreon_hide.poll_interval_ = 5000; - -/** - * Decorate - * - * @param {rocket.Elements} parent - */ -beestat.component.modal.patreon_hide.prototype.decorate_contents_ = function(parent) { - switch (this.is_active_patron_()) { - case false: - parent.appendChild($.createElement('p').innerText('Your Patreon account is connected but you\'re not currently a supporter. If you recently became a supporter it could take up to 24 hours to update.')); - break; - case null: - parent.appendChild($.createElement('p').innerText('Hey there! If you didn\'t notice, beestat doesn\'t run ads, cost money, or sell your data. If you find beestat useful, please consider supporting the project. Your contribution helps pay for servers, storage, and other cool things. Thanks!')); - break; - } -}; - -/** - * Get the title. - * - * @return {string} The title. - */ -beestat.component.modal.patreon_hide.prototype.get_title_ = function() { - return 'Don\'t want to see this anymore?'; -}; - -/** - * Close the modal but run some special code first to make sure any running - * interval gets stopped. - */ -beestat.component.modal.patreon_hide.prototype.dispose = function() { - if (this.is_polling_ === true) { - beestat.remove_poll_interval(beestat.component.modal.patreon_hide.poll_interval_); - beestat.dispatcher.removeEventListener('poll.patreon_hide'); - } - - beestat.component.modal.prototype.dispose.apply(this, arguments); -}; - -/** - * Hide the Patreon card for some amount of time. - * - * @param {number} amount How long. - * @param {string} unit The unit (day, month, etc). - */ -beestat.component.modal.patreon_hide.prototype.hide_patreon_card_for_ = function(amount, unit) { - beestat.setting( - 'patreon_hide_until', - moment().utc() - .add(amount, unit) - .format('YYYY-MM-DD HH:mm:ss') - ); - beestat.cards.patreon.dispose(); -}; - -/** - * Determine whether or not the current user is an active Patron. - * - * @return {boolean} true if yes, false if no, null if not connected. - */ -beestat.component.modal.patreon_hide.prototype.is_active_patron_ = function() { - var user = beestat.get_user(); - if (user.patreon_status !== null) { - return (user.patreon_status.patron_status === 'active_patron'); - } - return null; -}; - -/** - * Get the buttons on the modal. - * - * @return {[beestat.component.button]} The buttons. - */ -beestat.component.modal.patreon_hide.prototype.get_buttons_ = function() { - var self = this; - - var hide = new beestat.component.button() - .set_background_color('#fff') - .set_text_color(beestat.style.color.gray.base) - .set_text_hover_color(beestat.style.color.bluegray.base) - .set_text('Hide for one month') - .addEventListener('click', function() { - self.hide_patreon_card_for_(1, 'month'); - self.dispose(); - }); - - if (self.is_active_patron_() === null) { - var link = new beestat.component.button() - .set_text('Link Patreon to hide forever') - .set_background_color(beestat.style.color.green.base) - .set_background_hover_color(beestat.style.color.green.light) - .set_text_color('#fff') - .addEventListener('click', function() { - this - .set_background_color(beestat.style.color.gray.base) - .set_background_hover_color() - .set_text('Waiting for Patreon...') - .removeEventListener('click'); - - beestat.add_poll_interval(beestat.component.modal.patreon_hide.poll_interval_); - self.is_polling_ = true; - - beestat.dispatcher.addEventListener('poll.patreon_hide', function() { - switch (self.is_active_patron_()) { - case true: - // Connected and is Patron - beestat.cards.patreon.dispose(); - self.dispose(); - break; - case false: - // Connected but isn't Patron - self.hide_patreon_card_for_(3, 'day'); - self.dispose(); - break; - } - }); - - window.open('../api/?resource=patreon&method=authorize&arguments={}&api_key=ER9Dz8t05qUdui0cvfWi5GiVVyHP6OB8KPuSisP2'); - }); - - return [ - hide, - link - ]; - } - - var ok = new beestat.component.button() - .set_background_color(beestat.style.color.green.base) - .set_background_hover_color(beestat.style.color.green.light) - .set_text_color('#fff') - .set_text('OK') - .addEventListener('click', function() { - self.dispose(); - }); - - return [ - hide, - ok - ]; -}; +/** + * Options for hiding the patreon card. + */ +beestat.component.modal.enjoy_beestat = function() { + beestat.component.modal.apply(this, arguments); +}; +beestat.extend(beestat.component.modal.enjoy_beestat, beestat.component.modal); + +beestat.component.modal.enjoy_beestat.poll_interval_ = 5000; + +/** + * Decorate + * + * @param {rocket.Elements} parent + */ +beestat.component.modal.enjoy_beestat.prototype.decorate_contents_ = function(parent) { + switch (this.is_active_patron_()) { + case false: + parent.appendChild($.createElement('p').innerText('Your Patreon account is connected but you\'re not currently a supporter. If you recently became a supporter it could take up to 24 hours to update.')); + break; + case null: + parent.appendChild($.createElement('p').innerHTML('If you didn\'t notice, beestat doesn\'t run ads, charge money, or sell your data. If you find beestat useful, please consider supporting the project on Patreon. Your contribution helps pay for servers, storage, and other cool things. Thanks!')); + parent.appendChild($.createElement('p').innerHTML('Not into Patreon? Here are some other ways to help.')); + break; + } +}; + +/** + * Get the title. + * + * @return {string} The title. + */ +beestat.component.modal.enjoy_beestat.prototype.get_title_ = function() { + return 'Enjoy beestat?'; +}; + +/** + * Close the modal but run some special code first to make sure any running + * interval gets stopped. + */ +beestat.component.modal.enjoy_beestat.prototype.dispose = function() { + if (this.is_polling_ === true) { + beestat.remove_poll_interval(beestat.component.modal.enjoy_beestat.poll_interval_); + beestat.dispatcher.removeEventListener('poll.enjoy_beestat'); + } + + beestat.component.modal.prototype.dispose.apply(this, arguments); +}; + +/** + * Hide the Patreon card for some amount of time. + * + * @param {number} amount How long. + * @param {string} unit The unit (day, month, etc). + */ +beestat.component.modal.enjoy_beestat.prototype.hide_patreon_card_for_ = function(amount, unit) { + beestat.setting( + 'patreon_hide_until', + moment().utc() + .add(amount, unit) + .format('YYYY-MM-DD HH:mm:ss') + ); + beestat.cards.patreon.dispose(); +}; + +/** + * Determine whether or not the current user is an active Patron. + * + * @return {boolean} true if yes, false if no, null if not connected. + */ +beestat.component.modal.enjoy_beestat.prototype.is_active_patron_ = function() { + var user = beestat.get_user(); + if (user.patreon_status !== null) { + return (user.patreon_status.patron_status === 'active_patron'); + } + return null; +}; + +/** + * Get the buttons on the modal. + * + * @return {[beestat.component.button]} The buttons. + */ +beestat.component.modal.enjoy_beestat.prototype.get_buttons_ = function() { + var self = this; + + var hide = new beestat.component.button() + .set_background_color('#fff') + .set_text_color(beestat.style.color.gray.base) + .set_text_hover_color(beestat.style.color.bluegray.base) + .set_text('Hide for one month') + .addEventListener('click', function() { + self.hide_patreon_card_for_(1, 'month'); + self.dispose(); + }); + + if (self.is_active_patron_() === null) { + var link = new beestat.component.button() + .set_text('Link Patreon') + .set_background_color(beestat.style.color.green.base) + .set_background_hover_color(beestat.style.color.green.light) + .set_text_color('#fff') + .addEventListener('click', function() { + this + .set_background_color(beestat.style.color.gray.base) + .set_background_hover_color() + .set_text('Waiting for Patreon...') + .removeEventListener('click'); + + beestat.add_poll_interval(beestat.component.modal.enjoy_beestat.poll_interval_); + self.is_polling_ = true; + + beestat.dispatcher.addEventListener('poll.enjoy_beestat', function() { + switch (self.is_active_patron_()) { + case true: + // Connected and is Patron + beestat.cards.patreon.dispose(); + self.dispose(); + break; + case false: + // Connected but isn't Patron + self.hide_patreon_card_for_(3, 'day'); + self.dispose(); + break; + } + }); + + window.open('../api/?resource=patreon&method=authorize&arguments={}&api_key=ER9Dz8t05qUdui0cvfWi5GiVVyHP6OB8KPuSisP2'); + }); + + return [ + hide, + link + ]; + } + + var ok = new beestat.component.button() + .set_background_color(beestat.style.color.green.base) + .set_background_hover_color(beestat.style.color.green.light) + .set_text_color('#fff') + .set_text('OK') + .addEventListener('click', function() { + self.dispose(); + }); + + return [ + hide, + ok + ]; +}; diff --git a/js/js.php b/js/js.php index 7a715db..e7fc44d 100755 --- a/js/js.php +++ b/js/js.php @@ -86,7 +86,7 @@ if($setting->get('environment') === 'dev' || $setting->get('environment') === 'd echo '' . PHP_EOL; echo '' . PHP_EOL; echo '' . PHP_EOL; - echo '' . PHP_EOL; + echo '' . PHP_EOL; echo '' . PHP_EOL; echo '' . PHP_EOL; echo '' . PHP_EOL;