1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-02-04 19:16:07 +02:00
joplin/ReactNativeClient/lib/folders-screen-utils.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-12-14 18:12:14 +00:00
const Folder = require('lib/models/Folder.js');
const Setting = require('lib/models/Setting.js');
2017-07-15 16:54:19 +01:00
class FoldersScreenUtils {
static async allForDisplay(options = {}) {
const orderDir = Setting.value('folders.sortOrder.reverse') ? 'DESC' : 'ASC';
const folderOptions = Object.assign({}, {
caseInsensitive: true,
order: [{
by: 'title',
dir: orderDir,
}]
}, options);
let folders = await Folder.all(folderOptions);
2017-10-07 23:17:10 +01:00
if (Setting.value('folders.sortOrder.field') === 'last_note_user_updated_time') {
folders = await Folder.orderByLastModified(folders, orderDir);
}
return folders;
}
static async refreshFolders() {
const folders = await this.allForDisplay({ includeConflictFolder: true });
2017-07-15 16:54:19 +01:00
this.dispatch({
2017-11-08 21:22:24 +00:00
type: 'FOLDER_UPDATE_ALL',
items: folders,
2017-07-15 16:54:19 +01:00
});
}
static scheduleRefreshFolders() {
if (this.scheduleRefreshFoldersIID_) clearTimeout(this.scheduleRefreshFoldersIID_);
this.scheduleRefreshFoldersIID_ = setTimeout(() => {
this.scheduleRefreshFoldersIID_ = null;
this.refreshFolders();
}, 1000);
}
2017-07-15 16:54:19 +01:00
}
module.exports = { FoldersScreenUtils };