Skip to content

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

improving performance by using functions instead of components

Ilian Sapundshiev398f3bdf23b7
diff --git a/app/components/FileSourceDnd.js b/app/components/FileSourceDnd.js
index fb49c2555..312f39e92 100644
--- a/app/components/FileSourceDnd.js
+++ b/app/components/FileSourceDnd.js
@@ -23,7 +23,6 @@ import type { ConnectDragSource } from 'react-dnd';
import DragItemTypes from './DragItemTypes';
type Props = {
-
children: Array<Object>,
connectDragSource: ConnectDragSource
};
@@ -52,29 +51,7 @@ const boxSource = {
} */
};
-class FileSourceDnd extends React.Component<Props> {
- /* componentDidMount() {
- const xml = '<svg version="1.1" height="25" width="100" xmlns="http://www.w3.org/2000/svg">' +
- '<g>' +
- '<rect x="0" y="0" rx="5" ry="5" width="100%" height="100%" style="fill:' + this.props.tag.color + ';opacity:0.5" />' +
- '<text x="50%" y="55%" font-family="Roboto,Arial,Helvetica,Sans" font-size="13" dominant-baseline="middle" text-anchor="middle" fill="' + this.props.tag.textcolor + '">' + this.props.tag.title + '</text>' +
- '</g>' +
- '</svg>';
- const img = new Image();
- img.src = `data:image/svg+xml;charset=utf-8,${xml.replace(/(\r\n|\n|\r)/gm, '')}`;
- img.onload = () => this.props.connectDragPreview(img, { anchorX: 1, anchorY: 0 });
- // this.props.connectDragPreview(getEmptyImage(), { captureDraggingState: true });
- } */
-
- render() {
- const { connectDragSource } = this.props;
-
- return connectDragSource(
- <span>
- {this.props.children}
- </span>);
- }
-}
+const FileSourceDnd = (props: Props) => props.connectDragSource(<span>{props.children}</span>);
export default DragSource(DragItemTypes.FILE, boxSource, (connect, monitor) => ({
connectDragSource: connect.dragSource(),
diff --git a/app/components/TagDropContainer.js b/app/components/TagDropContainer.js
index 4fe3b3002..599290d73 100644
--- a/app/components/TagDropContainer.js
+++ b/app/components/TagDropContainer.js
@@ -17,7 +17,7 @@
* @flow
*/
-import React, { Component } from 'react';
+import React from 'react';
import { DropTarget } from 'react-dnd';
import DragItemTypes from './DragItemTypes';
@@ -36,29 +36,32 @@ const boxTarget = {
},
};
-class TagDropContainer extends Component<Props> {
- render() {
- const { canDrop, isOver, connectDropTarget } = this.props;
- const isActive = canDrop && isOver;
+const TagDropContainer = (props: Props) => {
+ const { canDrop, isOver, connectDropTarget } = props;
+ const isActive = canDrop && isOver;
- let backgroundColor = 'transparent';
- if (isActive) {
- backgroundColor = 'rgb(233, 233, 233)';
- } else if (canDrop) {
- backgroundColor = 'rgb(212, 212, 212)';
- }
-
- return connectDropTarget(
- <div
- style={{
- backgroundColor
- }}
- >
- {this.props.children}
- </div>,
- );
+ let border = '1px solid transparent';
+ let backgroundColor = 'transparent';
+ if (isActive) {
+ border = '1px solid rgb(233, 233, 233)';
+ backgroundColor = 'rgb(233, 233, 233)';
+ } else if (canDrop) {
+ border = '1px solid rgb(212, 212, 212)';
+ backgroundColor = 'rgb(212, 212, 212)';
}
-}
+
+ return connectDropTarget(
+ <div
+ style={{
+ border,
+ backgroundColor,
+ borderRadius: 3
+ }}
+ >
+ {props.children}
+ </div>,
+ );
+};
export default DropTarget(DragItemTypes.TAG, boxTarget, (connect, monitor) => ({
connectDropTarget: connect.dropTarget(),
diff --git a/app/components/TargetMoveFileBox.js b/app/components/TargetMoveFileBox.js
index 37288908e..ebb2278bf 100644
--- a/app/components/TargetMoveFileBox.js
+++ b/app/components/TargetMoveFileBox.js
@@ -37,7 +37,7 @@ const styles = theme => ({
justifyContent: 'center',
alignItems: 'center',
textAlign: 'center',
- fontSize: '30px',
+ fontSize: '20px',
fontWeight: 'bold',
color: 'white',
}
@@ -57,18 +57,16 @@ type Props = {
children: Object
};
-class TargetMoveFileBox extends React.Component<Props> {
- render() {
- const { classes, canDrop, isOver, connectDropTarget, children } = this.props;
- const dragContent = canDrop && isOver ? (<div className={classes.dropzone}>{i18n.t('core:releaseToMoveDrop')}</div>) : undefined;
- return connectDropTarget(
- <div>
- {dragContent}
- {children}
- </div>
- );
- }
-}
+const TargetMoveFileBox = (props: Props) => {
+ const { classes, canDrop, isOver, connectDropTarget, children } = props;
+ const dragContent = canDrop && isOver ? (<div className={classes.dropzone}>{i18n.t('core:releaseToMoveDrop')}</div>) : undefined;
+ return connectDropTarget(
+ <div>
+ {dragContent}
+ {children}
+ </div>
+ );
+};
export default withStyles(styles, { withTheme: true })(DropTarget(props => props.accepts, boxTarget, (connect, monitor) => ({
connectDropTarget: connect.dropTarget(),