TagSpaces is an offline, open source, document manager with tagging support
improving performance for dialogs
Ilian Sapundshievd36d557da73c
diff --git a/app/components/dialogs/ConfirmDialog.js b/app/components/dialogs/ConfirmDialog.jsindex 3e8e86596..c44dad544 100644--- a/app/components/dialogs/ConfirmDialog.js+++ b/app/components/dialogs/ConfirmDialog.js@@ -23,15 +23,11 @@ import DialogActions from '@material-ui/core/DialogActions';import DialogContent from '@material-ui/core/DialogContent';import DialogTitle from '@material-ui/core/DialogTitle';import DialogContentText from '@material-ui/core/DialogContentText';-import List from '@material-ui/core/List';import ListItem from '@material-ui/core/ListItem';import Typography from '@material-ui/core/Typography';-import { withStyles } from '@material-ui/core/styles';import GenericDialog from './GenericDialog';import i18n from '../../services/i18n';-const styles = theme => ({});-type Props = {open: boolean,title: string,@@ -44,59 +40,57 @@ type Props = {onClose: () => void};-class ConfirmDialog extends React.Component<Props> {- onConfirm = (result) => {- this.props.confirmCallback(result);- this.props.onClose();- };+const ConfirmDialog = (props: Props) => {+ function onConfirm(result) {+ props.confirmCallback(result);+ props.onClose();+ }- renderTitle = () => (- <DialogTitle>{this.props.title}</DialogTitle>- );+ function renderTitle() {+ return (<DialogTitle>{props.title}</DialogTitle>);+ }- renderContent = () => (- <DialogContent>- <DialogContentText data-tid={this.props.confirmDialogContentTID}>- {this.props.content}- {this.props.list && this.props.list.map((listItem) => (+ function renderContent() {+ return (<DialogContent>+ <DialogContentText data-tid={props.confirmDialogContentTID}>+ {props.content}+ {props.list && props.list.map((listItem) => (<ListItem title={listItem}><Typography variant="inherit" noWrap>{listItem}</Typography></ListItem>))}</DialogContentText>- </DialogContent>- );+ </DialogContent>);+ }- renderActions = () => (- <DialogActions>+ function renderActions() {+ return (<DialogActions><Button- onClick={() => this.onConfirm(false)}+ onClick={() => onConfirm(false)}color="primary"- data-tid={this.props.cancelDialogTID}+ data-tid={props.cancelDialogTID}>{i18n.t('core:no')}</Button><Button- data-tid={this.props.confirmDialogTID}- onClick={() => this.onConfirm(true)}+ data-tid={props.confirmDialogTID}+ onClick={() => onConfirm(true)}color="primary">{i18n.t('core:yes')}</Button>- </DialogActions>- );-- render() {- return (- <GenericDialog- open={this.props.open}- onClose={this.props.onClose}- renderTitle={this.renderTitle}- renderContent={this.renderContent}- renderActions={this.renderActions}- />- );+ </DialogActions>);}-}-export default withStyles(styles)(ConfirmDialog);+ return (+ <GenericDialog+ open={props.open}+ onClose={props.onClose}+ renderTitle={renderTitle}+ renderContent={renderContent}+ renderActions={renderActions}+ />+ );+};++export default ConfirmDialog;diff --git a/app/components/dialogs/GenericDialog.js b/app/components/dialogs/GenericDialog.jsindex 8908c4703..a2b4022e2 100644--- a/app/components/dialogs/GenericDialog.js+++ b/app/components/dialogs/GenericDialog.js@@ -47,56 +47,52 @@ export function onEnterKeyHandler(event: any, confirmFunction: () => void) {}}-class GenericDialog extends React.Component<Props> {- onConfirm = () => { // should be overwritten in the children classes- this.props.onClose();- };+const GenericDialog = (props: Props) => {+ // function renderTitle() {+ // return (+ // <DialogTitle>Dialog</DialogTitle>+ // );+ // }- renderTitle = () => (- <DialogTitle>Dialog</DialogTitle>- );+ // function renderContent() {+ // return (+ // <DialogContent>+ // <DialogContentText>+ // Some content+ // </DialogContentText>+ // </DialogContent>+ // );+ // }- renderContent = () => (- <DialogContent>- <DialogContentText>- Some content- </DialogContentText>- </DialogContent>- );+ // function renderActions() {+ // return (+ // <DialogActions>+ // <Button onClick={props.onClose} color="primary">+ // {i18n.t('core:cancel')}+ // </Button>+ // </DialogActions>+ // );+ // }- renderActions = () => (- <DialogActions>- <Button onClick={this.props.onClose} color="primary">- {i18n.t('core:cancel')}- </Button>- </DialogActions>+ const {+ fullScreen,+ open,+ onEnterKey,+ } = props;+ return (+ <Dialog+ fullScreen={fullScreen}+ open={open}+ TransitionComponent={Transition}+ keepMounted+ onClose={props.onClose}+ onKeyDown={onEnterKey || ((event) => onEnterKeyHandler(event, props.onClose))}+ >+ {props.renderTitle && props.renderTitle()}+ {props.renderContent && props.renderContent()}+ {props.renderActions && props.renderActions()}+ </Dialog>);-- render() {- const {- fullScreen,- open,- onEnterKey,- onClose,- renderTitle,- renderContent,- renderActions- } = this.props;- return (- <Dialog- fullScreen={fullScreen}- open={open}- TransitionComponent={Transition}- keepMounted- onClose={this.props.onClose}- onKeyDown={onEnterKey || ((event) => onEnterKeyHandler(event, onClose))}- >- {renderTitle && renderTitle()}- {renderContent ? renderContent() : this.renderContent()}- {renderActions && renderActions()}- </Dialog>- );- }-}+};export default GenericDialog;diff --git a/app/components/menus/FileMenu.js b/app/components/menus/FileMenu.jsindex e2361c33c..921d0df46 100644--- a/app/components/menus/FileMenu.js+++ b/app/components/menus/FileMenu.js@@ -31,7 +31,6 @@ import MoveCopy from '@material-ui/icons/FileCopy';import RenameFile from '@material-ui/icons/FormatTextdirectionLToR';import DeleteForever from '@material-ui/icons/DeleteForever';import i18n from '../../services/i18n';-import { extractContainingDirectoryPath } from '../../utils/paths';type Props = {anchorEl?: Object | null,@@ -47,121 +46,119 @@ type Props = {selectedFilePath?: string};-class FileMenu extends React.Component<Props> {- showDeleteFileDialog = () => {- this.props.onClose();- this.props.openDeleteFileDialog();- };+const FileMenu = (props: Props) => {+ function showDeleteFileDialog() {+ props.onClose();+ props.openDeleteFileDialog();+ }- showRenameFileDialog = () => {- this.props.onClose();- this.props.openRenameFileDialog();- };+ function showRenameFileDialog() {+ props.onClose();+ props.openRenameFileDialog();+ }- showMoveCopyFilesDialog = () => {- this.props.onClose();- this.props.openMoveCopyFilesDialog();- };+ function showMoveCopyFilesDialog() {+ props.onClose();+ props.openMoveCopyFilesDialog();+ }- showAddRemoveTagsDialog = () => {- this.props.onClose();- this.props.openAddRemoveTagsDialog();- };+ function showAddRemoveTagsDialog() {+ props.onClose();+ props.openAddRemoveTagsDialog();+ }- showInFileManager = () => {- this.props.onClose();- if (this.props.selectedFilePath) {- this.props.showInFileManager(this.props.selectedFilePath);+ function showInFileManager() {+ props.onClose();+ if (props.selectedFilePath) {+ props.showInFileManager(props.selectedFilePath);}- };+ }- openFileNatively = () => {- this.props.onClose();- if (this.props.selectedFilePath) {- this.props.openFileNatively(this.props.selectedFilePath);+ function openFileNatively() {+ props.onClose();+ if (props.selectedFilePath) {+ props.openFileNatively(props.selectedFilePath);}- };+ }- openFile = () => {- this.props.onClose();- if (this.props.selectedFilePath) {- this.props.openFile(this.props.selectedFilePath);+ function openFile() {+ props.onClose();+ if (props.selectedFilePath) {+ props.openFile(props.selectedFilePath);}- };+ }- render() {- return (- <div style={{ overflowY: 'hidden !important' }}>- <Menu- anchorEl={this.props.anchorEl}- open={this.props.open}- onClose={this.props.onClose}+ return (+ <div style={{ overflowY: 'hidden !important' }}>+ <Menu+ anchorEl={props.anchorEl}+ open={props.open}+ onClose={props.onClose}+ >+ <MenuItem+ data-tid="fileMenuOpenFile"+ onClick={openFile}>- <MenuItem- data-tid="fileMenuOpenFile"- onClick={this.openFile}- >- <ListItemIcon>- <OpenFile />- </ListItemIcon>- <ListItemText inset primary={i18n.t('core:openFile')} />- </MenuItem>- <MenuItem- data-tid="fileMenuRenameFile"- onClick={this.showRenameFileDialog}- >- <ListItemIcon>- <RenameFile />- </ListItemIcon>- <ListItemText inset primary={i18n.t('core:renameFile')} />- </MenuItem>- <MenuItem- data-tid="fileMenuOpenFileNatively"- onClick={this.openFileNatively}- >- <ListItemIcon>- <OpenFileNatively />- </ListItemIcon>- <ListItemText inset primary={i18n.t('core:openFileNatively')} />- </MenuItem>- <MenuItem- data-tid="fileMenuOpenContainingFolder"- onClick={this.showInFileManager}- >- <ListItemIcon>- <OpenContainingFolder />- </ListItemIcon>- <ListItemText inset primary={i18n.t('core:showInFileManager')} />- </MenuItem>- <Divider />- <MenuItem- data-tid="fileMenuAddRemoveTags"- onClick={this.showAddRemoveTagsDialog}- >- <ListItemIcon>- <AddRemoveTags />- </ListItemIcon>- <ListItemText inset primary={i18n.t('core:addRemoveTags')} />- </MenuItem>- <MenuItem- data-tid="fileMenuMoveCopyFile"- onClick={this.showMoveCopyFilesDialog}- >- <ListItemIcon>- <MoveCopy />- </ListItemIcon>- <ListItemText inset primary={i18n.t('core:moveCopyFile')} />- </MenuItem>- <MenuItem data-tid="fileMenuDeleteFile" onClick={this.showDeleteFileDialog}>- <ListItemIcon>- <DeleteForever />- </ListItemIcon>- <ListItemText inset primary={i18n.t('core:deleteEntry')} />- </MenuItem>- </Menu>- </div>- );- }-}+ <ListItemIcon>+ <OpenFile />+ </ListItemIcon>+ <ListItemText inset primary={i18n.t('core:openFile')} />+ </MenuItem>+ <MenuItem+ data-tid="fileMenuRenameFile"+ onClick={showRenameFileDialog}+ >+ <ListItemIcon>+ <RenameFile />+ </ListItemIcon>+ <ListItemText inset primary={i18n.t('core:renameFile')} />+ </MenuItem>+ <MenuItem+ data-tid="fileMenuOpenFileNatively"+ onClick={openFileNatively}+ >+ <ListItemIcon>+ <OpenFileNatively />+ </ListItemIcon>+ <ListItemText inset primary={i18n.t('core:openFileNatively')} />+ </MenuItem>+ <MenuItem+ data-tid="fileMenuOpenContainingFolder"+ onClick={showInFileManager}+ >+ <ListItemIcon>+ <OpenContainingFolder />+ </ListItemIcon>+ <ListItemText inset primary={i18n.t('core:showInFileManager')} />+ </MenuItem>+ <Divider />+ <MenuItem+ data-tid="fileMenuAddRemoveTags"+ onClick={showAddRemoveTagsDialog}+ >+ <ListItemIcon>+ <AddRemoveTags />+ </ListItemIcon>+ <ListItemText inset primary={i18n.t('core:addRemoveTags')} />+ </MenuItem>+ <MenuItem+ data-tid="fileMenuMoveCopyFile"+ onClick={showMoveCopyFilesDialog}+ >+ <ListItemIcon>+ <MoveCopy />+ </ListItemIcon>+ <ListItemText inset primary={i18n.t('core:moveCopyFile')} />+ </MenuItem>+ <MenuItem data-tid="fileMenuDeleteFile" onClick={showDeleteFileDialog}>+ <ListItemIcon>+ <DeleteForever />+ </ListItemIcon>+ <ListItemText inset primary={i18n.t('core:deleteEntry')} />+ </MenuItem>+ </Menu>+ </div>+ );+};export default FileMenu;