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);
if (!iError) {
const counts = {},
const
// counts = {},
accounts = oData.Result.Accounts,
mainEmail = SettingsGet('MainEmail');
if (isArray(accounts)) {
AccountUserStore.accounts.forEach(oAccount =>
counts[oAccount.email] = oAccount.count()
);
// AccountUserStore.accounts.forEach(oAccount => counts[oAccount.email] = oAccount.count());
delegateRunOnDestroy(AccountUserStore.accounts());
AccountUserStore.accounts(
accounts.map(
sValue => new AccountModel(sValue, counts[sValue])
sValue => new AccountModel(sValue/*, counts[sValue]*/)
)
);
// 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)) {

View file

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

View file

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

View file

@ -5,18 +5,7 @@ export const AccountUserStore = {
accounts: ko.observableArray(),
loading: ko.observable(false).extend({ debounce: 100 }),
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;
// }),
getEmailAddresses: () => AccountUserStore.accounts.map(item => item.email)
};
addObservablesTo(AccountUserStore, {

View file

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

View file

@ -31,7 +31,10 @@ export class SystemDropDownUserView extends AbstractViewRight {
this.accounts = AccountUserStore.accounts;
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({
currentAudio: '',

View file

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