From f788d3f1b7dac0056847b174457fac6090321c44 Mon Sep 17 00:00:00 2001 From: Alex Kutuzaki Date: Sun, 9 Jun 2019 19:29:03 +0300 Subject: [PATCH] feat: toggle user stats and notifications visibility --- src/js/index.js | 73 +++++++++++++++++++++++++------------------------ src/js/user.js | 4 ++- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/src/js/index.js b/src/js/index.js index 6794807..c0475ee 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -29,42 +29,12 @@ const priorityIcon = { TrelloPowerUp.initialize({ 'board-buttons': async t => { let buttons; - const currentUser = await new Storage(t).getUser(); - - const settingsPage = tt => - tt.popup({ - title: 'Settings', - url: './settings.html', - height: 270 - }); - - const loginPage = tt => - tt.popup({ - title: 'Log in Habitica', - url: './login.html', - height: 340 - }); + const storage = new Storage(t); + const currentUser = await storage.getUser(); + const settings = await storage.getSettings(); if (currentUser.loggedIn) { buttons = [ - { - condition: 'always', - icon: { - dark: ICONS.EXP, - light: ICONS.EXP - }, - text: currentUser.exp - ? `${currentUser.exp} / ${currentUser.expToNextLevel}` - : '?' - }, - { - condition: 'always', - icon: { - dark: ICONS.GOLD, - light: ICONS.GOLD - }, - text: currentUser.gold ? currentUser.gold.toFixed(2) : '?' - }, { condition: 'always', icon: { @@ -72,9 +42,37 @@ TrelloPowerUp.initialize({ light: ICONS.HABITICA_LOGO }, text: currentUser.name, - callback: settingsPage + callback: tt => + tt.popup({ + title: 'Settings', + url: './settings.html', + height: 270 + }) } ]; + + if (settings.showStats) { + buttons.unshift( + { + condition: 'always', + icon: { + dark: ICONS.EXP, + light: ICONS.EXP + }, + text: currentUser.exp + ? `${currentUser.exp} / ${currentUser.expToNextLevel}` + : '?' + }, + { + condition: 'always', + icon: { + dark: ICONS.GOLD, + light: ICONS.GOLD + }, + text: currentUser.gold ? currentUser.gold.toFixed(2) : '?' + } + ); + } } else { buttons = [ { @@ -84,7 +82,12 @@ TrelloPowerUp.initialize({ light: ICONS.HABITICA_LOGO }, text: 'Login', - callback: loginPage + callback: tt => + tt.popup({ + title: 'Log in Habitica', + url: './login.html', + height: 340 + }) } ]; } diff --git a/src/js/user.js b/src/js/user.js index 1e09088..aa33d7b 100644 --- a/src/js/user.js +++ b/src/js/user.js @@ -29,8 +29,10 @@ export default class Task { } async notifyAboutStats({ exp, gold }) { - const currentUser = await this.storage.getUser(); + const settings = await this.storage.getSettings(); + if (!settings.showStatsNotifications) return undefined; + const currentUser = await this.storage.getUser(); const expDiff = currentUser.exp ? exp - currentUser.exp : exp; const goldDiff = currentUser.gold ? gold - currentUser.gold : gold;