mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-03 14:37:02 +03:00
Updated subscribables
This commit is contained in:
parent
4b6f6b1bfc
commit
004eba6be2
7 changed files with 200 additions and 219 deletions
|
|
@ -2,7 +2,7 @@ import ko from 'ko';
|
|||
|
||||
import { FolderType } from 'Common/EnumsUser';
|
||||
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
|
||||
import { addObservablesTo } from 'Common/Utils';
|
||||
import { addObservablesTo, addSubscribablesTo } from 'Common/Utils';
|
||||
import { folderListOptionsBuilder } from 'Common/UtilsUser';
|
||||
import { getFolderInboxName, getFolderFromCacheList } from 'Common/Cache';
|
||||
import { SettingsGet } from 'Common/Globals';
|
||||
|
|
@ -125,18 +125,19 @@ export const FolderUserStore = new class {
|
|||
)
|
||||
);
|
||||
|
||||
const fRemoveSystemFolderType = (observable) => () => {
|
||||
const folder = getFolderFromCacheList(observable());
|
||||
if (folder) {
|
||||
folder.type(FolderType.User);
|
||||
}
|
||||
};
|
||||
const fSetSystemFolderType = (type) => (value) => {
|
||||
const folder = getFolderFromCacheList(value);
|
||||
if (folder) {
|
||||
folder.type(type);
|
||||
}
|
||||
};
|
||||
const
|
||||
fRemoveSystemFolderType = (observable) => () => {
|
||||
const folder = getFolderFromCacheList(observable());
|
||||
if (folder) {
|
||||
folder.type(FolderType.User);
|
||||
}
|
||||
},
|
||||
fSetSystemFolderType = type => value => {
|
||||
const folder = getFolderFromCacheList(value);
|
||||
if (folder) {
|
||||
folder.type(type);
|
||||
}
|
||||
};
|
||||
|
||||
this.sentFolder.subscribe(fRemoveSystemFolderType(this.sentFolder), this, 'beforeChange');
|
||||
this.draftFolder.subscribe(fRemoveSystemFolderType(this.draftFolder), this, 'beforeChange');
|
||||
|
|
@ -144,11 +145,13 @@ export const FolderUserStore = new class {
|
|||
this.trashFolder.subscribe(fRemoveSystemFolderType(this.trashFolder), this, 'beforeChange');
|
||||
this.archiveFolder.subscribe(fRemoveSystemFolderType(this.archiveFolder), this, 'beforeChange');
|
||||
|
||||
this.sentFolder.subscribe(fSetSystemFolderType(FolderType.SentItems), this);
|
||||
this.draftFolder.subscribe(fSetSystemFolderType(FolderType.Draft), this);
|
||||
this.spamFolder.subscribe(fSetSystemFolderType(FolderType.Spam), this);
|
||||
this.trashFolder.subscribe(fSetSystemFolderType(FolderType.Trash), this);
|
||||
this.archiveFolder.subscribe(fSetSystemFolderType(FolderType.Archive), this);
|
||||
addSubscribablesTo(this, {
|
||||
sentFolder: fSetSystemFolderType(FolderType.SentItems),
|
||||
draftFolder: fSetSystemFolderType(FolderType.Draft),
|
||||
spamFolder: fSetSystemFolderType(FolderType.Spam),
|
||||
trashFolder: fSetSystemFolderType(FolderType.Trash),
|
||||
archiveFolder: fSetSystemFolderType(FolderType.Archive)
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import ko from 'ko';
|
|||
import { Notification } from 'Common/Enums';
|
||||
import { Focused, MessageSetAction } from 'Common/EnumsUser';
|
||||
import { doc, elementById } from 'Common/Globals';
|
||||
import { pInt, pString, addObservablesTo } from 'Common/Utils';
|
||||
import { pInt, pString, addObservablesTo, addSubscribablesTo } from 'Common/Utils';
|
||||
import { plainToHtml } from 'Common/UtilsUser';
|
||||
|
||||
import {
|
||||
|
|
@ -170,52 +170,53 @@ export const MessageUserStore = new class {
|
|||
// Subscribers
|
||||
|
||||
let timer = 0, fn = this.listLoadingAnimation;
|
||||
this.listCompleteLoading.subscribe(value => {
|
||||
if (value) {
|
||||
fn(value);
|
||||
} else if (fn()) {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => {
|
||||
|
||||
addSubscribablesTo(this, {
|
||||
listCompleteLoading: value => {
|
||||
if (value) {
|
||||
fn(value);
|
||||
} else if (fn()) {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => {
|
||||
fn(value);
|
||||
timer = 0;
|
||||
}, 700);
|
||||
} else {
|
||||
fn(value);
|
||||
timer = 0;
|
||||
}, 700);
|
||||
} else {
|
||||
fn(value);
|
||||
}
|
||||
});
|
||||
|
||||
this.listLoading.subscribe(value =>
|
||||
this.listCompleteLoading(value || this.listIsNotCompleted())
|
||||
);
|
||||
this.listIsNotCompleted.subscribe(value =>
|
||||
this.listCompleteLoading(value || this.listLoading())
|
||||
);
|
||||
|
||||
this.list.subscribe(
|
||||
(list => {
|
||||
list.forEach(item =>
|
||||
item && item.newForAnimation() && item.newForAnimation(false)
|
||||
)
|
||||
}).debounce(500)
|
||||
);
|
||||
|
||||
this.message.subscribe(message => {
|
||||
if (message) {
|
||||
if (!SettingsUserStore.usePreviewPane()) {
|
||||
AppUserStore.focusedState(Focused.MessageView);
|
||||
}
|
||||
} else {
|
||||
AppUserStore.focusedState(Focused.MessageList);
|
||||
},
|
||||
|
||||
this.messageFullScreenMode(false);
|
||||
this.hideMessageBodies();
|
||||
}
|
||||
});
|
||||
listLoading: value =>
|
||||
this.listCompleteLoading(value || this.listIsNotCompleted()),
|
||||
|
||||
this.listEndFolder.subscribe(folder => {
|
||||
const message = this.message();
|
||||
if (message && folder && folder !== message.folder) {
|
||||
this.message(null);
|
||||
listIsNotCompleted: value =>
|
||||
this.listCompleteLoading(value || this.listLoading()),
|
||||
|
||||
list:
|
||||
(list => {
|
||||
list.forEach(item =>
|
||||
item && item.newForAnimation() && item.newForAnimation(false)
|
||||
)
|
||||
}).debounce(500),
|
||||
|
||||
message: message => {
|
||||
if (message) {
|
||||
if (!SettingsUserStore.usePreviewPane()) {
|
||||
AppUserStore.focusedState(Focused.MessageView);
|
||||
}
|
||||
} else {
|
||||
AppUserStore.focusedState(Focused.MessageList);
|
||||
|
||||
this.messageFullScreenMode(false);
|
||||
this.hideMessageBodies();
|
||||
}
|
||||
},
|
||||
|
||||
listEndFolder: folder => {
|
||||
const message = this.message();
|
||||
if (message && folder && folder !== message.folder) {
|
||||
this.message(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue