1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-23 22:36:32 +02:00

Chore: Refactor folder related functions to TypeScript

This commit is contained in:
Laurent Cozic
2024-01-06 17:21:51 +00:00
parent 68e04f944f
commit 763716397b
12 changed files with 116 additions and 104 deletions

View File

@@ -13,7 +13,7 @@ import SyncTargetOneDrive from './SyncTargetOneDrive';
import { createStore, applyMiddleware, Store } from 'redux';
const { defaultState, stateUtils } = require('./reducer');
import JoplinDatabase from './JoplinDatabase';
const { FoldersScreenUtils } = require('./folders-screen-utils.js');
import { cancelTimers as folderScreenUtilsCancelTimers, refreshFolders, scheduleRefreshFolders } from './folders-screen-utils';
const { DatabaseDriverNode } = require('./database-driver-node.js');
import BaseModel from './BaseModel';
import Folder from './models/Folder';
@@ -107,7 +107,7 @@ export default class BaseApplication {
await ResourceFetcher.instance().destroy();
await SearchEngine.instance().destroy();
await DecryptionWorker.instance().destroy();
await FoldersScreenUtils.cancelTimers();
await folderScreenUtilsCancelTimers();
await BaseItem.revisionService_.cancelTimers();
await ResourceService.instance().cancelTimers();
await reg.cancelTimers();
@@ -418,8 +418,7 @@ export default class BaseApplication {
const result = next(action);
let refreshNotes = false;
let refreshFolders: boolean | string = false;
// let refreshTags = false;
let doRefreshFolders: boolean | string = false;
let refreshNotesUseSelectedNoteId = false;
let refreshNotesHash = '';
@@ -434,7 +433,7 @@ export default class BaseApplication {
// Don't add FOLDER_UPDATE_ALL as refreshFolders() is calling it too, which
// would cause the sidebar to refresh all the time.
if (this.hasGui() && ['FOLDER_UPDATE_ONE'].indexOf(action.type) >= 0) {
refreshFolders = true;
doRefreshFolders = true;
}
if (action.type === 'HISTORY_BACKWARD' || action.type === 'HISTORY_FORWARD') {
@@ -510,23 +509,23 @@ export default class BaseApplication {
action.changedFields.includes('encryption_applied') ||
action.changedFields.includes('is_conflict')
) {
refreshFolders = true;
doRefreshFolders = true;
}
}
if (action.type === 'NOTE_DELETE') {
refreshFolders = true;
doRefreshFolders = true;
}
if (this.hasGui() && action.type === 'SETTING_UPDATE_ALL') {
refreshFolders = 'now';
doRefreshFolders = 'now';
}
if (this.hasGui() && action.type === 'SETTING_UPDATE_ONE' && (
action.key.indexOf('folders.sortOrder') === 0 ||
action.key === 'showNoteCounts' ||
action.key === 'showCompletedTodos')) {
refreshFolders = 'now';
doRefreshFolders = 'now';
}
if (this.hasGui() && action.type === 'SYNC_GOT_ENCRYPTED_ITEM') {
@@ -543,11 +542,11 @@ export default class BaseApplication {
await this.applySettingsSideEffects();
}
if (refreshFolders) {
if (refreshFolders === 'now') {
await FoldersScreenUtils.refreshFolders();
if (doRefreshFolders) {
if (doRefreshFolders === 'now') {
await refreshFolders((action: any) => this.dispatch(action));
} else {
await FoldersScreenUtils.scheduleRefreshFolders();
await scheduleRefreshFolders((action: any) => this.dispatch(action));
}
}
return result;
@@ -571,8 +570,6 @@ export default class BaseApplication {
});
BaseModel.dispatch = this.store().dispatch;
FoldersScreenUtils.dispatch = this.store().dispatch;
// reg.dispatch = this.store().dispatch;
BaseSyncTarget.dispatch = this.store().dispatch;
DecryptionWorker.instance().dispatch = this.store().dispatch;
ResourceFetcher.instance().dispatch = this.store().dispatch;
@@ -582,8 +579,6 @@ export default class BaseApplication {
public deinitRedux() {
this.store_ = null;
BaseModel.dispatch = function() {};
FoldersScreenUtils.dispatch = function() {};
// reg.dispatch = function() {};
BaseSyncTarget.dispatch = function() {};
DecryptionWorker.instance().dispatch = function() {};
ResourceFetcher.instance().dispatch = function() {};