1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-12 08:54:00 +02:00
joplin/ReactNativeClient/lib/components/shared/reduxSharedMiddleware.js

36 lines
962 B
JavaScript
Raw Normal View History

const Setting = require('lib/models/Setting');
const Tag = require('lib/models/Tag');
const { reg } = require('lib/registry.js');
const ResourceFetcher = require('lib/services/ResourceFetcher');
const reduxSharedMiddleware = async function(store, next, action) {
const newState = store.getState();
let refreshTags = false;
if (action.type == 'FOLDER_SET_COLLAPSED' || action.type == 'FOLDER_TOGGLE') {
Setting.setValue('collapsedFolderIds', newState.collapsedFolderIds);
}
if (action.type === 'SETTING_UPDATE_ONE' && !!action.key.match(/^sync\.\d+\.path$/)) {
reg.resetSyncTarget();
}
if (action.type === 'SETTING_UPDATE_ONE' && action.key === 'sync.resourceDownloadMode') {
ResourceFetcher.instance().autoAddResources();
}
if (action.type == 'NOTE_DELETE') {
refreshTags = true;
}
if (refreshTags) {
store.dispatch({
type: 'TAG_UPDATE_ALL',
items: await Tag.allWithNotes(),
});
}
2019-07-29 15:43:53 +02:00
};
2019-07-29 15:43:53 +02:00
module.exports = reduxSharedMiddleware;