1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00
joplin/ReactNativeClient/lib/folders-screen-utils.js

77 lines
1.8 KiB
JavaScript
Raw Normal View History

2017-12-14 20:12:14 +02:00
const Folder = require('lib/models/Folder.js');
const Setting = require('lib/models/Setting.js');
2017-07-15 17:54:19 +02:00
class FoldersScreenUtils {
static async allForDisplay(options = {}) {
const orderDir = Setting.value('folders.sortOrder.reverse') ? 'DESC' : 'ASC';
2019-07-29 15:43:53 +02:00
const folderOptions = Object.assign(
{},
{
caseInsensitive: true,
order: [
{
by: 'title',
dir: orderDir,
},
],
},
options
);
let folders = await Folder.all(folderOptions);
2017-10-08 00:17:10 +02:00
if (Setting.value('folders.sortOrder.field') === 'last_note_user_updated_time') {
folders = await Folder.orderByLastModified(folders, orderDir);
}
if (Setting.value('showNoteCounts')) {
await Folder.addNoteCounts(folders,
Setting.value('showCompletedTodos'));
}
return folders;
}
static async refreshFolders() {
FoldersScreenUtils.refreshCalls_.push(true);
try {
const folders = await this.allForDisplay({ includeConflictFolder: true });
this.dispatch({
type: 'FOLDER_UPDATE_ALL',
items: folders,
});
} finally {
FoldersScreenUtils.refreshCalls_.pop();
}
2017-07-15 17:54:19 +02:00
}
static scheduleRefreshFolders() {
if (this.scheduleRefreshFoldersIID_) clearTimeout(this.scheduleRefreshFoldersIID_);
this.scheduleRefreshFoldersIID_ = setTimeout(() => {
this.scheduleRefreshFoldersIID_ = null;
this.refreshFolders();
}, 1000);
}
static async cancelTimers() {
if (this.scheduleRefreshFoldersIID_) {
clearTimeout(this.scheduleRefreshFoldersIID_);
this.scheduleRefreshFoldersIID_ = null;
}
return new Promise((resolve) => {
const iid = setInterval(() => {
if (!FoldersScreenUtils.refreshCalls_.length) {
clearInterval(iid);
resolve();
}
}, 100);
});
}
2017-07-15 17:54:19 +02:00
}
FoldersScreenUtils.refreshCalls_ = [];
2019-07-29 15:43:53 +02:00
module.exports = { FoldersScreenUtils };