Skip to content

Commit

Permalink
feat: toggle user stats and notifications visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
alexktzk committed Jun 9, 2019
1 parent 50fef04 commit f788d3f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 36 deletions.
73 changes: 38 additions & 35 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,52 +29,50 @@ 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: {
dark: ICONS.HABITICA_LOGO,
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 = [
{
Expand All @@ -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
})
}
];
}
Expand Down
4 changes: 3 additions & 1 deletion src/js/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit f788d3f

Please sign in to comment.