TagSpaces is an offline, open source, document manager with tagging support
rewrite MainPage.tsx (#1297)
Stanimirdb36785b2855
diff --git a/app/components/TagContainer.tsx b/app/components/TagContainer.tsxindex 57b5d077c..4fc39a915 100644--- a/app/components/TagContainer.tsx+++ b/app/components/TagContainer.tsx@@ -17,7 +17,7 @@*/import React from 'react';-import uuidv1 from 'uuid';+// import uuidv1 from 'uuid';import { connect } from 'react-redux';import Button from '@material-ui/core/Button';import MoreVertIcon from '@material-ui/icons/MoreVert';@@ -34,7 +34,6 @@ interface Props {tag: Tag;isReadOnlyMode?: boolean;allTags?: Array<Tag>;- key?: string;defaultTextColor?: string;defaultBackgroundColor?: string;tagGroup?: TagGroup;@@ -55,7 +54,6 @@ interface Props {const TagContainer = React.memo((props: Props) => {const {- key,tag,deleteIcon,isDragging,@@ -158,7 +156,7 @@ const TagContainer = React.memo((props: Props) => {<divrole="presentation"data-tid={tid}- key={key || tag.id || uuidv1()}+ key={tag.id || (tagGroup ? tagGroup.uuid : '') + tid} // don't set unique uuidv1() here - menu anchorEl needs to be the same for the same TagContainer key (or TagMenu will be displayed in top left corner)onClick={event => {if (event.ctrlKey && addTags) {const selectedEntryPaths = [];diff --git a/app/components/TagContainerDnd.tsx b/app/components/TagContainerDnd.tsxindex 872cae03d..6a4f35b93 100644--- a/app/components/TagContainerDnd.tsx+++ b/app/components/TagContainerDnd.tsx@@ -22,7 +22,7 @@ import { DragSource, ConnectDragPreview, ConnectDragSource } from 'react-dnd';import { getEmptyImage } from 'react-dnd-html5-backend';import DragItemTypes from './DragItemTypes';import TagContainer from './TagContainer';-import { TagGroup, Tag } from '../reducers/taglibrary';+import { TagGroup, Tag } from '-/reducers/taglibrary';import { FileSystemEntry } from '-/services/utils-io';const boxSource = {@@ -70,7 +70,6 @@ const boxSource = {interface Props {tag: Tag;- key: string;tagGroup?: TagGroup;handleTagMenu: (event: Object, tag: Tag, param: any) => void;handleRemoveTag?: (event: Object, tag: Tag) => void;@@ -87,7 +86,6 @@ interface Props {const TagContainerDnd = (props: Props) => {const {- key,tag,tagGroup,entryPath,@@ -111,7 +109,6 @@ const TagContainerDnd = (props: Props) => {return connectDragSource(<span><TagContainer- key={key}tag={tag}tagGroup={tagGroup}handleTagMenu={handleTagMenu}diff --git a/app/components/TagLibrary.tsx b/app/components/TagLibrary.tsxindex 7ad188681..966500cfa 100644--- a/app/components/TagLibrary.tsx+++ b/app/components/TagLibrary.tsx@@ -16,8 +16,7 @@**/-import React from 'react';-import uuidv1 from 'uuid';+import React, { useCallback, useMemo, useState } from 'react';import { bindActionCreators } from 'redux';import { connect } from 'react-redux';import classNames from 'classnames';@@ -49,7 +48,8 @@ import {Tag,actions as TagLibraryActions,getAllTags,- getTagGroups+ getTagGroups,+ Uuid} from '../reducers/taglibrary';import TaggingActions from '../reducers/tagging-actions';import i18n from '../services/i18n';@@ -66,9 +66,7 @@ import {import SmartTags from '../reducers/smart-tags';import { FileSystemEntry } from '-/services/utils-io';import { AppConfig } from '-/config';--const isTagLibraryReadOnly =- window.ExtTagLibrary && window.ExtTagLibrary.length > 0;+import EditTagDialog from '-/components/dialogs/EditTagDialog';interface Props {classes: any;@@ -93,134 +91,120 @@ interface Props {moveTag: () => void;editTagGroup: () => void;editTag: () => void;- deleteTag: () => void;+ deleteTag: (tagTitle: string, parentTagGroupUuid: Uuid) => void;selectedEntries: Array<FileSystemEntry>;tagGroupCollapsed: Array<string>;}-interface State {- tagLibraryMenuAnchorEl: Element;- tagLibraryMenuOpened: boolean;- tagGroupMenuAnchorEl: Element;- tagGroupMenuOpened: boolean;- tagMenuAnchorEl: Element;- tagMenuOpened: boolean;- selectedTagEntry: TagGroup;- selectedTag: Tag;- selectedTagGroupEntry: TagGroup;- isCreateTagGroupDialogOpened: boolean;- isEditTagGroupDialogOpened: boolean;- isDeleteTagGroupDialogOpened: boolean;- isCreateTagDialogOpened: boolean;- isEditTagDialogOpened: boolean;- isDeleteTagDialogOpened: boolean;-}+const TagLibrary = (props: Props) => {+ const [+ tagGroupMenuAnchorEl,+ setTagGroupMenuAnchorEl+ ] = useState<null | HTMLElement>(null);+ const [tagMenuAnchorEl, setTagMenuAnchorEl] = useState<null | HTMLElement>(+ null+ );+ const [+ tagLibraryMenuAnchorEl,+ setTagLibraryMenuAnchorEl+ ] = useState<null | HTMLElement>(null);+ const [selectedTagGroupEntry, setSelectedTagGroupEntry] = useState<TagGroup>(+ null+ );+ // const [selectedTagEntry, setSelectedTagEntry] = useState<TagGroup>(null);+ const [selectedTag, setSelectedTag] = useState<Tag>(null);+ const [+ isCreateTagGroupDialogOpened,+ setIsCreateTagGroupDialogOpened+ ] = useState<boolean>(false);+ const [isEditTagGroupDialogOpened, setIsEditTagGroupDialogOpened] = useState<+ boolean+ >(false);+ const [+ isDeleteTagGroupDialogOpened,+ setIsDeleteTagGroupDialogOpened+ ] = useState<boolean>(false);+ const [isCreateTagDialogOpened, setIsCreateTagDialogOpened] = useState<+ boolean+ >(false);+ const [isEditTagDialogOpened, setIsEditTagDialogOpened] = useState<boolean>(+ false+ );+ const [isDeleteTagDialogOpened, setIsDeleteTagDialogOpened] = useState<+ boolean+ >(false);-class TagLibrary extends React.Component<Props, State> {- state = {- tagGroupMenuAnchorEl: null,- tagGroupMenuOpened: false,- tagMenuAnchorEl: null,- tagMenuOpened: false,- tagLibraryMenuAnchorEl: null,- tagLibraryMenuOpened: false,- selectedTagGroupEntry: null,- selectedTagEntry: null,- selectedTag: null,- isCreateTagGroupDialogOpened: false,- isEditTagGroupDialogOpened: false,- isDeleteTagGroupDialogOpened: false,- isCreateTagDialogOpened: false,- isEditTagDialogOpened: false,- isDeleteTagDialogOpened: false- };+ const isTagLibraryReadOnly =+ window.ExtTagLibrary && window.ExtTagLibrary.length > 0;- handleTagGroupTitleClick = (event: Object, tagGroup) => {- this.props.toggleTagGroup(tagGroup.uuid);+ const handleTagGroupTitleClick = (event: Object, tagGroup) => {+ props.toggleTagGroup(tagGroup.uuid);};- handleTagGroupMenu = (+ const handleTagGroupMenu = (event: React.ChangeEvent<HTMLInputElement>,tagGroup) => {- this.setState({+ setTagGroupMenuAnchorEl(event.currentTarget);+ setSelectedTagGroupEntry(tagGroup);+ /* this.setState({tagGroupMenuOpened: true,tagGroupMenuAnchorEl: event.currentTarget,selectedTagGroupEntry: tagGroup- });+ }); */};- handleTagMenu = (+ const handleTagMenuCallback = useCallback(+ (event: React.ChangeEvent<HTMLInputElement>, tag, tagGroup: TagGroup) => {+ handleTagMenu(event, tag, tagGroup);+ },+ []+ );++ const handleTagMenu = (event: React.ChangeEvent<HTMLInputElement>,tag,tagGroup: TagGroup) => {- this.setState({- tagMenuOpened: true,- tagMenuAnchorEl: event.currentTarget,- selectedTagGroupEntry: tagGroup,- selectedTag: tag- });+ if (!tagGroup.readOnly) {+ setTagMenuAnchorEl(event.currentTarget);+ setSelectedTagGroupEntry(tagGroup);+ setSelectedTag(tag);+ }};- handleTagLibraryMenu = (event: any) => {- this.setState({+ const handleTagLibraryMenu = (event: any) => {+ setTagLibraryMenuAnchorEl(event.currentTarget);+ /* this.setState({tagLibraryMenuOpened: true,tagLibraryMenuAnchorEl: event.currentTarget- });+ }); */};- showCreateTagGroupDialog = () => {- this.setState({ isCreateTagGroupDialogOpened: true });+ const showCreateTagGroupDialog = () => {+ setIsCreateTagGroupDialogOpened(true);+ // this.setState({ isCreateTagGroupDialogOpened: true });};- showCreateTagsDialog = () => {- this.setState({ isCreateTagDialogOpened: true });- this.handleCloseTagGroupMenu();+ const showCreateTagsDialog = () => {+ setIsCreateTagDialogOpened(true);+ setTagGroupMenuAnchorEl(null);};- showEditTagGroupDialog = () => {- this.setState({ isEditTagGroupDialogOpened: true });- this.handleCloseTagGroupMenu();+ const showEditTagGroupDialog = () => {+ setIsEditTagGroupDialogOpened(true);+ setTagGroupMenuAnchorEl(null);};- showDeleteTagGroupDialog = () => {- this.setState({ isDeleteTagGroupDialogOpened: true });- this.handleCloseTagGroupMenu();+ const showDeleteTagGroupDialog = () => {+ setIsDeleteTagGroupDialogOpened(true);+ setTagGroupMenuAnchorEl(null);};- handleCloseDialogs = () => {- this.setState({- isCreateTagGroupDialogOpened: false,- isEditTagGroupDialogOpened: false,- isDeleteTagGroupDialogOpened: false,- isCreateTagDialogOpened: false,- isEditTagDialogOpened: false,- isDeleteTagDialogOpened: false- });- };-- handleCloseTagGroupMenu = () => {- this.setState({- tagGroupMenuOpened: false- });- };-- handleCloseTagMenu = () => {- this.setState({- tagMenuOpened: false- });- };-- handleCloseImportExportMenu = () => {- this.setState({ tagLibraryMenuOpened: false });- };-- renderTagGroup = tagGroup => {+ const renderTagGroup = tagGroup => {// eslint-disable-next-line no-param-reassigntagGroup.expanded = !(- this.props.tagGroupCollapsed &&- this.props.tagGroupCollapsed.includes(tagGroup.uuid)+ props.tagGroupCollapsed && props.tagGroupCollapsed.includes(tagGroup.uuid));const isReadOnly = tagGroup.readOnly || isTagLibraryReadOnly;return (@@ -229,13 +213,9 @@ class TagLibrary extends React.Component<Props, State> {data-tid={'tagLibraryTagGroupTitle_' + tagGroup.title}buttonstyle={{ maxWidth: 250 }}- className={this.props.classes.listItem}- onClick={(event: any) =>- this.handleTagGroupTitleClick(event, tagGroup)- }- onContextMenu={(event: any) =>- this.handleTagGroupMenu(event, tagGroup)- }+ className={props.classes.listItem}+ onClick={(event: any) => handleTagGroupTitleClick(event, tagGroup)}+ onContextMenu={(event: any) => handleTagGroupMenu(event, tagGroup)}title={'Number of tags in this tag group: ' + tagGroup.children.length}@@ -245,14 +225,14 @@ class TagLibrary extends React.Component<Props, State> {</ListItemIcon><Typographyvariant="inherit"- className={this.props.classes.header}+ className={props.classes.header}style={{ paddingLeft: 0 }}data-tid="locationTitleElement"noWrap>{tagGroup.title + ' '}{!tagGroup.expanded && (- <span className={this.props.classes.badge}>+ <span className={props.classes.badge}>{tagGroup.children.length}</span>)}@@ -266,11 +246,9 @@ class TagLibrary extends React.Component<Props, State> {data-tid={'tagLibraryMoreButton_' + tagGroup.title.replace(/ /g, '_')}- onClick={(event: any) =>- this.handleTagGroupMenu(event, tagGroup)- }+ onClick={(event: any) => handleTagGroupMenu(event, tagGroup)}onContextMenu={(event: any) =>- this.handleTagGroupMenu(event, tagGroup)+ handleTagGroupMenu(event, tagGroup)}><MoreVertIcon />@@ -285,16 +263,16 @@ class TagLibrary extends React.Component<Props, State> {>{tagGroup.children &&tagGroup.children.map((tag: Tag) => {- if (this.props.isReadOnlyMode) {+ if (props.isReadOnlyMode) {return (<TagContainerkey={tagGroup.uuid + tag.title}tag={tag}tagGroup={tagGroup}- handleTagMenu={this.handleTagMenu}- addTags={this.props.addTags}- moveTag={this.props.moveTag}- selectedEntries={this.props.selectedEntries}+ handleTagMenu={handleTagMenuCallback}+ addTags={props.addTags}+ moveTag={props.moveTag}+ selectedEntries={props.selectedEntries}/>);}@@ -303,10 +281,10 @@ class TagLibrary extends React.Component<Props, State> {key={tagGroup.uuid + tag.title}tag={tag}tagGroup={tagGroup}- handleTagMenu={this.handleTagMenu}- addTags={this.props.addTags}- moveTag={this.props.moveTag}- selectedEntries={this.props.selectedEntries}+ handleTagMenu={handleTagMenuCallback}+ addTags={props.addTags}+ moveTag={props.moveTag}+ selectedEntries={props.selectedEntries}/>);})}@@ -316,123 +294,155 @@ class TagLibrary extends React.Component<Props, State> {);};- render() {- const { tagGroups, classes, allTags } = this.props;+ function confirmDeleteTag() {+ if (selectedTag && selectedTagGroupEntry) {+ props.deleteTag(selectedTag.title, selectedTagGroupEntry.uuid);+ }+ }- return (- <div className={classes.panel} style={this.props.style}>- <CustomLogo />- <div className={classes.toolbar}>- <Typography- className={classNames(classes.panelTitle, classes.header)}- title={- 'Your tag library contains ' +- allTags.length +- ' tags \ndistributed in ' +- tagGroups.length +- ' tag groups'- }- variant="subtitle1"- >- {i18n.t('core:tagLibrary')}- </Typography>- {!isTagLibraryReadOnly && (- <IconButton- data-tid="tagLibraryMenu"- onClick={this.handleTagLibraryMenu}- >- <MoreVertIcon />- </IconButton>- )}- </div>+ const { tagGroups, classes, allTags } = props;++ return (+ <div className={classes.panel} style={props.style}>+ <CustomLogo />+ <div className={classes.toolbar}>+ <Typography+ className={classNames(classes.panelTitle, classes.header)}+ title={+ 'Your tag library contains ' ++ allTags.length ++ ' tags \ndistributed in ' ++ tagGroups.length ++ ' tag groups'+ }+ variant="subtitle1"+ >+ {i18n.t('core:tagLibrary')}+ </Typography>+ {!isTagLibraryReadOnly && (+ <IconButton data-tid="tagLibraryMenu" onClick={handleTagLibraryMenu}>+ <MoreVertIcon />+ </IconButton>+ )}+ </div>+ {isDeleteTagGroupDialogOpened && (<ConfirmDialog- open={this.state.isDeleteTagGroupDialogOpened}- onClose={this.handleCloseDialogs}+ open={isDeleteTagGroupDialogOpened}+ onClose={() => setIsDeleteTagGroupDialogOpened(false)}title={i18n.t('core:deleteTagGroup')}content={i18n.t('core:deleteTagGroupContentConfirm', {- tagGroup: this.state.selectedTagGroupEntry- ? this.state.selectedTagGroupEntry.title- : ''+ tagGroup: selectedTagGroupEntry ? selectedTagGroupEntry.title : ''})}confirmCallback={result => {- if (result && this.state.selectedTagGroupEntry) {- this.props.removeTagGroup(this.state.selectedTagGroupEntry.uuid);+ if (result && selectedTagGroupEntry) {+ props.removeTagGroup(selectedTagGroupEntry.uuid);}}}cancelDialogTID="cancelDeleteTagGroupDialog"confirmDialogTID="confirmDeleteTagGroupDialog"/>+ )}+ {isCreateTagGroupDialogOpened && (<CreateTagGroupDialog- key={uuidv1()}- open={this.state.isCreateTagGroupDialogOpened}- onClose={this.handleCloseDialogs}- createTagGroup={this.props.createTagGroup}- color={this.props.tagBackgroundColor}- textcolor={this.props.tagTextColor}+ // key={uuidv1()}+ open={isCreateTagGroupDialogOpened}+ onClose={() => setIsCreateTagGroupDialogOpened(false)}+ createTagGroup={props.createTagGroup}+ color={props.tagBackgroundColor}+ textcolor={props.tagTextColor}/>+ )}+ {isCreateTagDialogOpened && (<CreateTagsDialog- key={uuidv1()}- open={this.state.isCreateTagDialogOpened}- onClose={this.handleCloseDialogs}- addTag={this.props.addTag}- selectedTagGroupEntry={this.state.selectedTagGroupEntry}+ // key={uuidv1()}+ open={isCreateTagDialogOpened}+ onClose={() => setIsCreateTagDialogOpened(false)}+ addTag={props.addTag}+ selectedTagGroupEntry={selectedTagGroupEntry}/>+ )}+ {isEditTagGroupDialogOpened && (<EditTagGroupDialog- open={this.state.isEditTagGroupDialogOpened}- onClose={this.handleCloseDialogs}- editTagGroup={this.props.editTagGroup}- selectedTagGroupEntry={this.state.selectedTagGroupEntry}+ open={isEditTagGroupDialogOpened}+ onClose={() => setIsEditTagGroupDialogOpened(false)}+ editTagGroup={props.editTagGroup}+ selectedTagGroupEntry={selectedTagGroupEntry}/>+ )}+ {Boolean(tagGroupMenuAnchorEl) && (<TagGroupMenu- anchorEl={this.state.tagGroupMenuAnchorEl}- open={this.state.tagGroupMenuOpened}- onClose={this.handleCloseTagGroupMenu}- selectedTagGroupEntry={this.state.selectedTagGroupEntry}- showCreateTagsDialog={this.showCreateTagsDialog}- showDeleteTagGroupDialog={this.showDeleteTagGroupDialog}- handleCloseTagGroupMenu={this.handleCloseTagGroupMenu}- showEditTagGroupDialog={this.showEditTagGroupDialog}- moveTagGroupUp={this.props.moveTagGroupUp}- moveTagGroupDown={this.props.moveTagGroupDown}- sortTagGroup={this.props.sortTagGroup}- collectTagsFromLocation={this.props.collectTagsFromLocation}- />- <TagLibraryMenu- anchorEl={this.state.tagLibraryMenuAnchorEl}- open={this.state.tagLibraryMenuOpened}- onClose={this.handleCloseImportExportMenu}- tagGroups={tagGroups}- importTagGroups={this.props.importTagGroups}- exportTagGroups={this.props.exportTagGroups}- showCreateTagGroupDialog={this.showCreateTagGroupDialog}- openURLExternally={this.props.openURLExternally}+ anchorEl={tagGroupMenuAnchorEl}+ open={Boolean(tagGroupMenuAnchorEl)}+ onClose={() => setTagGroupMenuAnchorEl(null)}+ selectedTagGroupEntry={selectedTagGroupEntry}+ showCreateTagsDialog={showCreateTagsDialog}+ showDeleteTagGroupDialog={showDeleteTagGroupDialog}+ handleCloseTagGroupMenu={() => setTagGroupMenuAnchorEl(null)}+ showEditTagGroupDialog={showEditTagGroupDialog}+ moveTagGroupUp={props.moveTagGroupUp}+ moveTagGroupDown={props.moveTagGroupDown}+ sortTagGroup={props.sortTagGroup}+ collectTagsFromLocation={props.collectTagsFromLocation}/>+ )}+ <TagLibraryMenu+ anchorEl={tagLibraryMenuAnchorEl}+ open={Boolean(tagLibraryMenuAnchorEl)}+ onClose={() => setTagLibraryMenuAnchorEl(null)}+ tagGroups={tagGroups}+ importTagGroups={props.importTagGroups}+ exportTagGroups={props.exportTagGroups}+ showCreateTagGroupDialog={showCreateTagGroupDialog}+ openURLExternally={props.openURLExternally}+ />+ {Boolean(tagMenuAnchorEl) && (<TagMenu- anchorEl={this.state.tagMenuAnchorEl}- open={this.state.tagMenuOpened}- onClose={this.handleCloseTagMenu}- selectedTagGroupEntry={this.state.selectedTagGroupEntry}- selectedTag={this.state.selectedTag}- editTag={this.props.editTag}- deleteTag={this.props.deleteTag}+ // key={'tag_' + selectedTag.path}+ anchorEl={tagMenuAnchorEl}+ open={Boolean(tagMenuAnchorEl)}+ onClose={() => setTagMenuAnchorEl(null)}+ showEditTagDialog={() => setIsEditTagDialogOpened(true)}+ showDeleteTagDialog={() => setIsDeleteTagDialogOpened(true)}+ selectedTag={selectedTag}/>- <div- className={classes.taggroupsArea}- data-tid="tagLibraryTagGroupList"- >- {AppConfig.showSmartTags && (- <List style={{ paddingTop: 0, paddingBottom: 0 }}>- {SmartTags(i18n).map(this.renderTagGroup)}- </List>- )}- <List style={{ paddingTop: 0 }}>- {tagGroups.map(this.renderTagGroup)}+ )}+ {isEditTagDialogOpened && (+ <EditTagDialog+ open={isEditTagDialogOpened}+ onClose={() => setIsEditTagDialogOpened(false)}+ editTag={props.editTag}+ selectedTagGroupEntry={selectedTagGroupEntry}+ selectedTag={selectedTag}+ />+ )}+ {isDeleteTagDialogOpened && (+ <ConfirmDialog+ open={isDeleteTagDialogOpened}+ onClose={() => setIsDeleteTagDialogOpened(false)}+ title={i18n.t('core:deleteTagFromTagGroup')}+ content={i18n.t('core:deleteTagFromTagGroupContentConfirm', {+ tagName: selectedTag ? selectedTag.title : ''+ })}+ confirmCallback={result => {+ if (result) {+ confirmDeleteTag();+ }+ }}+ cancelDialogTID="cancelDeleteTagDialogTagMenu"+ confirmDialogTID="confirmDeleteTagDialogTagMenu"+ />+ )}+ <div className={classes.taggroupsArea} data-tid="tagLibraryTagGroupList">+ {AppConfig.showSmartTags && (+ <List style={{ paddingTop: 0, paddingBottom: 0 }}>+ {SmartTags(i18n).map(renderTagGroup)}</List>- </div>+ )}+ <List style={{ paddingTop: 0 }}>{tagGroups.map(renderTagGroup)}</List></div>- );- }-}+ </div>+ );+};function mapStateToProps(state) {return {diff --git a/app/components/dialogs/CreateTagsDialog.tsx b/app/components/dialogs/CreateTagsDialog.tsxindex 375052bfb..6466e3ed2 100644--- a/app/components/dialogs/CreateTagsDialog.tsx+++ b/app/components/dialogs/CreateTagsDialog.tsx@@ -16,7 +16,7 @@**/-import React from 'react';+import React, { useEffect, useState } from 'react';import Button from '@material-ui/core/Button';import TextField from '@material-ui/core/TextField';import DialogActions from '@material-ui/core/DialogActions';@@ -27,6 +27,7 @@ import FormHelperText from '@material-ui/core/FormHelperText';import Dialog from '@material-ui/core/Dialog';import i18n from '-/services/i18n';import { TagGroup } from '-/reducers/taglibrary';+import useFirstRender from '-/utils/useFirstRender';interface Props {open: boolean;@@ -36,102 +37,98 @@ interface Props {selectedTagGroupEntry: TagGroup;}-interface State {- inputError: boolean;- disableConfirmButton: boolean;- tagTitle: string;-}+const CreateTagsDialog = (props: Props) => {+ const [inputError, setInputError] = useState<boolean>(false);+ const [tagTitle, setTagTitle] = useState<string>('');-class CreateTagsDialog extends React.Component<Props, State> {- state = {- inputError: false,- disableConfirmButton: true,- tagTitle: ''- };+ const firstRender = useFirstRender();++ useEffect(() => {+ if (!firstRender) {+ handleValidation();+ }+ }, [tagTitle]);- handleTagTitleChange = (event: React.ChangeEvent<HTMLInputElement>) => {+ const handleTagTitleChange = (event: React.ChangeEvent<HTMLInputElement>) => {const { target } = event;- const { value, name } = target;+ // const { value, name } = target;- if (name === 'tagTitle') {+ setTagTitle(target.value);+ /* if (name === 'tagTitle') {this.setState({ tagTitle: value }, this.handleValidation);- }+ } */};- handleValidation() {- const tagCheck = RegExp(/^[^\#\/\\[\]]{1,}$/);- if (this.state.tagTitle && tagCheck.test(this.state.tagTitle)) {- this.setState({ inputError: false, disableConfirmButton: false });- } else {- this.setState({ inputError: true, disableConfirmButton: true });+ const handleValidation = () => {+ const tagCheck = RegExp(/^[^#/\\[\]]{1,}$/);+ if (tagTitle && tagCheck.test(tagTitle)) {+ if (inputError) {+ setInputError(false);+ }+ } else if (!inputError) {+ setInputError(true);}- }+ };- onConfirm = () => {- if (!this.state.disableConfirmButton) {- this.setState({ disableConfirmButton: true });- this.props.addTag(- this.state.tagTitle,- this.props.selectedTagGroupEntry.uuid- );- this.props.onClose();+ const onConfirm = () => {+ if (!inputError) {+ props.addTag(tagTitle, props.selectedTagGroupEntry.uuid);+ props.onClose();}};- render() {- const { fullScreen, open, onClose } = this.props;+ const { fullScreen, open, onClose } = props;- return (- <Dialog- open={open}- onClose={onClose}- fullScreen={fullScreen}- keepMounted- scroll="paper"- onKeyDown={event => {- if (event.key === 'Enter' || event.keyCode === 13) {- event.preventDefault();- event.stopPropagation();- this.onConfirm();- } else if (event.key === 'Escape') {- onClose();- }- }}- >- <DialogTitle>{i18n.t('core:addTagsToGroupTitle')}</DialogTitle>- <DialogContent style={{ minWidth: 400 }}>- <FormControl fullWidth={true} error={this.state.inputError}>- <TextField- error={this.state.inputError}- name="tagTitle"- autoFocus- label={i18n.t('core:addTagsToGroupTagsPlaceholder')}- onChange={this.handleTagTitleChange}- value={this.state.tagTitle}- data-tid="addTagsInput"- fullWidth={true}- />- {this.state.inputError && (- <FormHelperText>{i18n.t('core:tagTitleHelper')}</FormHelperText>- )}- </FormControl>- </DialogContent>- <DialogActions>- <Button onClick={this.props.onClose} color="primary">- {i18n.t('core:cancel')}- </Button>- <Button- disabled={this.state.disableConfirmButton}- onClick={this.onConfirm}- data-tid="createTagsConfirmButton"- color="primary"- >- {i18n.t('core:ok')}- </Button>- </DialogActions>- </Dialog>- );- }-}+ return (+ <Dialog+ open={open}+ onClose={onClose}+ fullScreen={fullScreen}+ keepMounted+ scroll="paper"+ onKeyDown={event => {+ if (event.key === 'Enter' || event.keyCode === 13) {+ event.preventDefault();+ event.stopPropagation();+ onConfirm();+ } else if (event.key === 'Escape') {+ onClose();+ }+ }}+ >+ <DialogTitle>{i18n.t('core:addTagsToGroupTitle')}</DialogTitle>+ <DialogContent style={{ minWidth: 400 }}>+ <FormControl fullWidth={true} error={inputError}>+ <TextField+ error={inputError}+ name="tagTitle"+ autoFocus+ label={i18n.t('core:addTagsToGroupTagsPlaceholder')}+ onChange={handleTagTitleChange}+ value={tagTitle}+ data-tid="addTagsInput"+ fullWidth={true}+ />+ {inputError && (+ <FormHelperText>{i18n.t('core:tagTitleHelper')}</FormHelperText>+ )}+ </FormControl>+ </DialogContent>+ <DialogActions>+ <Button onClick={onClose} color="primary">+ {i18n.t('core:cancel')}+ </Button>+ <Button+ disabled={inputError}+ onClick={onConfirm}+ data-tid="createTagsConfirmButton"+ color="primary"+ >+ {i18n.t('core:ok')}+ </Button>+ </DialogActions>+ </Dialog>+ );+};export default CreateTagsDialog;diff --git a/app/components/dialogs/EditTagDialog.tsx b/app/components/dialogs/EditTagDialog.tsxindex 9611a7d94..8ad2bb86e 100644--- a/app/components/dialogs/EditTagDialog.tsx+++ b/app/components/dialogs/EditTagDialog.tsx@@ -16,7 +16,7 @@**/-import React from 'react';+import React, { useEffect, useState } from 'react';import Button from '@material-ui/core/Button';import TextField from '@material-ui/core/TextField';import format from 'date-fns/format';@@ -40,261 +40,222 @@ interface Props {selectedTagGroupEntry: TagGroup;}-interface State {- inputError: boolean;- displayColorPicker: boolean;- displayTextColorPicker: boolean;- disableConfirmButton: boolean;- title: string;- origTitle: string;- color: string;- textcolor: string;- modifiedDate: string;-}--class EditTagDialog extends React.Component<Props, State> {- state = {- displayColorPicker: false,- displayTextColorPicker: false,- inputError: false,- disableConfirmButton: true,- origTitle: '',- title: '',- color: '',- textcolor: '',- modifiedDate: ''- };+const EditTagDialog = (props: Props) => {+ const [displayColorPicker, setDisplayColorPicker] = useState<boolean>(false);+ const [displayTextColorPicker, setDisplayTextColorPicker] = useState<boolean>(+ false+ );+ const [inputError, setInputError] = useState<boolean>(false);+ // const [disableConfirmButton, setDisableConfirmButton] = useState<boolean>(!props.selectedTag.title);+ const [title, setTitle] = useState<string>(props.selectedTag.title);+ const [color, setColor] = useState<string>(props.selectedTag.color);+ const [textcolor, setTextcolor] = useState<string>(+ props.selectedTag.textcolor+ );+ const [modifiedDate, setModifiedDate] = useState<string>(+ props.selectedTag.modified_date+ );- componentWillReceiveProps = ({ open, selectedTag }: Props) => {- if (open === true) {- this.setState({- disableConfirmButton: !selectedTag.title,- origTitle: selectedTag.title,- title: selectedTag.title,- color: selectedTag.color,- textcolor: selectedTag.textcolor,- modifiedDate: selectedTag.modified_date- });- }- };+ useEffect(() => {+ handleValidation();+ }, [title]);- handleTagTitleChange = (event: React.ChangeEvent<HTMLInputElement>) => {+ const handleTagTitleChange = (event: React.ChangeEvent<HTMLInputElement>) => {const { target } = event;const { value, name } = target;if (name === 'title') {- this.setState({ title: value }, this.handleValidation);+ setTitle(value);}};- handleValidation() {- const tagCheck = RegExp(/^[^\#\/\\ \[\]]{1,}$/);- if (this.state.title && tagCheck.test(this.state.title)) {- this.setState({ inputError: false, disableConfirmButton: false });+ const handleValidation = () => {+ const tagCheck = RegExp(/^[^#/\\ [\]]{1,}$/);+ if (title && tagCheck.test(title)) {+ setInputError(false);} else {- this.setState({ inputError: true, disableConfirmButton: true });+ setInputError(true);}- }+ };- onConfirm = () => {+ const disableConfirmButton = () => inputError;++ const onConfirm = () => {if (- !this.state.disableConfirmButton &&- this.props.editTag &&- this.props.selectedTagGroupEntry &&- this.props.selectedTag+ !inputError &&+ props.editTag &&+ props.selectedTagGroupEntry &&+ props.selectedTag) {- this.props.editTag(+ props.editTag({- ...this.props.selectedTag,- title: this.state.title,- color: this.state.color,- textcolor: this.state.textcolor+ ...props.selectedTag,+ title,+ color,+ textcolor},- this.props.selectedTagGroupEntry.uuid,- this.state.origTitle+ props.selectedTagGroupEntry.uuid,+ props.selectedTag.title);- this.setState({ inputError: false, disableConfirmButton: true });- this.props.onClose();+ // setInputError(false);+ props.onClose();}};- toggleDefaultTagBackgroundColorPicker = () => {- this.setState({- displayColorPicker: !this.state.displayColorPicker- });- };-- toggleDefaultTagTextColorPicker = () => {- this.setState({- displayTextColorPicker: !this.state.displayTextColorPicker- });- };-- handleChangeColor = (color: string) => {- this.setState({ color });- };-- handleChangeTextColor = (color: string) => {- this.setState({ textcolor: color });+ const { fullScreen, open, onClose } = props;+ const styles = {+ color: {+ width: '100%',+ height: 30,+ borderRadius: 2,+ borderWidth: 1,+ borderStyle: 'solid',+ borderColor: 'gray',+ padding: '5px',+ background: color+ },+ textcolor: {+ width: '100%',+ height: 30,+ borderRadius: 2,+ borderWidth: 1,+ borderStyle: 'solid',+ borderColor: 'gray',+ padding: '5px',+ background: textcolor+ },+ helpText: {+ marginBottom: '5px',+ fontSize: '1rem'+ }};- render() {- const { color, textcolor, modifiedDate } = this.state;- const { fullScreen, open, onClose } = this.props;- const styles = {- color: {- width: '100%',- height: 30,- borderRadius: 2,- borderWidth: 1,- borderStyle: 'solid',- borderColor: 'gray',- padding: '5px',- background: color- },- textcolor: {- width: '100%',- height: 30,- borderRadius: 2,- borderWidth: 1,- borderStyle: 'solid',- borderColor: 'gray',- padding: '5px',- background: textcolor- },- helpText: {- marginBottom: '5px',- fontSize: '1rem'- }- };-- return (- <Dialog- open={open}- fullScreen={fullScreen}- onClose={onClose}- keepMounted- scroll="paper"- onKeyDown={event => {- if (event.key === 'Enter' || event.keyCode === 13) {- event.preventDefault();- event.stopPropagation();- this.onConfirm();- } else if (event.key === 'Escape') {- onClose();- }- }}- >- <DialogTitle style={{ overflow: 'visible' }}>- {i18n.t('core:editTagTitle')}- {` '${this.state.title}'`}- </DialogTitle>- <DialogContent style={{ overflow: 'visible' }}>- <FormControl+ return (+ <Dialog+ open={open}+ fullScreen={fullScreen}+ onClose={onClose}+ keepMounted+ scroll="paper"+ onKeyDown={event => {+ if (event.key === 'Enter' || event.keyCode === 13) {+ event.preventDefault();+ event.stopPropagation();+ onConfirm();+ } else if (event.key === 'Escape') {+ onClose();+ }+ }}+ >+ <DialogTitle style={{ overflow: 'visible' }}>+ {i18n.t('core:editTagTitle')}+ {` '${title}'`}+ </DialogTitle>+ <DialogContent style={{ overflow: 'visible' }}>+ <FormControl+ fullWidth={true}+ error={inputError}+ style={{ overflow: 'visible' }}+ >+ {modifiedDate && (+ <div+ className="tag-date"+ style={{+ fontSize: 12,+ position: 'relative',+ bottom: 20,+ color: '#808080'+ }}+ >+ <span className="text" style={{ fontWeight: 600 }}>+ {`${i18n.t('core:modifiedDate')}: `}+ </span>+ <time>{format(new Date(modifiedDate), 'yyyy-mm-dd')}</time>+ </div>+ )}+ <TextField+ error={inputError}+ margin="dense"+ name="title"+ autoFocus+ label={i18n.t('core:editTag')}+ onChange={handleTagTitleChange}+ value={title}+ data-tid="editTagInput"fullWidth={true}- error={this.state.inputError}- style={{ overflow: 'visible' }}- >- {modifiedDate && (- <div- className="tag-date"- style={{- fontSize: 12,- position: 'relative',- bottom: 20,- color: '#808080'- }}- >- <span className="text" style={{ fontWeight: 600 }}>- {`${i18n.t('core:modifiedDate')}: `}- </span>- <time>{format(new Date(modifiedDate), 'yyyy-mm-dd')}</time>- </div>- )}- <TextField- error={this.state.inputError}- margin="dense"- name="title"- autoFocus- label={i18n.t('core:editTag')}- onChange={this.handleTagTitleChange}- value={this.state.title}- data-tid="editTagInput"- fullWidth={true}- />- {this.state.inputError && (- <FormHelperText style={styles.helpText}>- {i18n.t('core:tagTitleHelper')}- </FormHelperText>- )}- </FormControl>- <FormControl fullWidth={true}>+ />+ {inputError && (<FormHelperText style={styles.helpText}>- {i18n.t('core:tagBackgroundColor')}+ {i18n.t('core:tagTitleHelper')}</FormHelperText>- <TransparentBackground>- <Button- onClick={this.toggleDefaultTagBackgroundColorPicker}- data-tid="tagBackgroundColorEditTagDialog"- style={styles.color}- role="presentation"- >- - </Button>- </TransparentBackground>- {this.state.displayColorPicker && (- <ColorPickerDialog- open={this.state.displayColorPicker}- setColor={this.handleChangeColor}- onClose={this.toggleDefaultTagBackgroundColorPicker}- color={this.state.color}- />- )}- </FormControl>- <FormControl fullWidth={true}>- <FormHelperText style={styles.helpText}>- {i18n.t('core:tagForegroundColor')}- </FormHelperText>- <TransparentBackground>- <Button- onClick={this.toggleDefaultTagTextColorPicker}- data-tid="tagForegroundColorEditTagDialog"- style={styles.textcolor}- role="presentation"- >- - </Button>- </TransparentBackground>- {this.state.displayTextColorPicker && (- <ColorPickerDialog- open={this.state.displayTextColorPicker}- setColor={this.handleChangeTextColor}- onClose={this.toggleDefaultTagTextColorPicker}- color={this.state.textcolor}- />- )}- </FormControl>- </DialogContent>- <DialogActions>- <Button- onClick={this.props.onClose}- data-tid="closeEditTagDialog"- color="primary"- >- {i18n.t('core:cancel')}- </Button>- <Button- disabled={this.state.disableConfirmButton}- onClick={this.onConfirm}- data-tid="editTagConfirm"- color="primary"- >- {i18n.t('core:ok')}- </Button>- </DialogActions>- </Dialog>- );- }-}+ )}+ </FormControl>+ <FormControl fullWidth={true}>+ <FormHelperText style={styles.helpText}>+ {i18n.t('core:tagBackgroundColor')}+ </FormHelperText>+ <TransparentBackground>+ <Button+ onClick={() => setDisplayColorPicker(!displayColorPicker)}+ data-tid="tagBackgroundColorEditTagDialog"+ style={styles.color}+ role="presentation"+ >+ + </Button>+ </TransparentBackground>+ {displayColorPicker && (+ <ColorPickerDialog+ open={displayColorPicker}+ setColor={value => setColor(value)}+ onClose={() => setDisplayColorPicker(!displayColorPicker)}+ color={color}+ />+ )}+ </FormControl>+ <FormControl fullWidth={true}>+ <FormHelperText style={styles.helpText}>+ {i18n.t('core:tagForegroundColor')}+ </FormHelperText>+ <TransparentBackground>+ <Button+ onClick={() => setDisplayTextColorPicker(!displayTextColorPicker)}+ data-tid="tagForegroundColorEditTagDialog"+ style={styles.textcolor}+ role="presentation"+ >+ + </Button>+ </TransparentBackground>+ {displayTextColorPicker && (+ <ColorPickerDialog+ open={displayTextColorPicker}+ setColor={txtcolor => setTextcolor(txtcolor)}+ onClose={() => setDisplayTextColorPicker(!displayTextColorPicker)}+ color={textcolor}+ />+ )}+ </FormControl>+ </DialogContent>+ <DialogActions>+ <Button+ onClick={props.onClose}+ data-tid="closeEditTagDialog"+ color="primary"+ >+ {i18n.t('core:cancel')}+ </Button>+ <Button+ disabled={inputError}+ onClick={onConfirm}+ data-tid="editTagConfirm"+ color="primary"+ >+ {i18n.t('core:ok')}+ </Button>+ </DialogActions>+ </Dialog>+ );+};export default EditTagDialog;diff --git a/app/components/dialogs/EditTagGroupDialog.tsx b/app/components/dialogs/EditTagGroupDialog.tsxindex 308673694..59e3f196c 100644--- a/app/components/dialogs/EditTagGroupDialog.tsx+++ b/app/components/dialogs/EditTagGroupDialog.tsx@@ -16,9 +16,8 @@**/-import React from 'react';+import React, { useEffect, useState } from 'react';import Button from '@material-ui/core/Button';-import format from 'date-fns/format';import TextField from '@material-ui/core/TextField';import DialogActions from '@material-ui/core/DialogActions';import DialogContent from '@material-ui/core/DialogContent';@@ -40,117 +39,80 @@ interface Props {onClose: () => void;}-interface State {- inputError: boolean;- displayColorPicker: boolean;- displayTextColorPicker: boolean;- disableConfirmButton: boolean;- title: string;- applyChanges: boolean;- color: string;- textcolor: string;- modifiedDate: string;-}+const EditTagGroupDialog = (props: Props) => {+ const [displayColorPicker, setDisplayColorPicker] = useState<boolean>(false);+ const [displayTextColorPicker, setDisplayTextColorPicker] = useState<boolean>(+ false+ );+ const [inputError, setInputError] = useState<boolean>(false);+ // const [disableConfirmButton, setDisableConfirmButton] = useState<boolean>(true);+ const [applyChanges, setApplyChanges] = useState<boolean>(false);+ const [title, setTitle] = useState<string>(props.selectedTagGroupEntry.title);+ const [color, setColor] = useState<string>(props.selectedTagGroupEntry.color);+ const [textcolor, setTextcolor] = useState<string>(+ props.selectedTagGroupEntry.textcolor+ );+ // const [modifiedDate, setModifiedDate] = useState<string>('');-class EditTagGroupDialog extends React.Component<Props, State> {- state = {- displayColorPicker: false,- displayTextColorPicker: false,- inputError: false,- disableConfirmButton: true,- applyChanges: false,- title: '',- color: '',- textcolor: '',- modifiedDate: ''- };+ useEffect(() => {+ handleValidation();+ }, [title]);- componentWillReceiveProps = ({ open, selectedTagGroupEntry }) => {- if (open === true) {- this.setState({- disableConfirmButton: !selectedTagGroupEntry.title,- applyChanges: false,- title: selectedTagGroupEntry.title,- color: selectedTagGroupEntry.color,- textcolor: selectedTagGroupEntry.textcolor,- modifiedDate: selectedTagGroupEntry.modified_date- });- }- };-- handleTagGroupTitleChange = (event: React.ChangeEvent<HTMLInputElement>) => {+ const handleTagGroupTitleChange = (+ event: React.ChangeEvent<HTMLInputElement>+ ) => {const { target } = event;const { value, name } = target;if (name === 'title') {- this.setState({ title: value }, this.handleValidation);+ setTitle(value);+ // this.setState({ title: value }, this.handleValidation);}};- handleValidation() {- if (this.state.title && this.state.title.length > 0) {- this.setState({ inputError: false, disableConfirmButton: false });+ const handleValidation = () => {+ if (title && title.length > 0) {+ setInputError(false);} else {- this.setState({ inputError: true, disableConfirmButton: true });+ setInputError(true);}- }+ };++ const disableConfirmButton = () => inputError;- onConfirm = () => {- const { disableConfirmButton, applyChanges } = this.state;- const { selectedTagGroupEntry } = this.props;- if (disableConfirmButton) {+ const onConfirm = () => {+ const { selectedTagGroupEntry } = props;+ if (disableConfirmButton()) {return;}if (selectedTagGroupEntry && selectedTagGroupEntry.children) {- this.props.editTagGroup({+ props.editTagGroup({...selectedTagGroupEntry,- title: this.state.title,- color: this.state.color,- textcolor: this.state.textcolor,+ title,+ color,+ textcolor,children: selectedTagGroupEntry.children.map(tag => ({...tag,- color: applyChanges ? this.state.color : tag.color,- textcolor: applyChanges ? this.state.textcolor : tag.textcolor,+ color: applyChanges ? color : tag.color,+ textcolor: applyChanges ? textcolor : tag.textcolor,style: tag.style}))});- this.setState({ inputError: false, disableConfirmButton: true });- this.props.onClose();+ // setInputError(false);+ // this.setState({ inputError: false, disableConfirmButton: true });+ props.onClose();}};- toggleDefaultTagBackgroundColorPicker = () => {- this.setState({ displayColorPicker: !this.state.displayColorPicker });- };-- toggleDefaultTagTextColorPicker = () => {- this.setState({- displayTextColorPicker: !this.state.displayTextColorPicker- });- };-- handleChangeColor = (color: string) => {- this.setState({ color });- };-- handleChangeTextColor = (color: string) => {- this.setState({ textcolor: color });- };-- setApplyChanges = (applyColorChanges: boolean) => {- this.setState({ applyChanges: applyColorChanges });- };-- renderTitle = () => (+ const renderTitle = () => (<DialogTitle style={{ overflow: 'visible' }}>{i18n.t('core:editTagGroupTitle')}- {` '${this.state.title}'`}+ {` '${title}'`}</DialogTitle>);- renderContent = () => {- const { color, textcolor, modifiedDate } = this.state;+ const renderContent = () => {const styles = {color: {width: '100%',@@ -182,10 +144,10 @@ class EditTagGroupDialog extends React.Component<Props, State> {<DialogContent style={{ overflow: 'visible' }}><FormControlfullWidth={true}- error={this.state.inputError}+ error={inputError}style={{ overflow: 'visible' }}>- {modifiedDate && (+ {/* {modifiedDate && (<divclassName="tag-date"style={{@@ -200,19 +162,19 @@ class EditTagGroupDialog extends React.Component<Props, State> {</span><time>{format(new Date(modifiedDate), 'yyyy-mm-dd')}</time></div>- )}+ )} */}<TextField- error={this.state.inputError}+ error={inputError}margin="dense"name="title"autoFocuslabel={i18n.t('core:editTagGroupNewName')}- onChange={this.handleTagGroupTitleChange}- value={this.state.title}+ onChange={handleTagGroupTitleChange}+ value={title}data-tid="editTagGroupInput"fullWidth={true}/>- {this.state.inputError && (+ {inputError && (<FormHelperText>{i18n.t('core:taggroupTitleHelper')}</FormHelperText>@@ -224,19 +186,19 @@ class EditTagGroupDialog extends React.Component<Props, State> {</FormHelperText><TransparentBackground><Button- onClick={this.toggleDefaultTagBackgroundColorPicker}+ onClick={() => setDisplayColorPicker(!displayColorPicker)}data-tid="editTagGroupBackgroundColor"style={styles.color}> </Button></TransparentBackground>- {this.state.displayColorPicker && (+ {displayColorPicker && (<ColorPickerDialog- open={this.state.displayColorPicker}- setColor={this.handleChangeColor}- onClose={this.toggleDefaultTagBackgroundColorPicker}- color={this.state.color}+ open={displayColorPicker}+ setColor={value => setColor(value)}+ onClose={() => setDisplayColorPicker(false)}+ color={color}/>)}</FormControl>@@ -246,7 +208,7 @@ class EditTagGroupDialog extends React.Component<Props, State> {</FormHelperText><TransparentBackground><Button- onClick={this.toggleDefaultTagTextColorPicker}+ onClick={() => setDisplayTextColorPicker(!displayTextColorPicker)}data-tid="editTagGroupForegroundColor"style={styles.textcolor}role="presentation"@@ -254,12 +216,12 @@ class EditTagGroupDialog extends React.Component<Props, State> { </Button></TransparentBackground>- {this.state.displayTextColorPicker && (+ {displayTextColorPicker && (<ColorPickerDialog- open={this.state.displayTextColorPicker}- setColor={this.handleChangeTextColor}- onClose={this.toggleDefaultTagTextColorPicker}- color={this.state.textcolor}+ open={displayTextColorPicker}+ setColor={txtcolor => setTextcolor(txtcolor)}+ onClose={() => setDisplayTextColorPicker(!displayTextColorPicker)}+ color={textcolor}/>)}</FormControl>@@ -269,22 +231,22 @@ class EditTagGroupDialog extends React.Component<Props, State> {</FormHelperText><Switchdata-tid="editTagGroupSwitch"- onClick={() => this.setApplyChanges(!this.state.applyChanges)}- checked={this.state.applyChanges}+ onClick={() => setApplyChanges(!applyChanges)}+ checked={applyChanges}/></FormControl></DialogContent>);};- renderActions = () => (+ const renderActions = () => (<DialogActions>- <Button onClick={this.props.onClose} color="primary">+ <Button onClick={props.onClose} color="primary">{i18n.t('core:cancel')}</Button><Button- disabled={this.state.disableConfirmButton}- onClick={this.onConfirm}+ disabled={disableConfirmButton()}+ onClick={onConfirm}data-tid="editTagGroupConfirmButton"color="primary">@@ -293,29 +255,27 @@ class EditTagGroupDialog extends React.Component<Props, State> {</DialogActions>);- render() {- const { onClose, open, fullScreen } = this.props;- return (- <Dialog- open={open}- fullScreen={fullScreen}- onClose={onClose}- onKeyDown={event => {- if (event.key === 'Enter' || event.keyCode === 13) {- event.preventDefault();- event.stopPropagation();- this.onConfirm();- } else if (event.key === 'Escape') {- onClose();- }- }}- >- {this.renderTitle()}- {this.renderContent()}- {this.renderActions()}- </Dialog>- );- }-}+ const { open, fullScreen } = props;+ return (+ <Dialog+ open={open}+ fullScreen={fullScreen}+ onClose={props.onClose}+ onKeyDown={event => {+ if (event.key === 'Enter' || event.keyCode === 13) {+ event.preventDefault();+ event.stopPropagation();+ onConfirm();+ } else if (event.key === 'Escape') {+ props.onClose();+ }+ }}+ >+ {renderTitle()}+ {renderContent()}+ {renderActions()}+ </Dialog>+ );+};export default EditTagGroupDialog;diff --git a/app/components/dialogs/ImportExportTagGroupsDialog.tsx b/app/components/dialogs/ImportExportTagGroupsDialog.tsxindex c786aa4e7..ed4bb656a 100644--- a/app/components/dialogs/ImportExportTagGroupsDialog.tsx+++ b/app/components/dialogs/ImportExportTagGroupsDialog.tsx@@ -16,7 +16,7 @@**/-import React from 'react';+import React, { useRef, useState } from 'react';import Button from '@material-ui/core/Button';import { withStyles } from '@material-ui/core/styles';import withMobileDialog from '@material-ui/core/withMobileDialog';@@ -56,122 +56,56 @@ interface Props {exportTagGroups: (taggroup: any) => void;}-interface State {- disableConfirmButton: boolean;- tagGroupList: Array<Object>;- selectedAll: boolean;-}--class ImportExportTagGroupsDialog extends React.Component<Props, State> {- state = {- disableConfirmButton: true,- selectedAll: false,- tagGroupList: []- };-- componentWillReceiveProps = (nextProps: Props) => {- if (nextProps.open === true) {- const tagGroupList = [];- const { tagGroups } = nextProps;- if (tagGroups) {- tagGroups.map(entry => {- tagGroupList.push({- uuid: entry.uuid || entry.key,- title: entry.title,- color: entry.color,- textcolor: entry.textcolor,- children: entry.children,- selected: true- });- return true;- });- this.setState(- { tagGroupList, selectedAll: true },- this.handleValidation- );- }- }- };+const ImportExportTagGroupsDialog = (props: Props) => {+ // const [selectedAll, setSelectedAll] = useState<boolean>(true);+ const selectedAll = useRef(true);+ const [tagGroupList, setTagGroupList] = useState<Array<any>>(+ props.tagGroups.map(entry => ({ ...entry, selected: selectedAll.current }))+ );- handleToggleSelectAll = () => {- const tagGroupList = [];- const tagGroups = this.state.tagGroupList;- tagGroups.map(entry => {- tagGroupList.push({- uuid: entry.uuid || entry.key,- title: entry.title,- color: entry.color,- textcolor: entry.textcolor,- children: entry.children,- selected: !this.state.selectedAll- });- return true;- });- this.setState({ tagGroupList }, this.handleValidation);+ const handleToggleSelectAll = () => {+ selectedAll.current = !selectedAll.current;+ setTagGroupList(+ tagGroupList.map(entry => ({ ...entry, selected: selectedAll.current }))+ );};- handleChange = name => (event: any, checked: boolean) => {+ /* const handleChange = name => (event: any, checked: boolean) => {// @ts-ignorethis.setState({ [name]: !checked });+ }; */++ const isSelected = () => tagGroupList.some(n => n.selected === true);++ const handleTagGroup = (tagGroup: any, checked: boolean, index) => {+ setTagGroupList([+ ...tagGroupList.slice(0, index),+ {+ ...tagGroupList[index],+ selected: !checked+ },+ ...tagGroupList.slice(index + 1)+ ]);};- handleValidation() {- let selected = false;- this.state.tagGroupList.map(n => {- if (n.selected === true) {- selected = true;- }- return true;- });- if (selected) {- this.setState({ disableConfirmButton: false });- } else {- this.setState({ disableConfirmButton: true });- }- }-- handleTagGroup = (tagGroup: any, checked: boolean, index) => {- const groups = this.state.tagGroupList;- if (!checked) {- groups[index].selected = true;- this.setState({ tagGroupList: groups }, this.handleValidation);- } else {- groups[index].selected = false;- this.setState({ tagGroupList: groups }, this.handleValidation);- }- };-- onConfirm = () => {- const { showNotification } = this.props;- const groupList = [];- const selectedTagGroup = this.state.tagGroupList;- selectedTagGroup.map(tagGroup => {- if (tagGroup.selected) {- groupList.push({- uuid: tagGroup.uuid || tagGroup.key,- title: tagGroup.title,- color: tagGroup.color,- textcolor: tagGroup.textcolor,- children: tagGroup.children- });- }- return true;- });- this.props.onClose();- if (this.props.dialogModeImport) {- this.props.importTagGroups(groupList);+ const onConfirm = () => {+ const { showNotification } = props;+ const groupList = tagGroupList.filter(tagGroup => tagGroup.selected);+ props.onClose();+ if (props.dialogModeImport) {+ props.importTagGroups(groupList);if (isFunc(showNotification)) {showNotification(i18n.t('core:successfullyImportedGroupTags'));}} else {- this.props.exportTagGroups(groupList);+ props.exportTagGroups(groupList);if (isFunc(showNotification)) {showNotification(i18n.t('core:successfullyExportedGroupTags'));}}};- renderTagGroups = (tagGroup, index) => (+ const renderTagGroups = (tagGroup, index) => (<div key={tagGroup.uuid || tagGroup.key}><FormControl component="fieldset"><FormGroup>@@ -180,8 +114,8 @@ class ImportExportTagGroupsDialog extends React.Component<Props, State> {<Checkboxid={tagGroup.uuid || tagGroup.key}checked={tagGroup.selected}- onClick={e => this.handleTagGroup(e, tagGroup.selected, index)}- onChange={e => this.handleChange(e)}+ onClick={e => handleTagGroup(e, tagGroup.selected, index)}+ // onChange={e => handleChange(e)}value={tagGroup.title}name={tagGroup.title}/>@@ -199,56 +133,54 @@ class ImportExportTagGroupsDialog extends React.Component<Props, State> {</div>);- renderTitle = () => {- if (this.props.dialogModeImport) {+ const renderTitle = () => {+ if (props.dialogModeImport) {return <DialogTitle>{i18n.t('core:importGroupTagsTitle')}</DialogTitle>;}return <DialogTitle>{i18n.t('core:exportGroupTagsTitle')}</DialogTitle>;};- renderContent = () => (- <DialogContent className={this.props.classes.root}>- <Button color="primary" onClick={this.handleToggleSelectAll}>+ const renderContent = () => (+ <DialogContent className={props.classes.root}>+ <Button color="primary" onClick={handleToggleSelectAll}>{i18n.t('core:selectAllTagGroups')}</Button><FormControl fullWidth={true}>- {this.state.tagGroupList.map(this.renderTagGroups)}+ {tagGroupList.map(renderTagGroups)}</FormControl></DialogContent>);- renderActions = () => (+ const renderActions = () => (<DialogActions>- <Button onClick={this.props.onClose} color="primary">+ <Button onClick={props.onClose} color="primary">{i18n.t('core:cancel')}</Button><Button- disabled={this.state.disableConfirmButton}- onClick={this.onConfirm}+ disabled={!isSelected()}+ onClick={onConfirm}data-tid="confirmImportExport"color="primary">- {this.props.dialogModeImport ? 'Import' : 'Export'}+ {props.dialogModeImport ? 'Import' : 'Export'}</Button></DialogActions>);- render() {- const { onClose, open, fullScreen } = this.props;- return (- <Dialog- open={open}- fullScreen={fullScreen}- onClose={onClose}- // onEnterKey={(event) => onEnterKeyHandler(event, this.onConfirm)}- >- {this.renderTitle()}- {this.renderContent()}- {this.renderActions()}- </Dialog>- );- }-}+ const { onClose, open, fullScreen } = props;+ return (+ <Dialog+ open={open}+ fullScreen={fullScreen}+ onClose={onClose}+ // onEnterKey={(event) => onEnterKeyHandler(event, this.onConfirm)}+ >+ {renderTitle()}+ {renderContent()}+ {renderActions()}+ </Dialog>+ );+};export default withStyles(styles)(withMobileDialog()(ImportExportTagGroupsDialog)diff --git a/app/components/menus/TagLibraryMenu.tsx b/app/components/menus/TagLibraryMenu.tsxindex 70b7013e2..10ebc3359 100644--- a/app/components/menus/TagLibraryMenu.tsx+++ b/app/components/menus/TagLibraryMenu.tsx@@ -16,7 +16,7 @@**/-import React, { useState } from 'react';+import React, { useRef, useState } from 'react';import ListItemText from '@material-ui/core/ListItemText';import ListItemIcon from '@material-ui/core/ListItemIcon';import Menu from '@material-ui/core/Menu';@@ -42,9 +42,10 @@ interface Props {}const TagLibraryMenu = (props: Props) => {- let fileInput;- const [tagGroups, setTagGroups] = useState(null);- const [selectedDirectoryPath, setSelectedDirectoryPath] = useState('');+ const fileInput = useRef<HTMLInputElement>(null);+ const tagGroupsImported = useRef([]);+ // const [tagGroups, setTagGroups] = useState(null);+ // const [selectedDirectoryPath, setSelectedDirectoryPath] = useState('');const [isSelectDirectoryDialogOpened,setIsSelectDirectoryDialogOpened@@ -62,13 +63,13 @@ const TagLibraryMenu = (props: Props) => {function handleExportTagGroup() {props.onClose();setDialogModeImport(false);- setTagGroups(props.tagGroups);+ // setTagGroups(props.tagGroups);setIsImportExportTagGroupDialogOpened(true);}function showSelectDirectoryDialog() {setIsSelectDirectoryDialogOpened(true);- setSelectedDirectoryPath('');+ // setSelectedDirectoryPath('');}function closeSelectDirectoryExtDialog() {@@ -83,7 +84,7 @@ const TagLibraryMenu = (props: Props) => {// TODO Select directory or file from dialogshowSelectDirectoryDialog();} else {- fileInput.click();+ fileInput.current.click();}}@@ -96,7 +97,7 @@ const TagLibraryMenu = (props: Props) => {try {const jsonObj = JSON.parse(reader.result);if (jsonObj.tagGroups) {- setTagGroups(jsonObj.tagGroups);+ tagGroupsImported.current = jsonObj.tagGroups;setIsImportExportTagGroupDialogOpened(true);} else {// TODO connect showNotification@@ -118,14 +119,18 @@ const TagLibraryMenu = (props: Props) => {return (<div style={{ overflowY: 'hidden' }}>- <ImportExportTagGroupsDialog- open={isImportExportTagGroupDialogOpened}- onClose={handleCloseDialogs}- tagGroups={tagGroups}- dialogModeImport={dialogModeImport}- exportTagGroups={props.exportTagGroups}- importTagGroups={props.importTagGroups}- />+ {isImportExportTagGroupDialogOpened && (+ <ImportExportTagGroupsDialog+ open={isImportExportTagGroupDialogOpened}+ onClose={handleCloseDialogs}+ tagGroups={+ dialogModeImport ? tagGroupsImported.current : props.tagGroups+ }+ dialogModeImport={dialogModeImport}+ exportTagGroups={props.exportTagGroups}+ importTagGroups={props.importTagGroups}+ />+ )}<SelectDirectoryDialogopen={isSelectDirectoryDialogOpened}onClose={closeSelectDirectoryExtDialog}@@ -173,9 +178,7 @@ const TagLibraryMenu = (props: Props) => {</Menu><inputstyle={{ display: 'none' }}- ref={input => {- fileInput = input;- }}+ ref={fileInput}accept="*"type="file"onChange={handleFileInputChange}diff --git a/app/components/menus/TagMenu.tsx b/app/components/menus/TagMenu.tsxindex 1d0e89fa7..d446ffb62 100644--- a/app/components/menus/TagMenu.tsx+++ b/app/components/menus/TagMenu.tsx@@ -16,7 +16,7 @@**/-import React, { useState } from 'react';+import React from 'react';import { bindActionCreators } from 'redux';import { connect } from 'react-redux';import ShowEntriesWithTagIcon from '@material-ui/icons/Launch';@@ -26,9 +26,7 @@ import ListItemIcon from '@material-ui/core/ListItemIcon';import ListItemText from '@material-ui/core/ListItemText';import Menu from '@material-ui/core/Menu';import MenuItem from '@material-ui/core/MenuItem';-import ConfirmDialog from '../dialogs/ConfirmDialog';-import EditTagDialog from '../dialogs/EditTagDialog';-import { Tag, TagGroup, Uuid } from '-/reducers/taglibrary';+import { Tag } from '-/reducers/taglibrary';import { actions as LocationIndexActions } from '-/reducers/location-index';import i18n from '-/services/i18n';import { SearchQuery } from '-/services/search';@@ -43,18 +41,14 @@ interface Props {open?: boolean;onClose: () => void;selectedTag?: Tag;- selectedTagGroupEntry?: TagGroup;searchLocationIndex: (searchQuery: SearchQuery) => void;- editTag: (tag: Tag, parentTagGroupUuid: Uuid, origTitle: string) => void;- deleteTag: (tagTitle: string, parentTagGroupUuid: Uuid) => void;openSearchPanel: () => void;+ showEditTagDialog: () => void;+ showDeleteTagDialog: () => void;maxSearchResults: number;}const TagLibraryMenu = (props: Props) => {- const [isEditTagDialogOpened, setIsEditTagDialogOpened] = useState(false);- const [isDeleteTagDialogOpened, setIsDeleteTagDialogOpened] = useState(false);-function showFilesWithThisTag() {if (props.selectedTag) {props.openSearchPanel();@@ -68,26 +62,12 @@ const TagLibraryMenu = (props: Props) => {function showEditTagDialog() {props.onClose();- setIsEditTagDialogOpened(true);+ props.showEditTagDialog();}function showDeleteTagDialog() {props.onClose();- setIsDeleteTagDialogOpened(true);- }-- function handleCloseDialogs() {- setIsEditTagDialogOpened(false);- setIsDeleteTagDialogOpened(false);- }-- function confirmDeleteTag() {- if (props.selectedTag && props.selectedTagGroupEntry) {- props.deleteTag(- props.selectedTag.title,- props.selectedTagGroupEntry.uuid- );- }+ props.showDeleteTagDialog();}return (@@ -119,28 +99,6 @@ const TagLibraryMenu = (props: Props) => {</MenuItem>)}</Menu>- <EditTagDialog- open={isEditTagDialogOpened}- onClose={handleCloseDialogs}- editTag={props.editTag}- selectedTagGroupEntry={props.selectedTagGroupEntry}- selectedTag={props.selectedTag}- />- <ConfirmDialog- open={isDeleteTagDialogOpened}- onClose={handleCloseDialogs}- title={i18n.t('core:deleteTagFromTagGroup')}- content={i18n.t('core:deleteTagFromTagGroupContentConfirm', {- tagName: props.selectedTag ? props.selectedTag.title : ''- })}- confirmCallback={result => {- if (result) {- confirmDeleteTag();- }- }}- cancelDialogTID="cancelDeleteTagDialogTagMenu"- confirmDialogTID="confirmDeleteTagDialogTagMenu"- /></div>);};diff --git a/app/containers/MainPage.tsx b/app/containers/MainPage.tsxindex f657bf606..e27ce4d91 100644--- a/app/containers/MainPage.tsx+++ b/app/containers/MainPage.tsx@@ -16,7 +16,7 @@**/-import React, { Component } from 'react';+import React, { useEffect, useState } from 'react';import { bindActionCreators } from 'redux';import { connect } from 'react-redux';import { withStyles } from '@material-ui/core/styles';@@ -92,6 +92,7 @@ import IOActions from '-/reducers/io-actions';import FileUploadDialog from '-/components/dialogs/FileUploadDialog';import ProgressDialog from '-/components/dialogs/ProgressDialog';import { FileSystemEntry } from '-/services/utils-io';+import useEventListener from '-/utils/useEventListener';const initialSplitSize = 44;const drawerWidth = 300;@@ -312,51 +313,53 @@ const SelectDirectoryAsync = props => (</React.Suspense>);-interface State {- selectedDirectoryPath: string;- isManagementPanelVisible: boolean;- mainSplitSize: any;- isDrawerOpened: boolean;- width: number;- height: number;-}--let showVerticalPanel = true;+/* let showVerticalPanel = true;if (window.ExtDefaultVerticalPanel === 'none') {showVerticalPanel = false;-}+} */-class MainPage extends Component<Props, State> {- state = {- selectedDirectoryPath: '',- isManagementPanelVisible: showVerticalPanel,- mainSplitSize: '100%',- isDrawerOpened: true,+const MainPage = (props: Props) => {+ const [selectedDirectoryPath, setSelectedDirectoryPath] = useState<string>(+ ''+ );+ /* const [isManagementPanelVisible, setManagementPanelVisible] = useState<+ boolean+ >(window.ExtDefaultVerticalPanel !== 'none' && !props.isEntryInFullWidth); */+ // const [mainSplitSize, setMainSplitSize] = useState<any>('100%');+ // const [isDrawerOpened, setDrawerOpened] = useState<boolean>(true);+ const [dimensions, setDimensions] = useState<any>({width: 1000,height: 1000- };+ });- UNSAFE_componentWillMount() {+ useEffect(() => {if (!AppConfig.isCordova) {- this.updateDimensions();+ updateDimensions();}- }+ // this.setupDesktopMenu();+ buildDesktopMenu(props);+ buildTrayIconMenu(props);+ }, []);++ useEffect(() => {+ if (props.isEntryInFullWidth) {+ props.closeAllVerticalPanels();+ // setMainSplitSize('0%');+ } else {+ // setMainSplitSize(props.mainSplitSize);+ // setManagementPanelVisible(true);+ showDrawer();+ }+ }, [props.isEntryInFullWidth]);- componentDidMount = () => {- if (!AppConfig.isCordova) {- window.addEventListener('resize', this.updateDimensions);+ const getMainSplitSize = () => {+ if (props.openedFiles.length === 0) {+ return '100%';}- // this.setupDesktopMenu();- buildDesktopMenu(this.props);- buildTrayIconMenu(this.props);- };- componentWillReceiveProps(nextProps: Props) {- const isFileOpened = this.props.openedFiles.length > 0;- const isFileOpenedNext = nextProps.openedFiles.length > 0;- const isEntryOpenedChanged = isFileOpenedNext !== isFileOpened;- const isEntryOpenedFullWidthChanged =- nextProps.isEntryInFullWidth !== this.props.isEntryInFullWidth;+ if (props.isEntryInFullWidth) {+ return '0%';+ }const width =window.innerWidth ||document.documentElement.clientWidth ||@@ -365,64 +368,34 @@ class MainPage extends Component<Props, State> {window.innerHeight ||document.documentElement.clientHeight ||body.clientHeight;- if (isFileOpenedNext) {- if (height > width) {- this.setState({- mainSplitSize: '0%'- // isManagementPanelVisible: !nextProps.isEntryInFullWidth- });- } else if (isEntryOpenedFullWidthChanged) {- if (nextProps.isEntryInFullWidth) {- this.props.closeAllVerticalPanels();- }- this.setState({- mainSplitSize: nextProps.isEntryInFullWidth- ? '0%'- : this.props.mainSplitSize,- isManagementPanelVisible: !nextProps.isEntryInFullWidth- });- } else if (isEntryOpenedChanged) {- this.setState({- mainSplitSize: this.props.mainSplitSize- });- }- }- if (!isFileOpenedNext && isEntryOpenedChanged) {- this.setState({- mainSplitSize: '100%'- });- }- if (- nextProps.isLocationManagerPanelOpened ||- nextProps.isTagLibraryPanelOpened ||- nextProps.isSearchPanelOpened ||- nextProps.isPerspectivesPanelOpened ||- nextProps.isHelpFeedbackPanelOpened- ) {- this.setManagementPanelVisibility(true);- // if (!nextProps.isDesktopMode) {- // this.showDrawer();- // }+ if (height > width) {+ return '0%';}+ return props.mainSplitSize;+ };++ const isManagementPanelVisible = () => {if (- !nextProps.isLocationManagerPanelOpened &&- !nextProps.isTagLibraryPanelOpened &&- !nextProps.isSearchPanelOpened &&- !nextProps.isPerspectivesPanelOpened &&- !nextProps.isHelpFeedbackPanelOpened+ props.isLocationManagerPanelOpened ||+ props.isTagLibraryPanelOpened ||+ props.isSearchPanelOpened ||+ props.isPerspectivesPanelOpened ||+ props.isHelpFeedbackPanelOpened) {- this.setManagementPanelVisibility(false);+ return true;}- }+ return false;+ // return window.ExtDefaultVerticalPanel !== 'none' && !props.isEntryInFullWidth;+ };- componentWillUnmount() {+ useEventListener('resize', () => {if (!AppConfig.isCordova) {- window.removeEventListener('resize', this.updateDimensions);+ updateDimensions();}- }+ });- updateDimensions = () => {+ const updateDimensions = () => {const width =window.innerWidth ||document.documentElement.clientWidth ||@@ -433,10 +406,13 @@ class MainPage extends Component<Props, State> {body.clientHeight;// console.log('Width: ' + width + ' Height: ' + height);- this.setState({ width, height });+ setDimensions({ width, height });- if (this.props.openedFiles.length > 0) {- this.props.setEntryFullWidth(height > width);+ if (props.openedFiles.length > 0) {+ const isFillWidth = height > width;+ if (isFillWidth !== props.isEntryInFullWidth) {+ props.setEntryFullWidth(isFillWidth);+ }}// Hide folder container on windows resize or on mobile@@ -455,61 +431,41 @@ class MainPage extends Component<Props, State> {} */};- setManagementPanelVisibility = isVisible => {- this.setState({- isManagementPanelVisible: isVisible- });- };-- hideDrawer = () => {- this.setState({- isDrawerOpened: false- });- };-- showDrawer = () => {+ const showDrawer = () => {if (- !this.props.isLocationManagerPanelOpened &&- !this.props.isSearchPanelOpened &&- !this.props.isTagLibraryPanelOpened+ !props.isLocationManagerPanelOpened &&+ !props.isSearchPanelOpened &&+ !props.isTagLibraryPanelOpened) {- this.props.openLocationManagerPanel();+ props.openLocationManagerPanel();}- this.setState({- isDrawerOpened: true- });+ // setDrawerOpened(true);};- /* toggleDrawer = () => {- this.setState({- isDrawerOpened: !this.state.isDrawerOpened- });- }; */-- skipRelease = () => {- this.props.setUpdateAvailable(false);+ const skipRelease = () => {+ props.setUpdateAvailable(false);};- getLatestVersion = () => {+ const getLatestVersion = () => {if (Pro) {- this.props.showNotification(+ props.showNotification(i18n.t('core:getLatestVersionPro'),'default',false);} else {- this.props.openFileNatively(AppConfig.links.downloadURL);+ props.openFileNatively(AppConfig.links.downloadURL);}- this.props.setUpdateAvailable(false);+ props.setUpdateAvailable(false);};- openChangelogPage = () => {- this.props.openFileNatively(AppConfig.links.changelogURL);+ const openChangelogPage = () => {+ props.openFileNatively(AppConfig.links.changelogURL);};- handleFileDrop = (item, monitor) => {- if (this.props.isReadOnlyMode) {- this.props.showNotification(+ const handleFileDrop = (item, monitor) => {+ if (props.isReadOnlyMode) {+ props.showNotification(i18n.t('core:dndDisabledReadOnlyMode'),'error',true@@ -519,392 +475,353 @@ class MainPage extends Component<Props, State> {if (monitor) {const { files } = monitor.getItem();console.log('Dropped files: ' + JSON.stringify(files));- if (!this.props.directoryPath) {- this.props.showNotification(+ if (!props.directoryPath) {+ props.showNotification('Importing files failed, because no folder is opened in TagSpaces!','error',true);} else {- this.props.resetProgress();- this.props- .uploadFilesAPI(- files,- this.props.directoryPath,- this.props.onUploadProgress- )+ props.resetProgress();+ props+ .uploadFilesAPI(files, props.directoryPath, props.onUploadProgress).then(fsEntries => {- this.props.reflectCreateEntries(fsEntries);+ props.reflectCreateEntries(fsEntries);return true;}).catch(error => {console.log('uploadFiles', error);});- this.props.toggleUploadDialog();+ props.toggleUploadDialog();}}};- chooseDirectoryPath = (currentPath: string) => {- this.setState({- selectedDirectoryPath: currentPath- });+ const keyBindingHandlers = {+ openParentDirectory: props.loadParentDirectoryContent,+ toggleShowHiddenEntries: props.toggleShowUnixHiddenEntries,+ showFolderNavigator: props.openLocationManagerPanel,+ showTagLibrary: props.openTagLibraryPanel,+ openSearch: props.openSearchPanel,+ showHelp: props.openHelpFeedbackPanel};- keyBindingHandlers = {- openParentDirectory: this.props.loadParentDirectoryContent,- toggleShowHiddenEntries: this.props.toggleShowUnixHiddenEntries,- showFolderNavigator: this.props.openLocationManagerPanel,- showTagLibrary: this.props.openTagLibraryPanel,- openSearch: this.props.openSearchPanel,- showHelp: this.props.openHelpFeedbackPanel+ const keyMap = {+ openParentDirectory: props.keyBindings.openParentDirectory,+ toggleShowHiddenEntries: props.keyBindings.toggleShowHiddenEntries,+ showFolderNavigator: props.keyBindings.showFolderNavigator,+ showTagLibrary: props.keyBindings.showTagLibrary,+ openSearch: props.keyBindings.openSearch,+ showHelp: props.keyBindings.showHelp};- keyMap = {- openParentDirectory: this.props.keyBindings.openParentDirectory,- toggleShowHiddenEntries: this.props.keyBindings.toggleShowHiddenEntries,- showFolderNavigator: this.props.keyBindings.showFolderNavigator,- showTagLibrary: this.props.keyBindings.showTagLibrary,- openSearch: this.props.keyBindings.openSearch,- showHelp: this.props.keyBindings.showHelp+ const handleSplitSizeChange = size => {+ if (size > 0 && dimensions.width) {+ const sizeInPercent =+ // @ts-ignore+ parseInt((size * 100) / dimensions.width, 10) + '%';+ // setMainSplitSize(sizeInPercent);+ props.setMainVerticalSplitSize(sizeInPercent);+ }};- render() {- const {- theme,- isCreateFileDialogOpened,- isSettingsDialogOpened,- isAboutDialogOpened,- isKeysDialogOpened,- isOnboardingDialogOpened,- isLicenseDialogOpened,- isThirdPartyLibsDialogOpened,- isSelectDirectoryDialogOpened,- isCreateDirectoryOpened,- isEditTagDialogOpened,- isUploadProgressDialogOpened,- isOpenLinkDialogOpened,- isProgressDialogOpened,- toggleOnboardingDialog,- toggleSettingsDialog,- toggleKeysDialog,- toggleLicenseDialog,- toggleThirdPartyLibsDialog,- toggleAboutDialog,- toggleCreateDirectoryDialog,- toggleCreateFileDialog,- toggleSelectDirectoryDialog,- toggleUploadDialog,- toggleProgressDialog,- toggleEditTagDialog,- toggleOpenLinkDialog,- setFirstRun,- openURLExternally,- directoryPath- } = this.props;- const { FILE } = NativeTypes;-- /* if (this.state.width < 400) {+ const {+ theme,+ toggleOnboardingDialog,+ toggleSettingsDialog,+ toggleKeysDialog,+ toggleLicenseDialog,+ toggleThirdPartyLibsDialog,+ toggleAboutDialog,+ toggleCreateDirectoryDialog,+ toggleCreateFileDialog,+ toggleSelectDirectoryDialog,+ toggleUploadDialog,+ toggleProgressDialog,+ toggleEditTagDialog,+ toggleOpenLinkDialog,+ setFirstRun,+ openURLExternally,+ directoryPath+ } = props;+ const { FILE } = NativeTypes;++ /* if (this.state.width < 400) {this.setManagementPanelVisibility(false);} */- return (- <HotKeys handlers={this.keyBindingHandlers} keyMap={this.keyMap}>- {isAboutDialogOpened && (- <AboutDialogAsync- open={isAboutDialogOpened}- openURLExternally={openURLExternally}- toggleLicenseDialog={toggleLicenseDialog}- toggleThirdPartyLibsDialog={toggleThirdPartyLibsDialog}- onClose={toggleAboutDialog}- />- )}- {isKeysDialogOpened && (- <KeyboardDialogAsync- open={isKeysDialogOpened}- onClose={toggleKeysDialog}- />- )}- {isLicenseDialogOpened && (- <LicenseDialogAsync- open={isLicenseDialogOpened}- onClose={() => {- setFirstRun(false);- toggleLicenseDialog();- }}- />- )}- {isOnboardingDialogOpened && (- <OnboardingDialogAsync- open={isOnboardingDialogOpened}- onClose={toggleOnboardingDialog}- />- )}- {isThirdPartyLibsDialogOpened && (- <ThirdPartyLibsDialogAsync- open={isThirdPartyLibsDialogOpened}- onClose={toggleThirdPartyLibsDialog}- />- )}- {isEditTagDialogOpened && (- <EditEntryTagDialogAsync- open={isEditTagDialogOpened}- onClose={toggleEditTagDialog}- />- )}- {isOpenLinkDialogOpened && (- <OpenLinkDialogAsync- open={isOpenLinkDialogOpened}- onClose={toggleOpenLinkDialog}- />- )}- {isSelectDirectoryDialogOpened && (- <SelectDirectoryAsync- open={isSelectDirectoryDialogOpened}- onClose={toggleSelectDirectoryDialog}- chooseDirectoryPath={this.chooseDirectoryPath}- selectedDirectoryPath={- this.state.selectedDirectoryPath || directoryPath- }- />- )}- {isUploadProgressDialogOpened && (- <FileUploadDialog- open={isUploadProgressDialogOpened}- onClose={toggleUploadDialog}- />- )}- {isProgressDialogOpened && (- <ProgressDialog- open={isProgressDialogOpened}- onClose={toggleProgressDialog}- />- )}- {isCreateDirectoryOpened && (- <CreateDirectoryDialog- open={isCreateDirectoryOpened}- onClose={toggleCreateDirectoryDialog}- selectedDirectoryPath={directoryPath}- />- )}- {isCreateFileDialogOpened && (- <CreateFileDialog- open={isCreateFileDialogOpened}- selectedDirectoryPath={- this.state.selectedDirectoryPath || directoryPath- }- chooseDirectoryPath={this.chooseDirectoryPath}- onClose={toggleCreateFileDialog}- />- )}- {isSettingsDialogOpened && (- <SettingsDialog- open={isSettingsDialogOpened}- onClose={toggleSettingsDialog}- />- )}- <Snackbar- data-tid={this.props.notificationStatus.tid}- anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}- open={this.props.notificationStatus.visible}- onClose={this.props.hideNotifications}- autoHideDuration={- this.props.notificationStatus.autohide ? 3000 : undefined+ return (+ <HotKeys handlers={keyBindingHandlers} keyMap={keyMap}>+ {props.isAboutDialogOpened && (+ <AboutDialogAsync+ open={props.isAboutDialogOpened}+ openURLExternally={openURLExternally}+ toggleLicenseDialog={toggleLicenseDialog}+ toggleThirdPartyLibsDialog={toggleThirdPartyLibsDialog}+ onClose={toggleAboutDialog}+ />+ )}+ {props.isKeysDialogOpened && (+ <KeyboardDialogAsync+ open={props.isKeysDialogOpened}+ onClose={toggleKeysDialog}+ />+ )}+ {props.isLicenseDialogOpened && (+ <LicenseDialogAsync+ open={props.isLicenseDialogOpened}+ onClose={() => {+ setFirstRun(false);+ toggleLicenseDialog();+ }}+ />+ )}+ {props.isOnboardingDialogOpened && (+ <OnboardingDialogAsync+ open={props.isOnboardingDialogOpened}+ onClose={toggleOnboardingDialog}+ />+ )}+ {props.isThirdPartyLibsDialogOpened && (+ <ThirdPartyLibsDialogAsync+ open={props.isThirdPartyLibsDialogOpened}+ onClose={toggleThirdPartyLibsDialog}+ />+ )}+ {props.isEditTagDialogOpened && (+ <EditEntryTagDialogAsync+ open={props.isEditTagDialogOpened}+ onClose={toggleEditTagDialog}+ />+ )}+ {props.isOpenLinkDialogOpened && (+ <OpenLinkDialogAsync+ open={props.isOpenLinkDialogOpened}+ onClose={toggleOpenLinkDialog}+ />+ )}+ {props.isSelectDirectoryDialogOpened && (+ <SelectDirectoryAsync+ open={props.isSelectDirectoryDialogOpened}+ onClose={toggleSelectDirectoryDialog}+ chooseDirectoryPath={currentPath =>+ setSelectedDirectoryPath(currentPath)}- message={this.props.notificationStatus.text}- action={[- <IconButton- data-tid={'close' + this.props.notificationStatus.tid}- key="close"- aria-label={i18n.t('core:closeButton')}- color="inherit"- onClick={this.props.hideNotifications}- >- <CloseIcon />- </IconButton>- ]}+ selectedDirectoryPath={selectedDirectoryPath || directoryPath}/>- <Snackbar- anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}- open={this.props.isGeneratingThumbs}- autoHideDuration={undefined}- message="Loading or generating thumbnails..."- action={[- <IconButton- key="closeButton"- aria-label={i18n.t('core:closeButton')}- color="inherit"- onClick={() => this.props.setGeneratingThumbnails(false)}- >- <CloseIcon />- </IconButton>- ]}+ )}+ {props.isUploadProgressDialogOpened && (+ <FileUploadDialog+ open={props.isUploadProgressDialogOpened}+ onClose={toggleUploadDialog}/>- <Snackbar- anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}- open={this.props.isIndexing}- autoHideDuration={undefined}- message="Indexing"- action={[- <Button- key="cancelIndexButton"- color="secondary"- size="small"- onClick={this.props.cancelDirectoryIndexing}- data-tid="cancelDirectoryIndexing"- >- {i18n.t('core:cancelIndexing')}- </Button>- ]}+ )}+ {props.isProgressDialogOpened && (+ <ProgressDialog+ open={props.isProgressDialogOpened}+ onClose={toggleProgressDialog}/>- <Snackbar- anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}- open={this.props.isUpdateAvailable}- autoHideDuration={undefined}- message={'Version ' + this.props.lastPublishedVersion + ' available.'}- action={[- <Button- key="laterButton"- color="secondary"- size="small"- onClick={this.skipRelease}- >- {i18n.t('core:later')}- </Button>,- <Button- key="changelogButton"- color="secondary"- size="small"- onClick={this.openChangelogPage}- >- {i18n.t('core:releaseNotes')}- </Button>,- <Button- key="latestVersionButton"- color="primary"- size="small"- onClick={this.getLatestVersion}- >- {i18n.t('core:getItNow')}- </Button>- ]}+ )}+ {props.isCreateDirectoryOpened && (+ <CreateDirectoryDialog+ open={props.isCreateDirectoryOpened}+ onClose={toggleCreateDirectoryDialog}+ selectedDirectoryPath={directoryPath}+ />+ )}+ {props.isCreateFileDialogOpened && (+ <CreateFileDialog+ open={props.isCreateFileDialogOpened}+ selectedDirectoryPath={selectedDirectoryPath || directoryPath}+ chooseDirectoryPath={currentPath =>+ setSelectedDirectoryPath(currentPath)+ }+ onClose={toggleCreateFileDialog}/>- {this.props.isDesktopMode ? (- <TargetFileBox- // @ts-ignore- accepts={[FILE]}- onDrop={this.handleFileDrop}+ )}+ {props.isSettingsDialogOpened && (+ <SettingsDialog+ open={props.isSettingsDialogOpened}+ onClose={toggleSettingsDialog}+ />+ )}+ <Snackbar+ data-tid={props.notificationStatus.tid}+ anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}+ open={props.notificationStatus.visible}+ onClose={props.hideNotifications}+ autoHideDuration={props.notificationStatus.autohide ? 3000 : undefined}+ message={props.notificationStatus.text}+ action={[+ <IconButton+ data-tid={'close' + props.notificationStatus.tid}+ key="close"+ aria-label={i18n.t('core:closeButton')}+ color="inherit"+ onClick={props.hideNotifications}>- <CustomDragLayer />- <SplitPane- split="vertical"- // style={{- // borderTop:- // AppConfig.isElectron && !AppConfig.isMacLike- // ? '1px solid lightgray'- // : 'none'- // }}- minSize={200}- maxSize={450}- resizerStyle={{ backgroundColor: theme.palette.divider }}- defaultSize={this.props.leftSplitSize}- size={- this.state.isManagementPanelVisible- ? this.props.leftSplitSize- : initialSplitSize- }- onChange={size => {- this.setState({- isManagementPanelVisible: size > initialSplitSize- });- bufferedLeftSplitResize(() =>- this.props.setLeftVerticalSplitSize(size)- );- }}- >- <VerticalNavigation />- <SplitPane- split="vertical"- minSize="200"- resizerStyle={{ backgroundColor: theme.palette.divider }}- size={this.state.mainSplitSize}- onChange={size => {- if (size > 0 && this.state.width) {- const sizeInPercent =- // @ts-ignore- parseInt((size * 100) / this.state.width, 10) + '%';- this.setState({- mainSplitSize: sizeInPercent- });- // bufferedMainSplitResize(() => this.props.setMainVerticalSplitSize(sizeInPercent));- this.props.setMainVerticalSplitSize(sizeInPercent);- }- }}- >- <FolderContainer- windowHeight={this.state.height}- windowWidth={this.state.width}- openedFiles={this.props.openedFiles}- currentDirectoryPath={this.props.directoryPath}- />- {this.props.openedFiles.length > 0 && (- <EntryContainer- openedFiles={this.props.openedFiles}- currentDirectoryPath={this.props.directoryPath}- />- )}- </SplitPane>- </SplitPane>- </TargetFileBox>- ) : (- <React.Fragment>- <SwipeableDrawer- open={this.state.isDrawerOpened}- onClose={this.hideDrawer}- onOpen={this.showDrawer}- hysteresis={0.1}- disableBackdropTransition={!AppConfig.isIOS}- disableDiscovery={AppConfig.isIOS}- >- <MobileNavigation hideDrawer={this.hideDrawer} />- </SwipeableDrawer>+ <CloseIcon />+ </IconButton>+ ]}+ />+ <Snackbar+ anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}+ open={props.isGeneratingThumbs}+ autoHideDuration={undefined}+ message="Loading or generating thumbnails..."+ action={[+ <IconButton+ key="closeButton"+ aria-label={i18n.t('core:closeButton')}+ color="inherit"+ onClick={() => props.setGeneratingThumbnails(false)}+ >+ <CloseIcon />+ </IconButton>+ ]}+ />+ <Snackbar+ anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}+ open={props.isIndexing}+ autoHideDuration={undefined}+ message="Indexing"+ action={[+ <Button+ key="cancelIndexButton"+ color="secondary"+ size="small"+ onClick={props.cancelDirectoryIndexing}+ data-tid="cancelDirectoryIndexing"+ >+ {i18n.t('core:cancelIndexing')}+ </Button>+ ]}+ />+ <Snackbar+ anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}+ open={props.isUpdateAvailable}+ autoHideDuration={undefined}+ message={'Version ' + props.lastPublishedVersion + ' available.'}+ action={[+ <Button+ key="laterButton"+ color="secondary"+ size="small"+ onClick={skipRelease}+ >+ {i18n.t('core:later')}+ </Button>,+ <Button+ key="changelogButton"+ color="secondary"+ size="small"+ onClick={openChangelogPage}+ >+ {i18n.t('core:releaseNotes')}+ </Button>,+ <Button+ key="latestVersionButton"+ color="primary"+ size="small"+ onClick={getLatestVersion}+ >+ {i18n.t('core:getItNow')}+ </Button>+ ]}+ />+ {props.isDesktopMode ? (+ <TargetFileBox+ // @ts-ignore+ accepts={[FILE]}+ onDrop={handleFileDrop}+ >+ <CustomDragLayer />+ <SplitPane+ split="vertical"+ // style={{+ // borderTop:+ // AppConfig.isElectron && !AppConfig.isMacLike+ // ? '1px solid lightgray'+ // : 'none'+ // }}+ minSize={200}+ maxSize={450}+ resizerStyle={{ backgroundColor: theme.palette.divider }}+ defaultSize={props.leftSplitSize}+ size={+ isManagementPanelVisible()+ ? props.leftSplitSize+ : initialSplitSize+ }+ onChange={size => {+ // setManagementPanelVisible(size > initialSplitSize);+ bufferedLeftSplitResize(() =>+ props.setLeftVerticalSplitSize(size)+ );+ }}+ >+ <VerticalNavigation /><SplitPanesplit="vertical"minSize="200"resizerStyle={{ backgroundColor: theme.palette.divider }}- size={this.state.mainSplitSize}- onChange={size => {- if (size > 0 && this.state.width) {- const sizeInPercent =- // @ts-ignore- parseInt((size * 100) / this.state.width, 10) + '%';- this.setState({- mainSplitSize: sizeInPercent- });- // bufferedMainSplitResize(() => this.props.setMainVerticalSplitSize(sizeInPercent));- this.props.setMainVerticalSplitSize(sizeInPercent);- }- }}+ size={getMainSplitSize()}+ onChange={handleSplitSizeChange}><FolderContainer- windowHeight={this.state.height}- windowWidth={this.state.width}- showDrawer={this.showDrawer}- openedFiles={this.props.openedFiles}- currentDirectoryPath={this.props.directoryPath}+ windowHeight={dimensions.height}+ windowWidth={dimensions.width}+ openedFiles={props.openedFiles}+ currentDirectoryPath={props.directoryPath}/>- {this.props.openedFiles.length > 0 && (+ {props.openedFiles.length > 0 && (<EntryContainer- openedFiles={this.props.openedFiles}- currentDirectoryPath={this.props.directoryPath}+ openedFiles={props.openedFiles}+ currentDirectoryPath={props.directoryPath}/>)}</SplitPane>- </React.Fragment>- )}- </HotKeys>- );- }-}+ </SplitPane>+ </TargetFileBox>+ ) : (+ <React.Fragment>+ <SwipeableDrawer+ open={isManagementPanelVisible()}+ onClose={() => props.closeAllVerticalPanels()}+ onOpen={showDrawer}+ hysteresis={0.1}+ disableBackdropTransition={!AppConfig.isIOS}+ disableDiscovery={AppConfig.isIOS}+ >+ <MobileNavigation+ hideDrawer={() => props.closeAllVerticalPanels()}+ />+ </SwipeableDrawer>+ <SplitPane+ split="vertical"+ minSize="200"+ resizerStyle={{ backgroundColor: theme.palette.divider }}+ size={getMainSplitSize()}+ onChange={handleSplitSizeChange}+ >+ <FolderContainer+ windowHeight={dimensions.height}+ windowWidth={dimensions.width}+ showDrawer={showDrawer}+ openedFiles={props.openedFiles}+ currentDirectoryPath={props.directoryPath}+ />+ {props.openedFiles.length > 0 && (+ <EntryContainer+ openedFiles={props.openedFiles}+ currentDirectoryPath={props.directoryPath}+ />+ )}+ </SplitPane>+ </React.Fragment>+ )}+ </HotKeys>+ );+};function mapStateToProps(state) {return {