Cleanup additional accounts in system menu

This commit is contained in:
djmaze 2021-12-02 11:12:21 +01:00
parent 64e77de103
commit 0d809dd574
7 changed files with 25 additions and 44 deletions

View file

@ -419,24 +419,23 @@ class AppUser extends AbstractApp {
IdentityUserStore.loading(false); IdentityUserStore.loading(false);
if (!iError) { if (!iError) {
const counts = {}, const
// counts = {},
accounts = oData.Result.Accounts, accounts = oData.Result.Accounts,
mainEmail = SettingsGet('MainEmail'); mainEmail = SettingsGet('MainEmail');
if (isArray(accounts)) { if (isArray(accounts)) {
AccountUserStore.accounts.forEach(oAccount => // AccountUserStore.accounts.forEach(oAccount => counts[oAccount.email] = oAccount.count());
counts[oAccount.email] = oAccount.count()
);
delegateRunOnDestroy(AccountUserStore.accounts()); delegateRunOnDestroy(AccountUserStore.accounts());
AccountUserStore.accounts( AccountUserStore.accounts(
accounts.map( accounts.map(
sValue => new AccountModel(sValue, counts[sValue]) sValue => new AccountModel(sValue/*, counts[sValue]*/)
) )
); );
// accounts.length && // accounts.length &&
AccountUserStore.accounts.unshift(new AccountModel(mainEmail, counts[mainEmail], false)); AccountUserStore.accounts.unshift(new AccountModel(mainEmail/*, counts[mainEmail]*/, false));
} }
if (isArray(oData.Result.Identities)) { if (isArray(oData.Result.Identities)) {

View file

@ -6,13 +6,13 @@ export class AccountModel extends AbstractModel {
* @param {boolean=} canBeDelete = true * @param {boolean=} canBeDelete = true
* @param {number=} count = 0 * @param {number=} count = 0
*/ */
constructor(email, count = 0, isAdditional = true) { constructor(email/*, count = 0*/, isAdditional = true) {
super(); super();
this.email = email; this.email = email;
this.addObservables({ this.addObservables({
count: count || 0, // count: count || 0,
deleteAccess: false, deleteAccess: false,
isAdditional: isAdditional isAdditional: isAdditional
}); });

View file

@ -87,12 +87,12 @@ export class MailBoxUserScreen extends AbstractScreen {
addEventListener('mailbox.inbox-unread-count', e => { addEventListener('mailbox.inbox-unread-count', e => {
FolderUserStore.foldersInboxUnreadCount(e.detail); FolderUserStore.foldersInboxUnreadCount(e.detail);
/* // Disabled in SystemDropDown.html
const email = AccountUserStore.email(); const email = AccountUserStore.email();
AccountUserStore.accounts.forEach(item => AccountUserStore.accounts.forEach(item =>
item && email === item.email && item.count(e.detail) item && email === item.email && item.count(e.detail)
); );
*/
this.updateWindowTitle(); this.updateWindowTitle();
}); });
} }

View file

@ -5,18 +5,7 @@ export const AccountUserStore = {
accounts: ko.observableArray(), accounts: ko.observableArray(),
loading: ko.observable(false).extend({ debounce: 100 }), loading: ko.observable(false).extend({ debounce: 100 }),
getEmailAddresses: () => AccountUserStore.accounts.map(item => item.email), getEmailAddresses: () => AccountUserStore.accounts.map(item => item.email)
accountsUnreadCount: ko.computed(() => 0),
// accountsUnreadCount: ko.computed(() => {
// let result = 0;
// AccountUserStore.accounts().forEach(item => {
// if (item) {
// result += item.count();
// }
// });
// return result;
// }),
}; };
addObservablesTo(AccountUserStore, { addObservablesTo(AccountUserStore, {

View file

@ -71,13 +71,6 @@
white-space: nowrap; white-space: nowrap;
} }
.account-item {
&:not(.current) i:first-child,
&.current i + i {
display: none;
}
}
.counter { .counter {
display: inline-block; display: inline-block;
} }

View file

@ -31,7 +31,10 @@ export class SystemDropDownUserView extends AbstractViewRight {
this.accounts = AccountUserStore.accounts; this.accounts = AccountUserStore.accounts;
this.accountsLoading = AccountUserStore.loading; this.accountsLoading = AccountUserStore.loading;
this.accountsUnreadCount = AccountUserStore.accountsUnreadCount; /*
this.accountsUnreadCount = : ko.computed(() => 0);
this.accountsUnreadCount = : ko.computed(() => AccountUserStore.accounts().reduce((result, item) => result + item.count(), 0));
*/
this.addObservables({ this.addObservables({
currentAudio: '', currentAudio: '',

View file

@ -17,21 +17,18 @@
</a> </a>
<ul class="dropdown-menu right-edge" tabindex="-1" role="menu" aria-labelledby="top-system-dropdown-id"> <ul class="dropdown-menu right-edge" tabindex="-1" role="menu" aria-labelledby="top-system-dropdown-id">
<!-- ko if: accounts().length -->
<!-- ko foreach: accounts --> <!-- ko foreach: accounts -->
<li role="presentation"> <li role="presentation">
<a class="account-item" href="#" data-bind="click: $root.accountClick, css: {'current': $root.accountEmail() === email}"> <a class="account-item" href="#" data-bind="click: $root.accountClick">
<!-- <b class="pull-right counter" data-bind="visible: count()"> <!-- <b class="pull-right counter" data-bind="visible: count()">
<span data-bind="text: count, visible: 100 > count()"></span> <span data-bind="text: count, visible: 100 > count()"></span>
<span data-bind="visible: 99 < count()">99+</span> <span data-bind="visible: 99 < count()">99+</span>
</b>--> </b>-->
<i class="fontastic"></i> <i class="fontastic" data-bind="text: $root.accountEmail() === email ? '✔' : '👤'"></i>
<i class="fontastic">👤</i>
<span class="email-title" data-bind="text: email, attr: {title: email}"></span> <span class="email-title" data-bind="text: email, attr: {title: email}"></span>
</a> </a>
</li> </li>
<!-- /ko --> <!-- /ko -->
<!-- /ko -->
<li class="dividerbar" role="presentation" data-bind="visible: allowAccounts"> <li class="dividerbar" role="presentation" data-bind="visible: allowAccounts">
<a href="#" tabindex="-1" data-bind="click: addAccountClick"> <a href="#" tabindex="-1" data-bind="click: addAccountClick">