Skip to content

TagSpaces is an offline, open source, document manager with tagging support

performance optimizations by updating the state

Ilian Sapundshiev002308be63a8
diff --git a/app/reducers/app.js b/app/reducers/app.js
index 8210160b7..61d9e7025 100644
--- a/app/reducers/app.js
+++ b/app/reducers/app.js
@@ -323,7 +323,36 @@ export default (state: Object = initialState, action: Object) => {
return state;
}
case types.REFLECT_RENAME_ENTRY: {
- const indexForRenaming = state.currentDirectoryEntries.findIndex((entry) => entry.path === action.path);
+ return {
+ ...state,
+ currentDirectoryEntries: state.currentDirectoryEntries.map((entry) => {
+ if (entry.path !== action.path) {
+ return entry;
+ }
+ return {
+ ...entry,
+ path: action.newPath,
+ // thumbPath: getThumbFileLocationForFile(action.newPath), // not needed due timing issue
+ name: extractFileName(action.newPath),
+ extension: extractFileExtension(action.newPath),
+ tags: [
+ ...entry.tags.filter(tag => tag.type === 'sidecar'), // add only sidecar tags
+ ...extractTagsAsObjects(action.newPath) // , getTagDelimiter(state)) TODO https://itnext.io/passing-state-between-reducers-in-redux-318de6db06cd
+ ]
+ };
+ }),
+ openedFiles: state.openedFiles.map((entry) => {
+ if (entry.path !== action.path) {
+ return entry;
+ }
+ return {
+ ...entry,
+ path: action.newPath, // TODO handle change extension case
+ shouldReload: true,
+ };
+ })
+ };
+/* const indexForRenaming = state.currentDirectoryEntries.findIndex((entry) => entry.path === action.path);
const indexForRenamingInOpenedFiles = state.openedFiles.findIndex((entry) => entry.path === action.path);
let directoryEntries = state.currentDirectoryEntries;
let openedFiles = state.openedFiles;
@@ -363,10 +392,34 @@ export default (state: Object = initialState, action: Object) => {
openedFiles
};
}
- return state;
+ return state; */
}
case types.REFLECT_UPDATE_SIDECARTAGS: {
- const indexForUpdating = state.currentDirectoryEntries.findIndex((entry) => entry.path === action.path);
+ return {
+ ...state,
+ currentDirectoryEntries: state.currentDirectoryEntries.map((entry) => {
+ if (entry.path !== action.path) {
+ return entry;
+ }
+ return {
+ ...entry,
+ tags: [
+ ...entry.tags.filter(tag => tag.type === 'plain'),
+ ...action.tags
+ ]
+ };
+ }),
+ openedFiles: state.openedFiles.map((entry) => {
+ if (entry.path !== action.path) {
+ return entry;
+ }
+ return {
+ ...entry,
+ shouldReload: true,
+ };
+ })
+ };
+/* const indexForUpdating = state.currentDirectoryEntries.findIndex((entry) => entry.path === action.path);
const indexForUpdatingInOpenedFiles = state.openedFiles.findIndex((entry) => entry.path === action.path);
let directoryEntries = state.currentDirectoryEntries;
let openedFiles = state.openedFiles;
@@ -402,10 +455,31 @@ export default (state: Object = initialState, action: Object) => {
openedFiles
};
}
- return state;
+ return state; */
}
case types.REFLECT_UPDATE_SIDECARMETA: {
- const indexForUpdating = state.currentDirectoryEntries.findIndex((entry) => entry.path === action.path);
+ return {
+ ...state,
+ currentDirectoryEntries: state.currentDirectoryEntries.map((entry) => {
+ if (entry.path !== action.path) {
+ return entry;
+ }
+ return {
+ ...entry,
+ ...action.entryMeta
+ };
+ }),
+ openedFiles: state.openedFiles.map((entry) => {
+ if (entry.path !== action.path) {
+ return entry;
+ }
+ return {
+ ...entry,
+ shouldReload: true,
+ };
+ })
+ };
+/* const indexForUpdating = state.currentDirectoryEntries.findIndex((entry) => entry.path === action.path);
const indexForUpdatingInOpenedFiles = state.openedFiles.findIndex((entry) => entry.path === action.path);
let directoryEntries = state.currentDirectoryEntries;
let openedFiles = state.openedFiles;
@@ -438,7 +512,7 @@ export default (state: Object = initialState, action: Object) => {
openedFiles
};
}
- return state;
+ return state; */
}
case types.CLOSE_ALL_FILES: {
window.history.pushState('', 'TagSpaces', location.pathname);
diff --git a/app/reducers/location-index.js b/app/reducers/location-index.js
index ce859a50a..5199eefc0 100644
--- a/app/reducers/location-index.js
+++ b/app/reducers/location-index.js
@@ -101,7 +101,7 @@ export default (state: Object = initialState, action: Object) => {
return state;
}
case types.REFLECT_CREATE_ENTRY: {
- const entryIndex = state.currentDirectoryEntries.findIndex((entry) => entry.path === action.newEntry.path);
+ const entryIndex = state.currentDirectoryIndex.findIndex((entry) => entry.path === action.newEntry.path);
if (entryIndex) {
return state;
}