2018-05-09 13:39:17 +02:00
|
|
|
const Setting = require('lib/models/Setting');
|
2019-02-24 20:02:50 +02:00
|
|
|
const Tag = require('lib/models/Tag');
|
2018-05-21 17:26:01 +02:00
|
|
|
const { reg } = require('lib/registry.js');
|
2018-05-09 13:39:17 +02:00
|
|
|
|
2019-02-24 20:02:50 +02:00
|
|
|
const reduxSharedMiddleware = async function(store, next, action) {
|
2018-05-09 11:49:31 +02:00
|
|
|
const newState = store.getState();
|
|
|
|
|
2019-02-24 20:02:50 +02:00
|
|
|
let refreshTags = false;
|
|
|
|
|
2018-05-09 11:49:31 +02:00
|
|
|
if (action.type == 'FOLDER_SET_COLLAPSED' || action.type == 'FOLDER_TOGGLE') {
|
|
|
|
Setting.setValue('collapsedFolderIds', newState.collapsedFolderIds);
|
|
|
|
}
|
2018-05-21 17:26:01 +02:00
|
|
|
|
|
|
|
if (action.type === 'SETTING_UPDATE_ONE' && !!action.key.match(/^sync\.\d+\.path$/)) {
|
|
|
|
reg.resetSyncTarget();
|
|
|
|
}
|
2019-02-24 20:02:50 +02:00
|
|
|
|
|
|
|
if (action.type == 'NOTE_DELETE') {
|
|
|
|
refreshTags = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (refreshTags) {
|
|
|
|
store.dispatch({
|
|
|
|
type: 'TAG_UPDATE_ALL',
|
|
|
|
items: await Tag.allWithNotes(),
|
|
|
|
});
|
|
|
|
}
|
2018-05-09 11:49:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = reduxSharedMiddleware;
|