Skip to content

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

Slow dnd tagging by many tags (#1568)

Stanimir602996b82128
diff --git a/app/components/CustomDragLayer.tsx b/app/components/CustomDragLayer.tsx
index 9a1ae603e..52efa55d8 100644
--- a/app/components/CustomDragLayer.tsx
+++ b/app/components/CustomDragLayer.tsx
@@ -1,7 +1,7 @@
import React from 'react';
import { XYCoord, useDragLayer } from 'react-dnd';
import { FilesDragPreview } from './FilesDragPreview';
-import { TagDragPreview } from './TagDragPreview';
+import TagDragPreview from './TagDragPreview';
import DragItemTypes from '-/components/DragItemTypes';
const layerStyles: React.CSSProperties = {
@@ -36,7 +36,7 @@ function getItemStyles(
export interface CustomDragLayerProps {}
-export const CustomDragLayer: React.FC<CustomDragLayerProps> = props => {
+const CustomDragLayer: React.FC<CustomDragLayerProps> = props => {
const {
itemType,
isDragging,
@@ -56,9 +56,7 @@ export const CustomDragLayer: React.FC<CustomDragLayerProps> = props => {
function renderItem() {
switch (itemType) {
case DragItemTypes.FILE:
- return (
- <FilesDragPreview entries={item.selectedEntries} path={item.path} />
- );
+ return <FilesDragPreview entries={item.selectedEntries} path={item.path} />;
case DragItemTypes.TAG:
return <TagDragPreview tag={item.tag} />;
@@ -78,3 +76,5 @@ export const CustomDragLayer: React.FC<CustomDragLayerProps> = props => {
</div>
);
};
+
+export default React.memo(CustomDragLayer);
diff --git a/app/components/FilesDragPreview.tsx b/app/components/FilesDragPreview.tsx
index 4d68364fe..bdabb4600 100644
--- a/app/components/FilesDragPreview.tsx
+++ b/app/components/FilesDragPreview.tsx
@@ -1,4 +1,4 @@
-import React, { memo } from 'react';
+import React from 'react';
import Avatar from '@material-ui/core/Avatar';
import Chip from '@material-ui/core/Chip';
@@ -7,7 +7,7 @@ export interface Props {
path: string;
}
-export const FilesDragPreview = memo((props: Props) => {
+export const FilesDragPreview = (props: Props) => {
const { entries, path } = props;
return (
<Chip
@@ -17,4 +17,6 @@ export const FilesDragPreview = memo((props: Props) => {
color="primary"
/>
);
-});
+};
+const areEqual = (prevProp, nextProp) => nextProp.path === prevProp.path;
+export default React.memo(FilesDragPreview, areEqual);
diff --git a/app/components/TagDragPreview.tsx b/app/components/TagDragPreview.tsx
index e6bed5b94..31b9acff1 100644
--- a/app/components/TagDragPreview.tsx
+++ b/app/components/TagDragPreview.tsx
@@ -1,4 +1,4 @@
-import React, { memo } from 'react';
+import React from 'react';
import TagContainer from '-/components/TagContainer';
import { TS } from '-/tagspaces.namespace';
@@ -6,7 +6,10 @@ export interface Props {
tag: TS.Tag;
}
-export const TagDragPreview = memo((props: Props) => {
+const TagDragPreview = (props: Props) => {
const { tag } = props;
return <TagContainer tag={tag} isDragging={true} />;
-});
+};
+const areEqual = (prevProp, nextProp) =>
+ nextProp.tag.title === prevProp.tag.title;
+export default React.memo(TagDragPreview, areEqual);
diff --git a/app/containers/MainPage.tsx b/app/containers/MainPage.tsx
index c291eb19b..293a610e9 100644
--- a/app/containers/MainPage.tsx
+++ b/app/containers/MainPage.tsx
@@ -76,7 +76,7 @@ import AppConfig from '../config';
import i18n from '../services/i18n';
import LoadingLazy from '../components/LoadingLazy';
import withDnDContext from '-/containers/withDnDContext';
-import { CustomDragLayer } from '-/components/CustomDragLayer';
+import CustomDragLayer from '-/components/CustomDragLayer';
import IOActions from '-/reducers/io-actions';
import FileUploadDialog from '-/components/dialogs/FileUploadDialog';
import ProgressDialog from '-/components/dialogs/ProgressDialog';