Better observable naming in MessageUserStore

This commit is contained in:
djmaze 2021-12-15 19:02:36 +01:00
parent 2aceb89a8b
commit b95541892f
4 changed files with 29 additions and 38 deletions

View file

@ -88,9 +88,10 @@ export const MessageUserStore = new class {
listEndPage: 1,
listLoading: false,
listLoadingAnimation: false,
listIsNotCompleted: false,
listCompleteLoading: false,
// Happens when message(s) removed from list
listIsIncomplete: false,
// when this.listLoading || this.listIsIncomplete
listIsLoading: false,
selectorMessageSelected: null,
selectorMessageFocused: null,
@ -112,6 +113,13 @@ export const MessageUserStore = new class {
// Computed Observables
addComputablesTo(this, {
/*
listIsLoading: () => {
const value = this.listLoading() | this.listIsIncomplete();
$htmlCL.toggle('list-loading', value);
return value;
},
*/
listEndHash: () =>
this.listEndFolder() +
'|' +
@ -168,30 +176,14 @@ export const MessageUserStore = new class {
// Subscribers
let timer = 0, fn = this.listLoadingAnimation;
addSubscribablesTo(this, {
listCompleteLoading: value => {
if (value) {
fn(value);
} else if (fn()) {
clearTimeout(timer);
timer = setTimeout(() => {
fn(value);
timer = 0;
}, 700);
} else {
fn(value);
}
},
listLoadingAnimation: value => $htmlCL.toggle('list-loading', value),
listIsLoading: value => $htmlCL.toggle('list-loading', value),
listLoading: value =>
this.listCompleteLoading(value || this.listIsNotCompleted()),
this.listIsLoading(value || this.listIsIncomplete()),
listIsNotCompleted: value =>
this.listCompleteLoading(value || this.listLoading()),
listIsIncomplete: value =>
this.listIsLoading(value || this.listLoading()),
message: message => {
clearTimeout(MessageSeenTimer);
@ -323,7 +315,7 @@ export const MessageUserStore = new class {
if (copy) {
messages.forEach(item => item.checked(false));
} else {
this.listIsNotCompleted(true);
this.listIsIncomplete(true);
messages.forEach(item => {
if (currentMessage && currentMessage.hash === item.hash) {
@ -639,8 +631,7 @@ export const MessageUserStore = new class {
if (collection) {
let unreadCountChange = false;
const iCount = collection.MessageResultCount,
iOffset = collection.Offset,
const
folder = getFolderFromCacheList(collection.Folder);
if (folder && !cached) {
@ -664,9 +655,9 @@ export const MessageUserStore = new class {
this.initUidNextAndNewMessages(folder.fullName, collection.UidNext, collection.NewMessages);
}
this.listCount(iCount);
this.listCount(collection.MessageResultCount);
this.listSearch(pString(collection.Search));
this.listPage(Math.ceil(iOffset / SettingsUserStore.messagesPerPage() + 1));
this.listPage(Math.ceil(collection.Offset / SettingsUserStore.messagesPerPage() + 1));
this.listThreadUid(data.Result.ThreadUid);
this.listEndFolder(collection.Folder);
@ -677,7 +668,7 @@ export const MessageUserStore = new class {
this.listDisableAutoSelect(true);
this.list(collection);
this.listIsNotCompleted(false);
this.listIsIncomplete(false);
clearNewMessageCache();

View file

@ -82,7 +82,7 @@ export class MailMessageList extends AbstractViewRight {
this.messageListEndThreadUid = MessageUserStore.listEndThreadUid;
this.messageListCompleteLoadingThrottle = MessageUserStore.listCompleteLoading;
this.messageListIsLoading = MessageUserStore.listIsLoading;
initOnStartOrLangChange(() => this.emptySubjectValue = i18n('MESSAGE_LIST/EMPTY_SUBJECT_TEXT'));
@ -263,7 +263,7 @@ export class MailMessageList extends AbstractViewRight {
}
reloadCommand() {
if (!MessageUserStore.listLoadingAnimation()) {
if (!MessageUserStore.listIsLoading()) {
rl.app.reloadMessageList(false, true);
}
}
@ -602,7 +602,7 @@ export class MailMessageList extends AbstractViewRight {
listEmptyMessage() {
if (!this.dragOver()
&& !MessageUserStore.list().length
&& !MessageUserStore.listCompleteLoading()
&& !MessageUserStore.listIsLoading()
&& !MessageUserStore.listError()) {
return i18n('MESSAGE_LIST/EMPTY_' + (MessageUserStore.listSearch() ? 'SEARCH_' : '') + 'LIST');
}

View file

@ -177,7 +177,7 @@ export class MailMessageView extends AbstractViewRight {
},
messageListOrViewLoading:
() => MessageUserStore.listCompleteLoading() | MessageUserStore.messageLoading()
() => MessageUserStore.listIsLoading() | MessageUserStore.messageLoading()
});
this.addSubscribables({

View file

@ -167,18 +167,18 @@
<i class="fontastic"></i>
<span data-i18n="MESSAGE_LIST/BACK_TO_MESSAGE_LIST"></span>
</div>
<div class="listSearchDesc" data-bind="visible: '' !== messageListSearchDesc(), text: messageListSearchDesc"></div>
<div class="listDragOver" data-bind="css: {'viewAppendArea': dragOver() && '' === messageListError() && !popupVisibility(), 'dragOverEnter': dragOverEnter }, initDom: dragOverArea">
<div class="listSearchDesc" data-bind="visible: messageListSearchDesc(), text: messageListSearchDesc"></div>
<div class="listDragOver" data-bind="css: {'viewAppendArea': dragOver() && !messageListError() && !popupVisibility(), 'dragOverEnter': dragOverEnter }, initDom: dragOverArea">
<i class="fontastic"></i>
<span data-i18n="MESSAGE_LIST/PUT_MESSAGE_HERE"></span>
</div>
<div class="listClear" data-bind="visible: clearListIsVisible()">
<a href="#" class="g-ui-link" data-i18n="MESSAGE_LIST/BUTTON_EMPTY_FOLDER" data-bind="command: clearCommand"></a>
</div>
<div class="listError error" data-bind="visible: !dragOver() && '' !== messageListError(), text: messageListError"></div>
<div class="listError error" data-bind="visible: !dragOver() && messageListError(), text: messageListError"></div>
<div class="listEmptyMessage" data-bind="visible: listEmptyMessage(), text: listEmptyMessage()"></div>
<div class="listLoading" data-bind="visible: !dragOver() && 0 === messageList().length &&
messageListCompleteLoadingThrottle() && '' === messageListError()">
<div class="listLoading" data-bind="visible: !dragOver() && !messageList().length &&
messageListIsLoading() && !messageListError()">
<i class="icon-spinner"></i>
<span data-i18n="GLOBAL/LOADING"></span>
</div>