Skip to content

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

TSN680 - Unneeded rendering with all items on clearing the search (#1449)

Stanimirdc73f4937d28
diff --git a/app/components/FolderContainer.tsx b/app/components/FolderContainer.tsx
index 436e985c3..9dddaa8fd 100644
--- a/app/components/FolderContainer.tsx
+++ b/app/components/FolderContainer.tsx
@@ -37,11 +37,7 @@ import MapiquePerspectiveIcon from '@material-ui/icons/Map';
import LocationMenu from './menus/LocationMenu';
import DirectoryMenu from './menus/DirectoryMenu';
import i18n from '../services/i18n';
-import {
- getPerspectives,
- getMaxSearchResults,
- getDesktopMode
-} from '-/reducers/settings';
+import { getMaxSearchResults, getDesktopMode } from '-/reducers/settings';
import { getLocations } from '-/reducers/locations';
import {
actions as AppActions,
@@ -614,7 +610,7 @@ function mapStateToProps(state) {
return {
settings: state.settings,
lastSelectedEntry: getLastSelectedEntry(state),
- perspectives: getPerspectives(state),
+ // perspectives: getPerspectives(state),
directoryContent: getDirectoryContent(state),
currentDirectoryPerspective: getCurrentDirectoryPerspective(state),
searchResultCount: getSearchResultCount(state),
@@ -652,8 +648,20 @@ function mapActionCreatorsToProps(dispatch) {
);
}
+const areEqual = (prevProp, nextProp) =>
+ nextProp.currentDirectoryPath === prevProp.currentDirectoryPath &&
+ nextProp.currentDirectoryPerspective ===
+ prevProp.currentDirectoryPerspective &&
+ nextProp.currentLocationPath === prevProp.currentLocationPath &&
+ JSON.stringify(nextProp.directoryContent) ===
+ JSON.stringify(prevProp.directoryContent) &&
+ JSON.stringify(nextProp.openedFiles) ===
+ JSON.stringify(prevProp.openedFiles) &&
+ nextProp.windowWidth === prevProp.windowWidth &&
+ nextProp.windowHeight === prevProp.windowHeight;
+
export default connect(
mapStateToProps,
mapActionCreatorsToProps
// @ts-ignore
-)(withStyles(styles)(withTheme(FolderContainer)));
+)(withStyles(styles)(withTheme(React.memo(FolderContainer, areEqual))));
diff --git a/app/components/LocationManager.tsx b/app/components/LocationManager.tsx
index cf013005a..e065cd97e 100644
--- a/app/components/LocationManager.tsx
+++ b/app/components/LocationManager.tsx
@@ -32,7 +32,7 @@ import {
getLocations
} from '../reducers/locations';
import { actions as AppActions } from '../reducers/app';
-import { getPerspectives, isDesktopMode } from '-/reducers/settings';
+import { isDesktopMode } from '-/reducers/settings';
import i18n from '../services/i18n';
import AppConfig from '../config';
import LoadingLazy from '-/components/LoadingLazy';
@@ -55,7 +55,7 @@ interface Props {
classes: any;
style: any;
locations: Array<TS.Location>;
- perspectives: Array<Object>;
+ // perspectives: Array<Object>;
hideDrawer: () => void;
openURLExternally: (path: string) => void;
toggleOpenLinkDialog: () => void;
@@ -304,7 +304,7 @@ const LocationManager = (props: Props) => {
function mapStateToProps(state) {
return {
locations: getLocations(state),
- perspectives: getPerspectives(state),
+ // perspectives: getPerspectives(state),
isDesktop: isDesktopMode(state)
};
}
diff --git a/app/components/LocationView.tsx b/app/components/LocationView.tsx
index 302e6020d..75a7011d1 100644
--- a/app/components/LocationView.tsx
+++ b/app/components/LocationView.tsx
@@ -84,7 +84,7 @@ interface Props {
changeLocation: (loc: TS.Location) => void;
}
-const LocationView = React.memo((props: Props) => {
+const LocationView = (props: Props) => {
const directoryTreeRef = useRef<DirectoryTreeViewRef>(null);
const [
locationDirectoryContextMenuAnchorEl,
@@ -323,7 +323,7 @@ const LocationView = React.memo((props: Props) => {
/>
</>
);
-});
+};
function mapStateToProps(state) {
return {
@@ -356,4 +356,4 @@ export default connect(
mapStateToProps,
mapDispatchToProps
// @ts-ignore
-)(withStyles(styles)(LocationView));
+)(withStyles(styles)(React.memo(LocationView)));
diff --git a/app/components/Search.tsx b/app/components/Search.tsx
index c3c31fc61..0cbd12c82 100644
--- a/app/components/Search.tsx
+++ b/app/components/Search.tsx
@@ -102,7 +102,7 @@ interface Props {
showUnixHiddenEntries: boolean;
}
-const Search = React.memo((props: Props) => {
+const Search = (props: Props) => {
const [, forceUpdate] = useReducer(x => x + 1, 0);
const textQuery = useRef<string>(props.searchQuery.textQuery);
// const tagsAND = useRef<Array<TS.Tag>>(props.searchQuery.tagsAND);
@@ -1210,7 +1210,7 @@ const Search = React.memo((props: Props) => {
</div>
</div>
);
-});
+};
function mapStateToProps(state) {
return {
@@ -1240,7 +1240,13 @@ function mapDispatchToProps(dispatch) {
);
}
+const areEqual = (prevProp, nextProp) =>
+ nextProp.indexing === prevProp.indexing &&
+ nextProp.searchQuery === prevProp.searchQuery &&
+ nextProp.currentDirectory === prevProp.currentDirectory &&
+ JSON.stringify(nextProp.searches) === JSON.stringify(prevProp.searches);
+
export default connect(
mapStateToProps,
mapDispatchToProps
-)(withStyles(styles, { withTheme: true })(Search));
+)(withStyles(styles, { withTheme: true })(React.memo(Search, areEqual)));
diff --git a/app/components/TagContainer.tsx b/app/components/TagContainer.tsx
index 1c52b9f5f..05af6f862 100644
--- a/app/components/TagContainer.tsx
+++ b/app/components/TagContainer.tsx
@@ -52,7 +52,7 @@ interface Props {
selectedEntries?: Array<TS.FileSystemEntry>;
}
-const TagContainer = React.memo((props: Props) => {
+const TagContainer = (props: Props) => {
const {
tag,
deleteIcon,
@@ -232,7 +232,7 @@ const TagContainer = React.memo((props: Props) => {
</Button>
</div>
);
-});
+};
function mapStateToProps(state) {
return {
@@ -243,4 +243,4 @@ function mapStateToProps(state) {
};
}
-export default connect(mapStateToProps)(TagContainer);
+export default connect(mapStateToProps)(React.memo(TagContainer));
diff --git a/app/containers/MainPage.tsx b/app/containers/MainPage.tsx
index 590323909..91297eb87 100644
--- a/app/containers/MainPage.tsx
+++ b/app/containers/MainPage.tsx
@@ -97,6 +97,7 @@ import ProgressDialog from '-/components/dialogs/ProgressDialog';
import useEventListener from '-/utils/useEventListener';
import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
import { TS } from '-/tagspaces.namespace';
+import useTraceUpdate from "-/utils/useTraceUpdate";
const initialSplitSize = 44;
const drawerWidth = 300;
@@ -315,6 +316,7 @@ if (window.ExtDefaultVerticalPanel === 'none') {
} */
const MainPage = (props: Props) => {
+ // useTraceUpdate(props);
/* const [selectedDirectoryPath, setSelectedDirectoryPath] = useState<string>(
''
); */
@@ -942,13 +944,50 @@ function mapDispatchToProps(dispatch) {
);
}
+const areEqual = (prevProp, nextProp) => nextProp.directoryPath === prevProp.directoryPath &&
+ nextProp.isAboutDialogOpened === prevProp.isAboutDialogOpened &&
+ nextProp.isCreateDirectoryOpened === prevProp.isCreateDirectoryOpened &&
+ nextProp.isCreateFileDialogOpened === prevProp.isCreateFileDialogOpened &&
+ nextProp.isDeleteMultipleEntriesDialogOpened ===
+ prevProp.isDeleteMultipleEntriesDialogOpened &&
+ nextProp.isDesktopMode === prevProp.isDesktopMode &&
+ nextProp.isEditTagDialogOpened === prevProp.isEditTagDialogOpened &&
+ nextProp.isEntryInFullWidth === prevProp.isEntryInFullWidth &&
+ nextProp.isHelpFeedbackPanelOpened === prevProp.isHelpFeedbackPanelOpened &&
+ nextProp.isIndexing === prevProp.isIndexing &&
+ nextProp.isKeysDialogOpened === prevProp.isKeysDialogOpened &&
+ nextProp.isLicenseDialogOpened === prevProp.isLicenseDialogOpened &&
+ nextProp.isLocationManagerPanelOpened ===
+ prevProp.isLocationManagerPanelOpened &&
+ nextProp.isOnboardingDialogOpened === prevProp.isOnboardingDialogOpened &&
+ nextProp.isOpenLinkDialogOpened === prevProp.isOpenLinkDialogOpened &&
+ nextProp.isPerspectivesPanelOpened === prevProp.isPerspectivesPanelOpened &&
+ nextProp.isProgressDialogOpened === prevProp.isProgressDialogOpened &&
+ nextProp.isReadOnlyMode === prevProp.isReadOnlyMode &&
+ nextProp.isSearchPanelOpened === prevProp.isSearchPanelOpened &&
+ nextProp.isSettingsDialogOpened === prevProp.isSettingsDialogOpened &&
+ nextProp.isTagLibraryPanelOpened === prevProp.isTagLibraryPanelOpened &&
+ nextProp.isThirdPartyLibsDialogOpened ===
+ prevProp.isThirdPartyLibsDialogOpened &&
+ nextProp.isUpdateAvailable === prevProp.isUpdateAvailable &&
+ nextProp.isUploadProgressDialogOpened ===
+ prevProp.isUploadProgressDialogOpened &&
+ nextProp.leftSplitSize === prevProp.leftSplitSize &&
+ nextProp.mainSplitSize === prevProp.mainSplitSize &&
+ JSON.stringify(nextProp.notificationStatus) ===
+ JSON.stringify(prevProp.notificationStatus) &&
+ JSON.stringify(nextProp.selectedEntries) ===
+ JSON.stringify(prevProp.selectedEntries) &&
+ JSON.stringify(nextProp.openedFiles) ===
+ JSON.stringify(prevProp.openedFiles);
+
export default withDnDContext(
connect(
mapStateToProps,
mapDispatchToProps
)(
translate(['core'], { wait: true })(
- withStyles(styles, { withTheme: true })(MainPage)
+ withStyles(styles, { withTheme: true })(React.memo(MainPage, areEqual))
)
)
);
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index 25da0556d..753911660 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -923,7 +923,10 @@ export const actions = {
fsEntryMeta?: TS.FileSystemEntryMeta
) => (dispatch: (actions: Object) => void, getState: () => any) => {
const { settings } = getState();
- dispatch(actions.loadDirectorySuccessInt(directoryPath, [], true)); // this is to reset directoryContent (it will reset color too)
+ /* const { currentDirectoryPath } = getState().app;
+ if (currentDirectoryPath !== directoryPath) {
+ dispatch(actions.loadDirectorySuccessInt(directoryPath, [], true)); // this is to reset directoryContent (it will reset color too)
+ } */
// dispatch(actions.setCurrentDirectoryColor('')); // this is to reset color only
dispatch(actions.showNotification(i18n.t('core:loading'), 'info', false));
PlatformIO.listDirectoryPromise(directoryPath, false)
@@ -1527,16 +1530,17 @@ export const actions = {
if (entryProps) {
const { supportedFileTypes } = getState().settings;
- let entryForOpening: OpenedEntry = openedFiles.find(
- obj => obj.path === entryPath
- );
+ let entryForOpening: OpenedEntry;
+ const entryExist = openedFiles.find(obj => obj.path === entryPath);
- if (!entryForOpening) {
+ if (!entryExist) {
entryForOpening = findExtensionsForEntry(
supportedFileTypes,
entryPath,
entryProps.isFile
);
+ } else {
+ entryForOpening = { ...entryExist };
}
if (fsEntryMeta.changed !== undefined) {
diff --git a/app/reducers/settings-default.ts b/app/reducers/settings-default.ts
index 11fe5f19b..67cc9ab9c 100644
--- a/app/reducers/settings-default.ts
+++ b/app/reducers/settings-default.ts
@@ -160,12 +160,12 @@ export default {
entryPropertiesSplitSize: 103,
leftVerticalSplitSize: 350,
mainVerticalSplitSize: '50%',
- supportedPerspectives: [
+ /* supportedPerspectives: [
{
id: 'perspectiveList',
name: 'List'
}
- ],
+ ], */
supportedThemes: ['light', 'dark'],
supportedLanguages: [
{
diff --git a/app/reducers/settings.ts b/app/reducers/settings.ts
index fb84e92a2..d4b1e5677 100644
--- a/app/reducers/settings.ts
+++ b/app/reducers/settings.ts
@@ -617,8 +617,8 @@ export const getKeyBindingObject = (state: any) =>
generateKeyBindingObject(state.settings.keyBindings);
export const getSupportedFileTypes = (state: any) =>
state.settings.supportedFileTypes;
-export const getPerspectives = (state: any) =>
- state.settings.supportedPerspectives;
+/* export const getPerspectives = (state: any) =>
+ state.settings.supportedPerspectives; */
export const getTagColor = (state: any) => state.settings.tagBackgroundColor;
export const getTagTextColor = (state: any) => state.settings.tagTextColor;
export const getCurrentTheme = (state: any) => state.settings.currentTheme;
diff --git a/app/utils/HandleAuth.tsx b/app/utils/HandleAuth.tsx
index 7e509d00f..7d1a03a9d 100644
--- a/app/utils/HandleAuth.tsx
+++ b/app/utils/HandleAuth.tsx
@@ -18,7 +18,7 @@ interface Props {
addLocations: (locations: Array<TS.Location>, override: boolean) => void;
importTagGroups: (tagGroups: Array<TS.TagGroup>, replace: boolean) => void;
}
-const HandleAuth = React.memo((props: Props) => {
+const HandleAuth = (props: Props) => {
const username = useRef(undefined);
React.useEffect(() => {
@@ -116,7 +116,7 @@ const HandleAuth = React.memo((props: Props) => {
});
return null;
-});
+};
function mapDispatchToProps(dispatch) {
return bindActionCreators(
@@ -130,4 +130,4 @@ function mapDispatchToProps(dispatch) {
);
}
-export default connect(undefined, mapDispatchToProps)(HandleAuth);
+export default connect(undefined, mapDispatchToProps)(React.memo(HandleAuth));
diff --git a/app/utils/useTraceUpdate.ts b/app/utils/useTraceUpdate.ts
new file mode 100644
index 000000000..dbf6efea3
--- /dev/null
+++ b/app/utils/useTraceUpdate.ts
@@ -0,0 +1,23 @@
+import { useEffect, useRef } from 'react';
+
+export default function useTraceUpdate(props) {
+ const prev = useRef(props);
+
+ useEffect(() => {
+ if (
+ process.env.NODE_ENV === 'development' ||
+ process.env.DEBUG_PROD === 'true'
+ ) {
+ const changedProps = Object.entries(props).reduce((ps, [k, v]) => {
+ if (prev.current[k] !== v) {
+ ps[k] = [prev.current[k], v];
+ }
+ return ps;
+ }, {});
+ if (Object.keys(changedProps).length > 0) {
+ console.log('Changed props:', changedProps);
+ }
+ prev.current = props;
+ }
+ });
+}