Skip to content

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

fix: improving flow support

Ilian Sapundshiev1be42478f867
diff --git a/.vscode/settings.json b/.vscode/settings.json
index e18a055e9..8b8442a26 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -2,7 +2,6 @@
"flow.pathToFlow": "node_modules/.bin/flow",
"javascript.validate.enable": false,
"git.autofetch": true,
- "editor.minimap.enabled": true,
"git.confirmSync": false,
"cSpell.userWords": ["customizability", "mapique", "tagspaces", "treeviz"],
"typescript.format.enable": false,
@@ -21,6 +20,7 @@
},
"cSpell.words": [
"Affero",
+ "flowtype",
"haftungsbeschraenkt",
"lastindex",
"nbsp",
diff --git a/app/.eslintrc b/app/.eslintrc
index 6d3c12ad9..2111b8497 100644
--- a/app/.eslintrc
+++ b/app/.eslintrc
@@ -5,7 +5,7 @@
"flowtype/delimiter-dangle": [2, "never"],
"flowtype/generic-spacing": [2, "never"],
"flowtype/no-primitive-constructor-types": 2,
- "flowtype/no-weak-types": 1,
+ "flowtype/no-weak-types": 0,
"flowtype/object-type-delimiter": [2, "comma"],
"flowtype/require-parameter-type": 0,
"flowtype/require-return-type": 0,
diff --git a/app/components/CustomLogo.js b/app/components/CustomLogo.js
index 0c33d5f51..dd6d1f78c 100644
--- a/app/components/CustomLogo.js
+++ b/app/components/CustomLogo.js
@@ -21,12 +21,12 @@ import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import IconButton from '@material-ui/core/IconButton';
+import { withStyles } from '@material-ui/core/styles';
import Badge from '@material-ui/core/Badge';
import { Pro } from '../pro';
import TextLogoIcon from '../assets/images/text-logo.svg';
import { actions as AppActions } from '../reducers/app';
import versionMeta from '../version.json';
-import { withStyles } from '@material-ui/core/styles';
const AppVersionBadge = withStyles(theme => ({
badge: {
diff --git a/app/components/EntryProperties.js b/app/components/EntryProperties.js
index 8550611af..201867909 100644
--- a/app/components/EntryProperties.js
+++ b/app/components/EntryProperties.js
@@ -141,7 +141,6 @@ const styles = theme => ({
});
const customRenderer = new marked.Renderer();
-// customRenderer.link = (href, title, text) => `<a href="javascript:window.open('${href}', '_blank', 'nodeIntegration=no')" target="_blank">${text}</a>`;
customRenderer.link = (href, title, text) =>
`<a href="#" onClick="event.preventDefault();event.stopPropagation(); window.open('${href}', '_blank', 'nodeIntegration=no');return false;">${text}</a>`;
@@ -159,22 +158,20 @@ marked.setOptions({
type Props = {
classes: Object,
- entryPath?: string | null,
- shouldReload?: boolean | null,
- settings: Object,
- shouldCopyFile?: boolean,
+ entryPath: string,
+ shouldReload: boolean | null,
+ shouldCopyFile: boolean,
editTagForEntry: () => void,
- renameFile: () => void,
- renameDirectory: () => void,
+ renameFile: (path: string, nextPath: string) => void,
+ renameDirectory: (path: string, nextPath: string) => void,
normalizeShouldCopyFile: () => void,
- showNotification: () => void,
+ showNotification: (message: string) => void,
reflectUpdateSidecarMeta: (path: string, entryMeta: Object) => void,
updateThumbnailUrl: (path: string, thumbUrl: string) => void,
addTags: () => void,
removeTags: () => void,
removeAllTags: () => void,
- resetState: () => void,
- showSelectDirectoryDialog: () => void,
+ resetState: (stateName: string) => void,
isReadOnlyMode: boolean,
setPropertiesEditMode: (editMode: boolean) => void
};
@@ -190,9 +187,11 @@ type State = {
isEditTagDialogOpened: boolean | null,
isDeleteTagDialogOpened: boolean,
isFileThumbChooseDialogOpened: boolean,
+ isMoveCopyFilesDialogOpened: boolean,
isEditName: boolean,
isEditDescription: boolean,
displayColorPicker: boolean,
+ thumbPath: string,
isFile: boolean
};
@@ -235,7 +234,7 @@ class EntryProperties extends Component<Props, State> {
}
}
- loadEntryProperties = entryPath => {
+ loadEntryProperties = (entryPath: string) => {
getAllPropertiesPromise(entryPath)
.then(entryProps => {
this.setState({
@@ -336,6 +335,7 @@ class EntryProperties extends Component<Props, State> {
toggleEditDescriptionField = () => {
if (this.props.isReadOnlyMode) {
this.setState({
+ // customRenderer.link = (href, title, text) => `<a href="javascript:window.open('${href}', '_blank', 'nodeIntegration=no')" target="_blank">${text}</a>`;
isEditDescription: false
});
return;
diff --git a/app/components/LocationManager.js b/app/components/LocationManager.js
index 8cbde5815..1e0b90c05 100644
--- a/app/components/LocationManager.js
+++ b/app/components/LocationManager.js
@@ -87,7 +87,8 @@ type Props = {
perspectives: Array<Object>,
currentLocationId: string,
isReadOnlyMode: boolean,
- hideDrawer?: () => void,
+ hideDrawer: () => void,
+ openFile: (path: string) => void,
openURLExternally: (path: string) => void,
loadDirectoryContent: (path: string) => void,
openLocation: (location: Location) => void,
@@ -512,7 +513,7 @@ class LocationManager extends React.Component<Props, State> {
});
};
- renderNameColumnAction = (field, location, key) => {
+ renderNameColumnAction = field => {
const children = (
<span style={{ fontSize: 15, marginLeft: 5 }} title={field}>
<FolderIcon
@@ -520,21 +521,12 @@ class LocationManager extends React.Component<Props, State> {
className={this.props.classes.icon}
/>
{field && field.length > 25 ? field.substr(0, 25) + '...' : field}
- {/* <IconButton
- style={{ float: 'right', paddingTop: 0, paddingBottom: 0, paddingLeft: 0, paddingRight: 0 }}
- aria-label={i18n.t('core:options')}
- aria-haspopup="true"
- data-tid={'locationMoreButton_' + field.name}
- onClick={event => this.handleLocationContextMenuClick(event, location)}
- >
- <MoreVertIcon />
- </IconButton> */}
</span>
);
return {
children,
props: {}
- }; // (<span>{ name }</span>);
+ };
};
handleCellClick = (record, index) => ({
diff --git a/app/components/menus/DirectoryMenu.js b/app/components/menus/DirectoryMenu.js
index 81abe246a..b948a0f42 100644
--- a/app/components/menus/DirectoryMenu.js
+++ b/app/components/menus/DirectoryMenu.js
@@ -34,7 +34,7 @@ import AutoRenew from '@material-ui/icons/Autorenew';
import DefaultPerspectiveIcon from '@material-ui/icons/GridOn';
import GalleryPerspectiveIcon from '@material-ui/icons/Camera';
import MapiquePerspectiveIcon from '@material-ui/icons/Map';
-import TreeVizPerspectiveIcon from '@material-ui/icons/AccountTree';
+// import TreeVizPerspectiveIcon from '@material-ui/icons/AccountTree';
import NewFileIcon from '@material-ui/icons/InsertDriveFile';
import NewFolderIcon from '@material-ui/icons/CreateNewFolder';
import RenameFolderIcon from '@material-ui/icons/FormatTextdirectionLToR';
diff --git a/app/components/menus/EntryTagMenu.js b/app/components/menus/EntryTagMenu.js
index 5d30b3e88..b5253c747 100644
--- a/app/components/menus/EntryTagMenu.js
+++ b/app/components/menus/EntryTagMenu.js
@@ -36,17 +36,16 @@ import { getMaxSearchResults } from '../../reducers/settings';
import { actions as AppActions } from '../../reducers/app';
type Props = {
- classes: Object,
open: boolean,
onClose: () => void,
anchorEl: Object | null,
selectedTag: Tag | null,
currentEntryPath: string,
removeTags: (paths: Array<string>, tags: Array<Tag>) => void,
- editTagForEntry: (path: string, tag: Tag) => void,
searchLocationIndex: (searchQuery: SearchQuery) => void,
maxSearchResults: number,
openSearchPanel: () => void,
+ toggleEditTagDialog: (tag: Tag) => void,
isReadOnlyMode: boolean
};
diff --git a/app/perspectives/file-manager/index.js b/app/perspectives/file-manager/index.js
deleted file mode 100644
index f616c0b93..000000000
--- a/app/perspectives/file-manager/index.js
+++ /dev/null
@@ -1,360 +0,0 @@
-/**
- * TagSpaces - universal file and folder organizer
- * Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License (version 3) as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- *
- * @flow
- */
-
-// export { default as FileManagerPerspective } from './rc-table';
-import React from 'react';
-import Table from 'rc-table';
-import Checkbox from '@material-ui/core/Checkbox';
-import ArrowDownward from '@material-ui/icons/ArrowDownward';
-import ArrowUpward from '@material-ui/icons/ArrowUpward';
-import Button from '@material-ui/core/Button';
-import Tooltip from '@material-ui/core/Tooltip';
-import { formatDateTime, formatFileSize } from '../../utils/misc';
-import TagContainer from '../../components/TagContainer';
-import FileMenu from '../../components/menus/FileMenu';
-import { type FileSystemEntry } from '../../services/utils-io';
-import { type Tag } from '../../reducers/taglibrary';
-// import 'rc-table/assets/index.css';
-
-type Props = {
- classes: Object,
- openFile: (path: string) => void,
- openFileNatively: (path: string) => void,
- deleteFile: (path: string) => void,
- renameFile: (path: string) => void,
- showInFileManager: (path: string) => void,
- loadDirectoryContent: (path: string) => void,
- directoryContent: Array<FileSystemEntry>
-};
-
-type State = {};
-
-class FileManagerPerspective extends React.Component<Props, State> {
- state = {
- fileContextMenuOpened: false,
- fileContextMenuAnchorEl: null,
- selected: [],
- orderBy: '',
- data: [],
- order: '',
- checked: [0],
- itemPath: '',
- extension: this.props.directoryContent.map(item => item.extension)
- };
-
- /*
- <Button
- data-tid="extension"
- title={this.state.extension}
- onClick={(e) => this.handleExtensionButton(e, this.state.itemPath)}
- >
- {this.state.extension}
- </Button>
- */
-
- handleRequestSort = sortBy => {
- this.setState({ orderBy: !this.state.orderBy });
- this.props.sortByCriteria(sortBy, this.state.orderBy);
- };
-
- handleSelectAllClick = (event, checked) => {
- if (checked) {
- this.setState({ selected: this.state.data.map(n => n.id) });
- return;
- }
- this.setState({ selected: [] });
- };
-
- handleClick = (event, id) => {
- const { selected } = this.state;
- const selectedIndex = selected.indexOf(id);
- let newSelected = [];
-
- if (selectedIndex === -1) {
- newSelected = newSelected.concat(selected, id);
- } else if (selectedIndex === 0) {
- newSelected = newSelected.concat(selected.slice(1));
- } else if (selectedIndex === selected.length - 1) {
- newSelected = newSelected.concat(selected.slice(0, -1));
- } else if (selectedIndex > 0) {
- newSelected = newSelected.concat(
- selected.slice(0, selectedIndex),
- selected.slice(selectedIndex + 1)
- );
- }
-
- this.setState({ selected: newSelected });
- };
-
- handleChangePage = (event, page) => {
- this.setState({ page });
- };
-
- handleChangeRowsPerPage = event => {
- this.setState({ rowsPerPage: event.target.value });
- };
-
- isSelected = id => this.state.selected.indexOf(id) !== -1;
-
- renderExtColumnAction = () => (
- <div>
- <Checkbox
- checked={this.state.checkBox}
- onChange={(event, checked) => this.setState({ checkBox: checked })}
- tabIndex={-1}
- disableRipple
- />
- </div>
- );
-
- renderExtHeadTableAction = () => (
- <div>
- <Tooltip title="Sort">
- <Button
- title="Ext"
- onClick={this.handleRequestSort('ext', !this.state.order)}
- >
- <ArrowUpward style={{ width: 16, height: 16 }} />
- </Button>
- </Tooltip>
- </div>
- );
-
- renderNameColumnAction = name => <span>{name}</span>;
-
- renderIsFileColumnAction = isFile => {
- if (isFile) {
- return <span>File</span>;
- }
- return <span>Folder</span>;
- };
-
- renderTagColumnAction = (tags: Array<Tag>) =>
- // TODO color should come from this.props.settings.tagBackgroundColor
- tags.map((tag, index) => (
- <TagContainer
- key={index}
- defaultTextColor={'white'}
- defaultBackgroundColor={'green'}
- tag={tag}
- index={index}
- />
- ));
-
- renderLastModifiedColumnAction = lmdt => (
- <span>{formatDateTime(lmdt, true)}</span>
- );
-
- renderSizeColumnAction = size => <span>{formatFileSize(size)}</span>;
-
- handleCellClick = (record, index) => ({
- onContextMenu: e => {
- this.handleFileContextMenu(e, record.path);
- },
- onClick: () => {
- this.setState({ checkBox: true });
- },
- onDoubleClick: e => {
- this.onRowClick(record, index, e);
- }
- });
- // <a
- // title="Ext"
- // onClick={e => this.handleRequestSort(e, 'ext', !this.state.order)}
- // >
- columns = [
- {
- title: this.renderExtHeadTableAction,
- dataIndex: 'ext',
- key: 'ext',
- width: '30%',
- render: this.renderExtColumnAction,
- onCell: this.handleCellClick
- },
- {
- title: (
- <div>
- {' '}
- Name
- <Tooltip title="Sort">
- <ArrowUpward style={{ width: 16, height: 16 }} />
- </Tooltip>
- </div>
- ),
- dataIndex: 'name',
- key: 'name',
- width: '80%',
- render: this.renderNameColumnAction,
- onCell: this.handleCellClick
- },
- {
- title: (
- <div>
- {' '}
- Is File
- <Tooltip title="Sort">
- <ArrowDownward style={{ width: 16, height: 16 }} />
- </Tooltip>
- </div>
- ),
- dataIndex: 'isFile',
- key: 'isFile',
- render: this.renderIsFileColumnAction,
- onCell: this.handleCellClick
- },
- {
- title: (
- <div>
- {' '}
- Tags
- <Tooltip title="Sort">
- <ArrowDownward style={{ width: 16, height: 16 }} />
- </Tooltip>
- </div>
- ),
- dataIndex: 'tags',
- key: 'tags',
- render: this.renderTagColumnAction,
- onCell: this.handleCellClick
- },
- {
- title: (
- <div>
- {' '}
- Size
- <Tooltip title="Sort">
- <ArrowDownward style={{ width: 16, height: 16 }} />
- </Tooltip>
- </div>
- ),
- dataIndex: 'size',
- key: 'size',
- render: this.renderSizeColumnAction,
- onCell: this.handleCellClick
- },
- {
- title: (
- <div>
- {' '}
- Last Modified
- <Tooltip title="Sort">
- <ArrowDownward style={{ width: 16, height: 16 }} />
- </Tooltip>
- </div>
- ),
- dataIndex: 'lmdt',
- key: 'lmdt',
- render: this.renderLastModifiedColumnAction,
- onCell: this.handleCellClick
- }
- ];
-
- handleToggle = value => e => {
- e.preventDefault();
- const { checked } = this.state;
- const currentIndex = checked.indexOf(value);
- const newChecked = [...checked];
-
- if (currentIndex === -1) {
- newChecked.push(value);
- } else {
- newChecked.splice(currentIndex, 1);
- }
-
- this.setState({
- checked: newChecked
- });
- };
-
- onRowClick = (record, index, event) => {
- this.setState({ itemPath: record.path });
- event.preventDefault();
- // console.log(`Click nth(${index}) row of parent, record.name: ${record.path}`);
- // See https://facebook.github.io/react/docs/events.html for original click event details.
- if (event.shiftKey) {
- console.log('Shift + mouse click triggered.');
- }
- if (record.isFile) {
- this.props.openFile(record.path);
- } else {
- this.props.loadDirectoryContent(record.path);
- }
- };
-
- handleFileContextMenu = (event, directoryPath) => {
- this.setState({
- fileContextMenuOpened: true,
- fileContextMenuAnchorEl: event.currentTarget,
- selectedFilePath: directoryPath
- });
- };
-
- toggleFileMenuClose = event => {
- this.setState({
- fileContextMenuOpened: !this.state.fileContextMenuOpened,
- fileContextMenuAnchorEl: event ? event.currentTarget : null
- });
- };
-
- handleRequestCloseContextMenus = () => {
- this.setState({
- fileContextMenuOpened: false,
- fileContextMenuAnchorEl: null
- });
- };
-
- render() {
- console.log('File Manager: ', this.props);
- const classes = this.props.classes;
-
- // numSelected={selected.length}
- // order={order}
- // orderBy={orderBy}
- // onSelectAllClick={this.handleSelectAllClick}
- // onRequestSort={this.handleRequestSort}
-
- return (
- <div>
- <Table
- rowKey="uuid"
- data={this.props.directoryContent}
- columns={this.columns}
- />
- <FileMenu
- classes={classes}
- open={this.state.fileContextMenuOpened}
- onClose={this.toggleFileMenuClose}
- anchorEl={this.state.fileContextMenuAnchorEl}
- openFileNatively={this.props.openFileNatively}
- openFile={this.props.openFile}
- deleteFile={this.props.deleteFile}
- renameFile={this.props.renameFile}
- copyFiles={this.props.copyFiles}
- moveFiles={this.props.moveFiles}
- showInFileManager={this.props.showInFileManager}
- addRemoveTags={this.props.addRemoveTags}
- selectedFilePath={this.state.selectedFilePath}
- allTags={this.props.allTags}
- />
- </div>
- );
- }
-}
-
-export default FileManagerPerspective;
diff --git a/app/perspectives/virtualizing-perspective/src/index.js b/app/perspectives/virtualizing-perspective/src/index.js
deleted file mode 100644
index 0695d0848..000000000
--- a/app/perspectives/virtualizing-perspective/src/index.js
+++ /dev/null
@@ -1,1513 +0,0 @@
-/**
- * TagSpaces - universal file and folder organizer
- * Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License (version 3) as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- *
- * @flow
- */
-
-import React from 'react';
-import uuidv1 from 'uuid';
-import { connect } from 'react-redux';
-import { bindActionCreators } from 'redux';
-import removeMd from 'remove-markdown';
-import memoize from 'memoize-one';
-import { withStyles } from '@material-ui/core/styles';
-import classNames from 'classnames';
-import Paper from '@material-ui/core/Paper';
-import Typography from '@material-ui/core/Typography';
-import Toolbar from '@material-ui/core/Toolbar';
-import MoreVertIcon from '@material-ui/icons/MoreVert';
-import RadioCheckedIcon from '@material-ui/icons/RadioButtonChecked';
-import RadioUncheckedIcon from '@material-ui/icons/RadioButtonUnchecked';
-import ListItemIcon from '@material-ui/core/ListItemIcon';
-import ListItemText from '@material-ui/core/ListItemText';
-import Grid from '@material-ui/core/Grid';
-// import { Grid as GridVirtualized } from 'react-virtualized';
-import {
- CellMeasurer,
- CellMeasurerCache,
- createMasonryCellPositioner,
- Masonry,
- WindowScroller,
- AutoSizer
-} from 'react-virtualized';
-import ParentDirIcon from '@material-ui/icons/SubdirectoryArrowLeft';
-import ViewListIcon from '@material-ui/icons/ViewList';
-import SwapVertIcon from '@material-ui/icons/SwapVert';
-import ViewGridIcon from '@material-ui/icons/ViewModule';
-import ArrowUpIcon from '@material-ui/icons/KeyboardArrowUp';
-import ArrowDownIcon from '@material-ui/icons/KeyboardArrowDown';
-import IconButton from '@material-ui/core/IconButton';
-import Menu from '@material-ui/core/Menu';
-import MenuItem from '@material-ui/core/MenuItem';
-import Divider from '@material-ui/core/Divider';
-import ThumbnailCoverIcon from '@material-ui/icons/PhotoSizeSelectActual';
-import ThumbnailContainIcon from '@material-ui/icons/PhotoSizeSelectLarge';
-import FolderIcon from '@material-ui/icons/FolderOpen';
-import FolderHiddenIcon from '@material-ui/icons/Folder';
-import TagIcon from '@material-ui/icons/LocalOffer';
-import CopyIcon from '@material-ui/icons/FileCopy';
-import DeleteIcon from '@material-ui/icons/Delete';
-import SelectAllIcon from '@material-ui/icons/CheckBox';
-import DeSelectAllIcon from '@material-ui/icons/CheckBoxOutlineBlank';
-import {
- type FileSystemEntry,
- findColorForFileEntry
-} from '../../../services/utils-io';
-import { type Tag } from '../../../reducers/taglibrary';
-import { getSupportedFileTypes } from '../../../reducers/settings';
-import { extractTitle } from '../../../utils/paths';
-import {
- formatFileSize,
- formatDateTime,
- sortByCriteria,
- isObj,
- isVisibleOnScreen
-} from '../../../utils/misc';
-import styles from './styles.css';
-import FileMenu from '../../../components/menus/FileMenu';
-import DirectoryMenu from '../../../components/menus/DirectoryMenu';
-import EntryTagMenu from '../../../components/menus/EntryTagMenu';
-import TagContainerDnd from '../../../components/TagContainerDnd';
-import TagContainer from '../../../components/TagContainer';
-import i18n from '../../../services/i18n';
-import ConfirmDialog from '../../../components/dialogs/ConfirmDialog';
-import AddRemoveTagsDialog from '../../../components/dialogs/AddRemoveTagsDialog';
-import MoveCopyFilesDialog from '../../../components/dialogs/MoveCopyFilesDialog';
-import RenameFileDialog from '../../../components/dialogs/RenameFileDialog';
-import TagDropContainer from '../../../components/TagDropContainer';
-import TargetMoveFileBox from '../../../components/TargetMoveFileBox';
-import FileSourceDnd from '../../../components/FileSourceDnd';
-import AppConfig from '../../../config';
-import DragItemTypes from '../../../components/DragItemTypes';
-import IOActions from '../../../reducers/io-actions';
-import {
- actions as AppActions,
- getLastSelectedEntry,
- getSelectedEntries,
- getCurrentDirectoryColor,
- isLoading,
- isReadOnlyMode
-} from '../../../reducers/app';
-import TaggingActions from '../../../reducers/tagging-actions';
-
-const maxDescriptionPreviewLength = 100;
-
-const settings = JSON.parse(localStorage.getItem('tsPerspectiveGrid')); // loading settings
-
-type Props = {
- classes: Object,
- theme: Object,
- currentDirectoryPath: string,
- currentDirectoryColor: string,
- lastSelectedEntryPath: string | null,
- selectedEntries: Array<Object>,
- supportedFileTypes: Array<Object>,
- isAppLoading: boolean,
- isReadOnlyMode: boolean,
- openFile: (path: string, isFile?: boolean) => void,
- deleteFile: (path: string) => void,
- deleteDirectory: (path: string) => void,
- loadDirectoryContent: (path: string) => void,
- openDirectory: (path: string) => void,
- showInFileManager: (path: string) => void,
- openFileNatively: (path: string) => void,
- loadParentDirectoryContent: () => void,
- setLastSelectedEntry: (entryPath: string | null) => void,
- setSelectedEntries: (selectedEntries: Array<Object>) => void,
- addTags: () => void,
- removeTags: () => void,
- removeAllTags: () => void,
- editTagForEntry: () => void,
- perspectiveCommand: Object,
- directoryContent: Array<FileSystemEntry>,
- moveFiles: (files: Array<string>, destination: string) => void,
- showNotification: (
- text: string,
- notificationType: string,
- autohide: boolean
- ) => void
-};
-
-type State = {
- fileContextMenuAnchorEl?: Object | null,
- fileContextMenuOpened?: boolean,
- dirContextMenuAnchorEl?: Object | null,
- dirContextMenuOpened?: boolean,
- tagContextMenuAnchorEl?: Object | null,
- tagContextMenuOpened?: boolean,
- layoutType?: string,
- singleClickAction?: string,
- doubleClickAction?: string,
- entrySize?: string,
- thumbnailMode?: string,
- sortingContextMenuAnchorEl?: Object | null,
- sortingContextMenuOpened?: boolean | null,
- optionsContextMenuAnchorEl?: Object | null,
- optionsContextMenuOpened?: boolean | null,
- sortBy?: string,
- orderBy?: null | boolean,
- fileOperationsEnabled?: boolean,
- allFilesSelected?: boolean,
- showDirectories?: boolean,
- isDeleteMultipleFilesDialogOpened?: boolean,
- isMoveCopyFilesDialogOpened?: boolean,
- isAddRemoveTagsDialogOpened?: boolean,
- isFileRenameDialogOpened?: boolean,
- selectedEntryPath?: string,
- selectedTag?: Tag | null,
- columnWidth: number,
- height: number,
- gutterSize: number,
- overscanByPixels: number,
- windowScrollerEnabled: boolean
-};
-
-class GridPerspective extends React.Component<Props, State> {
- constructor(props) {
- super(props);
- this.state = {
- fileContextMenuOpened: false,
- fileContextMenuAnchorEl: null,
- dirContextMenuOpened: false,
- dirContextMenuAnchorEl: null,
- tagContextMenuOpened: false,
- tagContextMenuAnchorEl: null,
- sortingContextMenuOpened: false,
- sortingContextMenuAnchorEl: null,
- optionsContextMenuOpened: false,
- optionsContextMenuAnchorEl: null,
- selectedEntryPath: '',
- sortBy: settings && settings.sortBy ? settings.sortBy : 'byName',
- orderBy: settings && settings.orderBy ? settings.orderBy : true,
- layoutType:
- settings && settings.layoutType ? settings.layoutType : 'grid',
- singleClickAction:
- settings && settings.singleClickAction
- ? settings.singleClickAction
- : 'openInternal', // openExternal
- doubleClickAction:
- settings && settings.doubleClickAction
- ? settings.doubleClickAction
- : 'openInternal', // openExternal
- entrySize: settings && settings.entrySize ? settings.entrySize : 'normal', // small, big
- thumbnailMode:
- settings && settings.thumbnailMode ? settings.thumbnailMode : 'cover', // contain
- fileOperationsEnabled: false,
- allFilesSelected: false,
- showDirectories:
- settings && settings.showDirectories ? settings.showDirectories : true,
- isDeleteMultipleFilesDialogOpened: false,
- isMoveCopyFilesDialogOpened: false,
- isAddRemoveTagsDialogOpened: false,
- isFileRenameDialogOpened: false,
- selectedTag: null,
- columnWidth: 200,
- height: 400,
- gutterSize: 10,
- overscanByPixels: 1000,
- windowScrollerEnabled: true
- };
-
- this.initContent(this.props.directoryContent);
- }
-
- componentWillReceiveProps = (nextProps: Props) => {
- const {
- lastSelectedEntryPath,
- perspectiveCommand,
- selectedEntries
- } = nextProps;
-
- if (perspectiveCommand && perspectiveCommand.key) {
- this.props.setLastSelectedEntry(null);
- if (perspectiveCommand.key === 'TOGGLE_SELECT_ALL') {
- this.toggleSelectAllFiles();
- } else if (
- perspectiveCommand.key === 'ADD_REMOVE_TAGS' &&
- selectedEntries &&
- selectedEntries.length > 0
- ) {
- this.openAddRemoveTagsDialog();
- } else if (
- perspectiveCommand.key === 'RENAME_ENTRY' &&
- selectedEntries &&
- selectedEntries.length === 1
- ) {
- if (selectedEntries[0].isFile) {
- this.setState({ selectedEntryPath: selectedEntries[0].path }, () => {
- this.openFileRenameDialog();
- });
- }
- } else if (
- perspectiveCommand.key === 'DELETE_SELECTED_ENTRIES' &&
- this.state.fileOperationsEnabled
- ) {
- this.openDeleteFileDialog();
- }
- }
-
- if (lastSelectedEntryPath !== null) {
- this.computeFileOperationsEnabled();
- // this.makeFirstSelectedEntryVisible(); // disable due to wrong scrolling
- }
-
- // Directory changed
- if (
- nextProps.currentDirectoryPath !== this.props.currentDirectoryPath // && this.mainGrid
- ) {
- // Clear selection on directory change
- this.clearSelection();
-
- // const grid = document.querySelector(
- // '[data-tid="perspectiveGridFileTable"]'
- // );
- // const firstGridItem = grid.querySelector('div');
-
- // if (isObj(firstGridItem)) {
- // firstGridItem.scrollIntoView({ top: 80 });
- // }
- }
- // Directory content changed
- if (nextProps.directoryContent !== this.props.directoryContent) {
- this.initContent(nextProps.directoryContent);
- this.calculateColumnCount();
- this.resetCellPositioner();
- this._masonry.recomputeCellPositions();
- }
- };
-
- initContent = directoryContent => {
- const { sortBy, orderBy } = this.state;
- this.sortedContent = this.sort(directoryContent, sortBy, orderBy);
- };
-
- sort = memoize((data, criteria, order) =>
- sortByCriteria(data, criteria, order)
- );
-
- makeFirstSelectedEntryVisible = () => {
- const { selectedEntries } = this.props;
- if (selectedEntries && selectedEntries.length > 0) {
- const firstSelectedElement = document.querySelector(
- '[data-entry-id="' + selectedEntries[0].uuid + '"]'
- );
- if (
- isObj(firstSelectedElement) &&
- !isVisibleOnScreen(firstSelectedElement)
- ) {
- // firstSelectedElement.parentNode.scrollTop = firstSelectedElement.offsetTop - firstSelectedElement.parentNode.offsetTop;
- firstSelectedElement.scrollIntoView(false);
- }
- }
- };
-
- saveSettings() {
- const settingsObj = {
- showDirectories: this.state.showDirectories,
- layoutType: this.state.layoutType,
- orderBy: this.state.orderBy,
- sortBy: this.state.sortBy,
- singleClickAction: this.state.singleClickAction,
- doubleClickAction: this.state.doubleClickAction,
- entrySize: this.state.entrySize,
- thumbnailMode: this.state.thumbnailMode
- };
- localStorage.setItem('tsPerspectiveGrid', JSON.stringify(settingsObj));
- }
-
- scrollToBottom = () => {
- const messagesContainer = ReactDOM.findDOMNode(this.messagesContainer);
- messagesContainer.scrollTop = messagesContainer.scrollHeight;
- };
-
- // mainGrid;
-
- handleLayoutSwitch = (layoutType: string) => {
- this.setState({ layoutType }, this.saveSettings);
- };
-
- handleSortBy = sortBy => {
- this.closeSortingMenu();
- this.setState(
- {
- orderBy: !this.state.orderBy,
- sortBy
- },
- this.saveSettings
- );
- };
-
- handleSortingMenu = event => {
- this.setState({
- sortingContextMenuOpened: !this.state.sortingContextMenuOpened,
- sortingContextMenuAnchorEl: event ? event.currentTarget : null
- });
- };
-
- handleOptionsMenu = event => {
- this.setState({
- optionsContextMenuOpened: !this.state.optionsContextMenuOpened,
- optionsContextMenuAnchorEl: event ? event.currentTarget : null
- });
- };
-
- handleGridCellClick = (event, fsEntry: FileSystemEntry) => {
- const { selectedEntries } = this.props;
- if (event.shiftKey) {
- let lastSelectedIndex = this.props.directoryContent.findIndex(
- entry => entry.path === this.props.lastSelectedEntryPath
- );
- const currentSelectedIndex = this.props.directoryContent.findIndex(
- entry => entry.path === fsEntry.path
- );
- if (lastSelectedIndex < 0) {
- lastSelectedIndex = currentSelectedIndex;
- }
-
- let entriesToSelect;
- // console.log('lastSelectedIndex: ' + lastSelectedIndex + ' currentSelectedIndex: ' + currentSelectedIndex);
- if (currentSelectedIndex > lastSelectedIndex) {
- entriesToSelect = this.props.directoryContent.slice(
- lastSelectedIndex,
- currentSelectedIndex + 1
- );
- } else if (currentSelectedIndex < lastSelectedIndex) {
- entriesToSelect = this.props.directoryContent.slice(
- currentSelectedIndex,
- lastSelectedIndex + 1
- );
- } else if (currentSelectedIndex === lastSelectedIndex) {
- entriesToSelect = [fsEntry];
- this.props.setLastSelectedEntry(fsEntry.path);
- }
-
- this.props.setSelectedEntries(entriesToSelect);
- this.setState(this.computeFileOperationsEnabled);
- } else if (event.ctrlKey) {
- if (
- selectedEntries &&
- selectedEntries.some(entry => entry.path === fsEntry.path)
- ) {
- this.props.setSelectedEntries(
- selectedEntries.filter(entry => entry.path !== fsEntry.path)
- ); // deselect selected entry
- this.setState(this.computeFileOperationsEnabled);
- // this.props.setLastSelectedEntry(null);
- } else {
- this.props.setSelectedEntries([...selectedEntries, fsEntry]);
- this.setState(this.computeFileOperationsEnabled);
- // this.props.setLastSelectedEntry(fsEntry.path);
- }
- } else {
- this.props.setSelectedEntries([fsEntry]);
- this.setState(this.computeFileOperationsEnabled);
- this.props.setLastSelectedEntry(fsEntry.path);
- if (fsEntry.isFile) {
- if (this.state.singleClickAction === 'openInternal') {
- this.props.openFile(fsEntry.path, fsEntry.isFile);
- } else if (this.state.singleClickAction === 'openExternal') {
- this.props.openFileNatively(fsEntry.path);
- }
- // else if (this.state.singleClickAction === 'selects') {}
- }
- }
- };
-
- clearSelection = () => {
- this.props.setSelectedEntries([]);
- this.setState(
- {
- allFilesSelected: false
- },
- this.computeFileOperationsEnabled
- );
- this.props.setLastSelectedEntry(null);
- };
-
- toggleSelectAllFiles = () => {
- if (this.state.allFilesSelected) {
- this.clearSelection();
- } else {
- const selectedEntries = [];
- this.props.directoryContent.map(entry => {
- if (entry.isFile) {
- selectedEntries.push(entry);
- }
- return true;
- });
- this.props.setSelectedEntries(selectedEntries);
- this.setState(
- {
- allFilesSelected: !this.state.allFilesSelected
- },
- this.computeFileOperationsEnabled
- );
- }
- };
-
- toggleShowDirectories = () => {
- this.closeOptionsMenu();
- this.setState(
- {
- showDirectories: !this.state.showDirectories
- },
- this.saveSettings
- );
- };
-
- toggleThumbnailsMode = () => {
- this.closeOptionsMenu();
- this.setState(
- {
- thumbnailMode:
- this.state.thumbnailMode === 'cover' ? 'contain' : 'cover'
- },
- this.saveSettings
- );
- };
-
- changeEntrySize = entrySize => {
- this.closeOptionsMenu();
- this.setState({ entrySize }, this.saveSettings);
- };
-
- changeSingleClickAction = singleClickAction => {
- this.closeOptionsMenu();
- this.setState({ singleClickAction }, this.saveSettings);
- };
-
- handleGridCellDblClick = (event, fsEntry: FileSystemEntry) => {
- this.props.setSelectedEntries([]);
- this.setState(this.computeFileOperationsEnabled);
- if (fsEntry.isFile) {
- this.props.setSelectedEntries([fsEntry]);
- this.setState(this.computeFileOperationsEnabled);
- this.props.openFile(fsEntry.path);
- } else {
- console.log('Handle Grid cell db click, selected path : ', fsEntry.path);
- this.props.loadDirectoryContent(fsEntry.path);
- }
- };
-
- handleGridContextMenu = (event, fsEntry: FileSystemEntry) => {
- const { selectedEntries } = this.props;
-
- if (fsEntry.isFile) {
- this.props.setSelectedEntries(
- event.ctrlKey ? [...selectedEntries, fsEntry] : [fsEntry]
- );
- this.setState({
- fileContextMenuOpened: true,
- fileContextMenuAnchorEl: event.currentTarget,
- selectedEntryPath: fsEntry.path
- });
- } else {
- this.props.setSelectedEntries([fsEntry]);
- this.setState({
- dirContextMenuOpened: true,
- dirContextMenuAnchorEl: event.currentTarget,
- selectedEntryPath: fsEntry.path
- });
- }
- };
-
- handleTagMenu = (event: Object, tag: Tag, entryPath: string) => {
- event.preventDefault();
- event.stopPropagation();
-
- this.setState({
- selectedTag: tag,
- tagContextMenuAnchorEl: event.currentTarget,
- tagContextMenuOpened: true,
- selectedEntryPath: entryPath
- });
- };
-
- closeFileMenu = () => {
- this.setState({
- fileContextMenuOpened: false,
- fileContextMenuAnchorEl: null
- });
- };
-
- closeDirMenu = () => {
- this.setState({
- dirContextMenuOpened: false,
- dirContextMenuAnchorEl: null
- });
- };
-
- closeTagMenu = () => {
- this.setState({
- tagContextMenuOpened: false,
- tagContextMenuAnchorEl: null
- });
- };
-
- closeSortingMenu = () => {
- this.setState({
- sortingContextMenuOpened: false,
- sortingContextMenuAnchorEl: null
- });
- };
-
- closeOptionsMenu = () => {
- this.setState({
- optionsContextMenuOpened: false,
- optionsContextMenuAnchorEl: null
- });
- };
-
- handleCloseDialogs = () => {
- this.setState({
- isFileRenameDialogOpened: false,
- isDeleteMultipleFilesDialogOpened: false,
- isAddRemoveTagsDialogOpened: false,
- isMoveCopyFilesDialogOpened: false
- });
- // this.clearSelection();
- };
-
- openFileRenameDialog = () => {
- this.setState({ isFileRenameDialogOpened: true });
- };
-
- openMoveCopyFilesDialog = () => {
- this.setState({ isMoveCopyFilesDialogOpened: true });
- };
-
- openDeleteFileDialog = () => {
- this.setState({ isDeleteMultipleFilesDialogOpened: true });
- };
-
- openAddRemoveTagsDialog = () => {
- this.setState({ isAddRemoveTagsDialogOpened: true });
- };
-
- computeFileOperationsEnabled = () => {
- const { selectedEntries } = this.props;
- if (selectedEntries && selectedEntries.length > 0) {
- let selectionContainsDirectories = false;
- selectedEntries.map(entry => {
- if (!entry.isFile) {
- selectionContainsDirectories = true;
- }
- return true;
- });
- this.setState({ fileOperationsEnabled: !selectionContainsDirectories });
- } else {
- this.setState({ fileOperationsEnabled: false });
- }
- };
-
- handleFileMoveDrop = (item, monitor) => {
- if (this.props.isReadOnlyMode) {
- this.props.showNotification(
- i18n.t('core:dndDisabledReadOnlyMode'),
- 'error',
- true
- );
- return;
- }
- if (monitor) {
- const { path } = monitor.getItem();
- console.log('Dropped files: ' + path);
- this.props.moveFiles([path], item.children.props.entryPath);
- }
- };
-
- renderCell = (fsEntry: FileSystemEntry) => {
- const { entrySize, layoutType, showDirectories } = this.state;
- const { classes, theme, selectedEntries } = this.props;
- if (fsEntry === undefined || (!fsEntry.isFile && !showDirectories)) {
- return;
- }
-
- let selected = false;
- if (
- selectedEntries &&
- selectedEntries.some(entry => entry.path === fsEntry.path)
- ) {
- selected = true;
- }
- let entryHeight = 130;
- if (entrySize === 'small') {
- entryHeight = 50;
- } else if (entrySize === 'normal') {
- entryHeight = 80;
- } else if (entrySize === 'big') {
- entryHeight = 130;
- }
- const cellContent = (
- <TagDropContainer entryPath={fsEntry.path}>
- <Paper
- data-entry-id={fsEntry.uuid}
- className={classNames(
- layoutType === 'grid' && classes.gridCell,
- layoutType === 'row' && classes.rowCell,
- selected && layoutType === 'grid' && classes.selectedGridCell,
- selected && layoutType === 'row' && classes.selectedRowCell
- )}
- style={{
- // minHeight: layoutType === 'row' ? entryHeight : 'auto',
- backgroundColor: theme.palette.background.default
- }}
- onContextMenu={event => this.handleGridContextMenu(event, fsEntry)}
- onDoubleClick={event => this.handleGridCellDblClick(event, fsEntry)}
- onClick={event => this.handleGridCellClick(event, fsEntry)}
- >
- {this.renderCellContent(fsEntry, entryHeight)}
- </Paper>
- </TagDropContainer>
- );
- if (fsEntry.isFile) {
- return <FileSourceDnd>{cellContent}</FileSourceDnd>;
- }
-
- return (
- <div style={{ position: 'relative' }}>
- <TargetMoveFileBox
- accepts={[DragItemTypes.FILE]}
- onDrop={this.handleFileMoveDrop}
- >
- {cellContent}
- </TargetMoveFileBox>
- </div>
- );
- };
-
- renderTag = (tag: Object, fsEntry) => {
- const isReadOnly = this.props.isReadOnlyMode;
- return isReadOnly ? (
- <TagContainer
- tag={tag}
- key={tag.id}
- entryPath={fsEntry.path}
- addTags={this.props.addTags}
- handleTagMenu={this.handleTagMenu}
- selectedEntries={this.props.selectedEntries}
- />
- ) : (
- <TagContainerDnd
- tag={tag}
- key={tag.id}
- entryPath={fsEntry.path}
- addTags={this.props.addTags}
- handleTagMenu={this.handleTagMenu}
- selectedEntries={this.props.selectedEntries}
- />
- );
- };
-
- renderCellContent = (fsEntry: FileSystemEntry, entryHeight: number) => {
- const { classes, theme, supportedFileTypes } = this.props;
- const fsEntryBackgroundColor = fsEntry.color
- ? fsEntry.color
- : 'transparent';
- let description = removeMd(fsEntry.description);
- if (description.length > maxDescriptionPreviewLength) {
- description = description.substr(0, maxDescriptionPreviewLength) + '...';
- }
- const fsEntryColor = findColorForFileEntry(
- fsEntry.extension,
- fsEntry.isFile,
- supportedFileTypes
- );
-
- let thumbPathUrl = fsEntry.thumbPath
- ? 'url("' + fsEntry.thumbPath + '")'
- : '';
- if (AppConfig.isWin) {
- thumbPathUrl = thumbPathUrl.split('\\').join('\\\\');
- }
- if (this.state.layoutType === 'grid') {
- return (
- <div
- style={{
- backgroundColor: fsEntryBackgroundColor
- }}
- >
- <div
- className={classes.gridCellThumb}
- style={{
- backgroundSize: this.state.thumbnailMode,
- backgroundImage: thumbPathUrl,
- height: 150 // fsEntry.isFile ? 150 : 70
- }}
- >
- <div id="gridCellTags" className={classes.gridCellTags}>
- {fsEntry.tags.map(tag => this.renderTag(tag, fsEntry))}
- </div>
- {description.length > 0 && (
- <Typography
- id="gridCellDescription"
- className={classes.gridCellDescription}
- title={i18n.t('core:filePropertiesDescription')}
- variant="caption"
- >
- {description}
- </Typography>
- )}
- </div>
- <Typography
- className={classes.gridCellTitle}
- data-tid="fsEntryName"
- title={fsEntry.path}
- noWrap={true}
- variant="body1"
- >
- {extractTitle(fsEntry.name, !fsEntry.isFile)}
- </Typography>
- {fsEntry.isFile ? (
- <div className={classes.gridDetails}>
- <Typography
- className={classes.gridFileExtension}
- style={{ backgroundColor: fsEntryColor }}
- noWrap={true}
- variant="button"
- title={fsEntry.path}
- >
- {fsEntry.extension}
- </Typography>
- <Typography className={classes.gridSizeDate} variant="caption">
- <span
- title={
- i18n.t('core:modifiedDate') +
- ': ' +
- formatDateTime(fsEntry.lmdt, true)
- }
- >
- {fsEntry.lmdt}
- </span>
- <span title={fsEntry.size + ' ' + i18n.t('core:sizeInBytes')}>
- {' ' + formatFileSize(fsEntry.size)}
- </span>
- </Typography>
- </div>
- ) : (
- <div className={classes.gridDetails}>
- <FolderIcon
- className={classes.gridFolder}
- style={{ backgroundColor: fsEntryColor }}
- title={fsEntry.path}
- />
- {/* <Typography className={classes.gridSizeDate} variant="caption">
- {' ' + formatDateTime4Tag(fsEntry.lmdt) }
- </Typography> */}
- </div>
- )}
- </div>
- );
- } else if (this.state.layoutType === 'row') {
- return (
- <Grid
- container
- wrap="nowrap"
- style={{
- backgroundColor: theme.palette.background.default
- }}
- >
- <Grid
- item
- style={{
- minHeight: entryHeight,
- padding: 10,
- marginRight: 5,
- borderRadius: 4,
- backgroundColor: fsEntryBackgroundColor
- }}
- >
- {fsEntry.isFile ? (
- <div
- className={classes.rowFileExtension}
- title={fsEntry.path}
- style={{ backgroundColor: fsEntryColor }}
- >
- {fsEntry.extension}
- </div>
- ) : (
- <span className={classes.gridFolder} title={fsEntry.path}>
- <FolderIcon
- className={classes.rowFolder}
- style={{ backgroundColor: fsEntryColor }}
- />
- </span>
- )}
- </Grid>
- <Grid item xs zeroMinWidth>
- <Typography>
- {extractTitle(fsEntry.name, !fsEntry.isFile)}
- </Typography>
- {fsEntry.tags.map(tag => this.renderTag(tag, fsEntry))}
- <Typography
- // noWrap
- style={{
- color: 'gray',
- padding: 5
- }}
- >
- <span title={fsEntry.size + ' ' + i18n.t('core:sizeInBytes')}>
- {fsEntry.isFile && formatFileSize(fsEntry.size) + ' - '}
- </span>
- <span
- title={
- i18n.t('core:modifiedDate') +
- ': ' +
- formatDateTime(fsEntry.lmdt, true)
- }
- >
- {fsEntry.isFile && fsEntry.lmdt && '️ ' + fsEntry.lmdt + ' '}
- </span>
- <span title={i18n.t('core:entryDescription')}>
- {description && description}
- </span>
- </Typography>
- </Grid>
- {fsEntry.thumbPath && (
- <Grid
- item
- style={
- {
- // margin: 5,
- }
- }
- >
- <div
- className={classes.gridCellThumb}
- style={{
- backgroundSize: this.state.thumbnailMode,
- backgroundImage: thumbPathUrl,
- margin: 1,
- height: 85,
- width: 85
- }}
- />
- </Grid>
- )}
- </Grid>
- );
- }
- };
-
- cellRenderer = ({ index, key, parent, style }) => (
- <CellMeasurer cache={this.cache} index={index} key={key} parent={parent}>
- <div style={style}>
- <div style={{ height: '225px' }}>
- {this.renderCell(this.sortedContent[index])}
- </div>
- </div>
- </CellMeasurer>
- );
-
- onResize = ({ width }) => {
- this._width = width;
-
- this.calculateColumnCount();
- this.resetCellPositioner();
- this._masonry.recomputeCellPositions();
- };
-
- resetCellPositioner = () => {
- const { columnWidth, gutterSize } = this.state;
-
- this.cellPositioner.reset({
- columnCount: this._columnCount,
- columnWidth,
- spacer: gutterSize
- });
- };
-
- calculateColumnCount = () => {
- const { columnWidth, gutterSize } = this.state;
-
- this._columnCount = Math.floor(this._width / (columnWidth + gutterSize));
- };
-
- renderMasonry = ({ width }) => {
- this._width = width;
-
- this.calculateColumnCount();
- this.initCellPositioner();
-
- const { overscanByPixels } = this.state;
-
- return (
- <Masonry
- autoHeight={true}
- cellCount={this.sortedContent.length}
- cellMeasurerCache={this.cache}
- cellPositioner={this.cellPositioner}
- cellRenderer={this.cellRenderer}
- height={this._height}
- overscanByPixels={overscanByPixels}
- ref={ref => {
- this._masonry = ref;
- }}
- scrollTop={this.scrollTop}
- width={width}
- />
- );
- };
-
- renderAutoSizer = ({ height, scrollTop }) => {
- this._height = height;
- this._scrollTop = scrollTop;
-
- const { overscanByPixels } = this.state;
-
- return (
- <AutoSizer
- disableHeight
- height={height}
- onResize={this.onResize}
- overscanByPixels={overscanByPixels}
- scrollTop={scrollTop}
- >
- {this.renderMasonry}
- </AutoSizer>
- );
- };
-
- initCellPositioner = () => {
- if (typeof this.cellPositioner === 'undefined') {
- const { columnWidth, gutterSize } = this.state;
-
- this.cellPositioner = createMasonryCellPositioner({
- cellMeasurerCache: this.cache,
- columnCount: this._columnCount,
- columnWidth,
- spacer: gutterSize
- });
- }
- };
-
- cache = new CellMeasurerCache({
- defaultHeight: 250,
- defaultWidth: 200,
- fixedWidth: true
- });
-
- render() {
- const {
- classes,
- isAppLoading,
- directoryContent,
- currentDirectoryColor,
- selectedEntries,
- theme
- } = this.props;
- const {
- layoutType,
- entrySize,
- sortBy,
- orderBy,
- overscanByPixels
- } = this.state;
- const selectedFilePaths = selectedEntries
- .filter(fsEntry => fsEntry.isFile)
- .map(fsentry => fsentry.path);
- const sortedContent = this.sort(directoryContent, sortBy, orderBy);
- const sortedDirectories = sortedContent.filter(entry => !entry.isFile);
- const sortedFiles = sortedContent.filter(entry => entry.isFile);
- let entryWidth = 200;
- if (entrySize === 'small') {
- entryWidth = 150;
- } else if (entrySize === 'normal') {
- entryWidth = 200;
- } else if (entrySize === 'big') {
- entryWidth = 300;
- }
- // console.log('Render grid');
- return (
- <div style={{ height: '100%' }}>
- <style>
- {`
- #gridCellTags:hover, #gridCellDescription:hover {
- opacity: 1
- }
- `}
- </style>
- <Toolbar
- className={classes.topToolbar}
- data-tid="perspectiveGridToolbar"
- >
- <IconButton
- title={i18n.t('core:toggleSelectAllFiles')}
- data-tid="gridPerspectiveSelectAllFiles"
- onClick={this.toggleSelectAllFiles}
- >
- {this.state.allFilesSelected ? (
- <SelectAllIcon />
- ) : (
- <DeSelectAllIcon />
- )}
- </IconButton>
- <IconButton
- title={i18n.t('core:navigateToParentDirectory')}
- aria-label={i18n.t('core:navigateToParentDirectory')}
- data-tid="gridPerspectiveOnBackButton"
- onClick={this.props.loadParentDirectoryContent}
- >
- <ParentDirIcon />
- </IconButton>
- {this.state.layoutType === 'row' ? (
- <IconButton
- title={i18n.t('core:switchToGridView')}
- aria-label={i18n.t('core:switchToGridView')}
- data-tid="gridPerspectiveSwitchLayoutToGrid"
- onClick={() => {
- this.handleLayoutSwitch('grid');
- }}
- >
- <ViewGridIcon />
- </IconButton>
- ) : (
- <IconButton
- title={i18n.t('core:switchToListView')}
- aria-label={i18n.t('core:switchToListView')}
- data-tid="gridPerspectiveSwitchLayoutToRow"
- onClick={() => {
- this.handleLayoutSwitch('row');
- }}
- >
- <ViewListIcon />
- </IconButton>
- )}
- {!this.props.isReadOnlyMode && (
- <IconButton
- title={i18n.t('core:tagSelectedEntries')}
- aria-label={i18n.t('core:tagSelectedEntries')}
- data-tid="gridPerspectiveAddRemoveTags"
- disabled={selectedEntries.length < 1}
- onClick={this.openAddRemoveTagsDialog}
- >
- <TagIcon />
- </IconButton>
- )}
- {!this.props.isReadOnlyMode && (
- <IconButton
- title={i18n.t('core:copyMoveSelectedEntries')}
- aria-label={i18n.t('core:copyMoveSelectedEntries')}
- data-tid="gridPerspectiveCopySelectedFiles"
- disabled={!this.state.fileOperationsEnabled}
- onClick={this.openMoveCopyFilesDialog}
- >
- <CopyIcon />
- </IconButton>
- )}
- {!this.props.isReadOnlyMode && (
- <IconButton
- title={i18n.t('core:deleteSelectedEntries')}
- aria-label={i18n.t('core:deleteSelectedEntries')}
- data-tid="gridPerspectiveDeleteMultipleFiles"
- disabled={!this.state.fileOperationsEnabled}
- onClick={this.openDeleteFileDialog}
- >
- <DeleteIcon />
- </IconButton>
- )}
- <IconButton
- title={i18n.t('core:sort')}
- aria-label={i18n.t('core:sort')}
- data-tid="gridPerspectiveSortMenu"
- onClick={e => {
- this.handleSortingMenu(e);
- }}
- >
- <SwapVertIcon />
- </IconButton>
- <IconButton
- title={i18n.t('core:options')}
- data-tid="gridPerspectiveOptionsMenu"
- onClick={e => {
- this.handleOptionsMenu(e);
- }}
- >
- <MoreVertIcon />
- </IconButton>
- </Toolbar>
- <div
- style={{
- height: '100%',
- backgroundColor: theme.palette.background.default
- }}
- >
- <div
- style={{
- height: '100%',
- overflowY: AppConfig.isFirefox ? 'auto' : 'overlay',
- backgroundColor: currentDirectoryColor || 'transparent'
- }}
- >
- <WindowScroller overscanByPixels={overscanByPixels}>
- {this.renderAutoSizer}
- </WindowScroller>{' '}
- {/*
- <GridVirtualized
- cellRenderer={this.cellRenderer}
- columnCount={5}
- columnWidth={100}
- height={300}
- rowCount={this.sortedContent.length}
- rowHeight={30}
- width={300}
- /> */}
- {/* <div
- className={layoutType === 'grid' ? classes.gridContainer : classes.rowContainer}
- style={{
- gridTemplateColumns: layoutType === 'grid' ? 'repeat(auto-fit,minmax(' + entryWidth + 'px,1fr))' : 'none',
- }}
- ref={ref => {
- this.mainGrid = ref;
- }}
- data-tid="perspectiveGridFileTable"
- >
- {(sortedDirectories.map(entry => this.renderCell(entry)))}
- {(sortedFiles.map(entry => this.renderCell(entry)))}
- {isAppLoading && (
- <Typography style={{ padding: 15 }}>
- {i18n.t('core:loading')}
- </Typography>
- )}
- {(!isAppLoading && sortedFiles.length < 1 && sortedDirectories.length < 1) && (
- <Typography style={{ padding: 15 }}>
- {i18n.t('core:noFileFolderFound')}
- </Typography>
- )}
- </div> */}
- </div>
- </div>
- <AddRemoveTagsDialog
- open={this.state.isAddRemoveTagsDialogOpened}
- onClose={this.handleCloseDialogs}
- addTags={this.props.addTags}
- removeTags={this.props.removeTags}
- removeAllTags={this.props.removeAllTags}
- selectedEntries={this.props.selectedEntries}
- />
- <MoveCopyFilesDialog
- key={uuidv1()}
- open={this.state.isMoveCopyFilesDialogOpened}
- onClose={this.handleCloseDialogs}
- selectedFiles={selectedFilePaths}
- />
- <RenameFileDialog
- open={this.state.isFileRenameDialogOpened}
- onClose={this.handleCloseDialogs}
- selectedFilePath={this.state.selectedEntryPath}
- />
- <ConfirmDialog
- open={this.state.isDeleteMultipleFilesDialogOpened}
- onClose={this.handleCloseDialogs}
- title={i18n.t('core:deleteConfirmationTitle')}
- content={i18n.t('core:deleteConfirmationContent')}
- list={selectedFilePaths}
- confirmCallback={result => {
- if (result && this.props.selectedEntries) {
- this.props.selectedEntries.map(fsentry => {
- if (fsentry.isFile) {
- this.props.deleteFile(fsentry.path);
- }
- return true;
- });
- }
- }}
- cancelDialogTID="cancelDeleteFileDialog"
- confirmDialogTID="confirmDeleteFileDialog"
- confirmDialogContentTID="confirmDeleteDialogContent"
- />
- <FileMenu
- anchorEl={this.state.fileContextMenuAnchorEl}
- open={this.state.fileContextMenuOpened}
- onClose={this.closeFileMenu}
- openDeleteFileDialog={this.openDeleteFileDialog}
- openRenameFileDialog={this.openFileRenameDialog}
- openMoveCopyFilesDialog={this.openMoveCopyFilesDialog}
- openAddRemoveTagsDialog={this.openAddRemoveTagsDialog}
- openFile={this.props.openFile}
- openFileNatively={this.props.openFileNatively}
- showInFileManager={this.props.showInFileManager}
- isReadOnlyMode={this.props.isReadOnlyMode}
- selectedFilePath={this.state.selectedEntryPath}
- />
- <DirectoryMenu
- open={this.state.dirContextMenuOpened}
- onClose={this.closeDirMenu}
- anchorEl={this.state.dirContextMenuAnchorEl}
- directoryPath={this.state.selectedEntryPath}
- loadDirectoryContent={this.props.loadDirectoryContent}
- openDirectory={this.props.openDirectory}
- showInFileManager={this.props.showInFileManager}
- openFileNatively={this.props.openFileNatively}
- openFile={this.props.openFile}
- deleteDirectory={this.props.deleteDirectory}
- isReadOnlyMode={this.props.isReadOnlyMode}
- perspectiveMode={true}
- />
- <EntryTagMenu
- anchorEl={this.state.tagContextMenuAnchorEl}
- open={this.state.tagContextMenuOpened}
- onClose={this.closeTagMenu}
- selectedTag={this.state.selectedTag}
- currentEntryPath={this.state.selectedEntryPath}
- removeTags={this.props.removeTags}
- editTagForEntry={this.props.editTagForEntry}
- isReadOnlyMode={this.props.isReadOnlyMode}
- />
- <Menu
- open={this.state.sortingContextMenuOpened}
- onClose={this.closeSortingMenu}
- anchorEl={this.state.sortingContextMenuAnchorEl}
- >
- {/* <ListSubHeader>Sort by</ListSubHeader> */}
- <MenuItem
- data-tid="gridPerspectiveSortByName"
- onClick={() => {
- this.handleSortBy('byName');
- }}
- >
- <ListItemIcon style={{ minWidth: 25 }}>
- {this.state.sortBy === 'byName' &&
- (this.state.orderBy ? <ArrowUpIcon /> : <ArrowDownIcon />)}
- </ListItemIcon>
- <ListItemText inset primary={i18n.t('core:fileTitle')} />
- </MenuItem>
- <MenuItem
- data-tid="gridPerspectiveSortBySize"
- onClick={() => {
- this.handleSortBy('byFileSize');
- }}
- >
- <ListItemIcon style={{ minWidth: 25 }}>
- {this.state.sortBy === 'byFileSize' &&
- (this.state.orderBy ? <ArrowUpIcon /> : <ArrowDownIcon />)}
- </ListItemIcon>
- <ListItemText inset primary={i18n.t('core:fileSize')} />
- </MenuItem>
- <MenuItem
- data-tid="gridPerspectiveSortByDate"
- onClick={() => {
- this.handleSortBy('byDateModified');
- }}
- >
- <ListItemIcon style={{ minWidth: 25 }}>
- {this.state.sortBy === 'byDateModified' &&
- (this.state.orderBy ? <ArrowUpIcon /> : <ArrowDownIcon />)}
- </ListItemIcon>
- <ListItemText inset primary={i18n.t('core:fileLDTM')} />
- </MenuItem>
- <MenuItem
- data-tid="gridPerspectiveSortByFirstTag"
- onClick={() => {
- this.handleSortBy('byFirstTag');
- }}
- >
- <ListItemIcon style={{ minWidth: 25 }}>
- {this.state.sortBy === 'byFirstTag' &&
- (this.state.orderBy ? <ArrowUpIcon /> : <ArrowDownIcon />)}
- </ListItemIcon>
- <ListItemText inset primary={i18n.t('core:fileFirstTag')} />
- </MenuItem>
- <MenuItem
- data-tid="gridPerspectiveSortByExt"
- onClick={() => {
- this.handleSortBy('byExtension');
- }}
- >
- <ListItemIcon style={{ minWidth: 25 }}>
- {this.state.sortBy === 'byExtension' &&
- (this.state.orderBy ? <ArrowUpIcon /> : <ArrowDownIcon />)}
- </ListItemIcon>
- <ListItemText inset primary={i18n.t('core:fileExtension')} />
- </MenuItem>
- <MenuItem
- data-tid="gridPerspectiveSortRandom"
- onClick={() => {
- this.handleSortBy('random');
- }}
- >
- <ListItemIcon style={{ minWidth: 25 }}>
- {this.state.sortBy === 'random' && <ArrowDownIcon />}
- </ListItemIcon>
- <ListItemText inset primary={i18n.t('core:random')} />
- </MenuItem>
- </Menu>
- <Menu
- open={this.state.optionsContextMenuOpened}
- onClose={this.closeOptionsMenu}
- anchorEl={this.state.optionsContextMenuAnchorEl}
- >
- <MenuItem
- data-tid="gridPerspectiveToggleShowDirectories"
- title={i18n.t('core:showHideDirectories')}
- aria-label={i18n.t('core:showHideDirectories')}
- onClick={this.toggleShowDirectories}
- >
- <ListItemIcon style={{ minWidth: 25 }}>
- {this.state.showDirectories ? (
- <FolderIcon />
- ) : (
- <FolderHiddenIcon />
- )}
- </ListItemIcon>
- <ListItemText inset primary={i18n.t('core:showHideDirectories')} />
- </MenuItem>
- <MenuItem
- data-tid="gridPerspectiveToggleThumbnailsMode"
- title={i18n.t('core:toggleThumbnailModeTitle')}
- aria-label={i18n.t('core:toggleThumbnailMode')}
- onClick={this.toggleThumbnailsMode}
- >
- <ListItemIcon>
- {this.state.thumbnailMode === 'cover' ? (
- <ThumbnailCoverIcon />
- ) : (
- <ThumbnailContainIcon />
- )}
- </ListItemIcon>
- <ListItemText inset primary={i18n.t('core:toggleThumbnailMode')} />
- </MenuItem>
- <Divider />
- <MenuItem
- data-tid="gridPerspectiveEntrySizeSmall"
- title={i18n.t('core:entrySizeSmall')}
- aria-label={i18n.t('core:entrySizeSmall')}
- onClick={() => this.changeEntrySize('small')}
- >
- <ListItemIcon>
- {this.state.entrySize === 'small' ? (
- <RadioCheckedIcon />
- ) : (
- <RadioUncheckedIcon />
- )}
- </ListItemIcon>
- <ListItemText inset primary={i18n.t('core:entrySizeSmall')} />
- </MenuItem>
- <MenuItem
- data-tid="gridPerspectiveEntrySizeNormal"
- title={i18n.t('core:entrySizeNormal')}
- aria-label={i18n.t('core:entrySizeNormal')}
- onClick={() => this.changeEntrySize('normal')}
- >
- <ListItemIcon>
- {this.state.entrySize === 'normal' ? (
- <RadioCheckedIcon />
- ) : (
- <RadioUncheckedIcon />
- )}
- </ListItemIcon>
- <ListItemText inset primary={i18n.t('core:entrySizeNormal')} />
- </MenuItem>
- <MenuItem
- data-tid="gridPerspectiveEntrySizeBig"
- title={i18n.t('core:entrySizeBig')}
- aria-label={i18n.t('core:entrySizeBig')}
- onClick={() => this.changeEntrySize('big')}
- >
- <ListItemIcon>
- {this.state.entrySize === 'big' ? (
- <RadioCheckedIcon />
- ) : (
- <RadioUncheckedIcon />
- )}
- </ListItemIcon>
- <ListItemText inset primary={i18n.t('core:entrySizeBig')} />
- </MenuItem>
- <Divider />
- <MenuItem
- data-tid="gridPerspectiveSingleClickOpenInternally"
- title={i18n.t('core:singleClickOpenInternally')}
- aria-label={i18n.t('core:singleClickOpenInternally')}
- onClick={() => this.changeSingleClickAction('openInternal')}
- >
- <ListItemIcon>
- {this.state.singleClickAction === 'openInternal' ? (
- <RadioCheckedIcon />
- ) : (
- <RadioUncheckedIcon />
- )}
- </ListItemIcon>
- <ListItemText
- inset
- primary={i18n.t('core:singleClickOpenInternally')}
- />
- </MenuItem>
- <MenuItem
- data-tid="gridPerspectiveSingleClickOpenExternally"
- title={i18n.t('core:singleClickOpenExternally')}
- aria-label={i18n.t('core:singleClickOpenExternally')}
- onClick={() => this.changeSingleClickAction('openExternal')}
- >
- <ListItemIcon>
- {this.state.singleClickAction === 'openExternal' ? (
- <RadioCheckedIcon />
- ) : (
- <RadioUncheckedIcon />
- )}
- </ListItemIcon>
- <ListItemText
- inset
- primary={i18n.t('core:singleClickOpenExternally')}
- />
- </MenuItem>
- <MenuItem
- data-tid="gridPerspectiveSingleClickSelects"
- title={i18n.t('core:singleClickSelects')}
- aria-label={i18n.t('core:singleClickSelects')}
- onClick={() => this.changeSingleClickAction('selects')}
- >
- <ListItemIcon>
- {this.state.singleClickAction === 'selects' ? (
- <RadioCheckedIcon />
- ) : (
- <RadioUncheckedIcon />
- )}
- </ListItemIcon>
- <ListItemText inset primary={i18n.t('core:singleClickSelects')} />
- </MenuItem>
- </Menu>
- </div>
- );
- }
-}
-
-function mapActionCreatorsToProps(dispatch) {
- return bindActionCreators(
- {
- moveFiles: IOActions.moveFiles,
- setSelectedEntries: AppActions.setSelectedEntries,
- showNotification: AppActions.showNotification,
- addTags: TaggingActions.addTags
- },
- dispatch
- );
-}
-
-function mapStateToProps(state) {
- return {
- supportedFileTypes: getSupportedFileTypes(state),
- isAppLoading: isLoading(state),
- isReadOnlyMode: isReadOnlyMode(state),
- lastSelectedEntryPath: getLastSelectedEntry(state),
- currentDirectoryColor: getCurrentDirectoryColor(state),
- selectedEntries: getSelectedEntries(state)
- };
-}
-
-export default connect(
- mapStateToProps,
- mapActionCreatorsToProps
-)(withStyles(styles, { withTheme: true })(GridPerspective));
diff --git a/app/perspectives/virtualizing-perspective/src/styles.css.js b/app/perspectives/virtualizing-perspective/src/styles.css.js
deleted file mode 100644
index 2b5588ed8..000000000
--- a/app/perspectives/virtualizing-perspective/src/styles.css.js
+++ /dev/null
@@ -1,158 +0,0 @@
-/**
- * TagSpaces - universal file and folder organizer
- * Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License (version 3) as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- *
- * @flow
- */
-import AppConfig from '../../../config';
-
-export default theme => ({
- gridContainer: {
- display: 'grid',
- gridGap: '2px 2px',
- padding: 10,
- marginBottom: 100
- },
- rowContainer: {
- display: 'grid',
- gridGap: '0px 0px',
- padding: 0,
- paddingRight: 10,
- margin: 0,
- marginBottom: 100
- },
- gridCell: {
- // backgroundColor: theme.palette.background.paper,
- border: '2px solid transparent',
- margin: 2,
- marginBottom: 3,
- marginRight: 3,
- borderRadius: 5
- },
- rowCell: {
- // backgroundColor: theme.palette.background.paper,
- boxShadow: 'none',
- borderLeft: '2px solid transparent',
- borderRight: '2px solid transparent',
- borderTop: '1px solid transparent',
- borderBottom: '1px solid ' + theme.palette.divider,
- margin: 0,
- marginTop: 0,
- marginBottom: 0,
- borderRadius: 0
- },
- selectedGridCell: {
- border: '2px solid' + theme.palette.primary.main,
- backgroundColor: theme.palette.primary.light + ' !important'
- },
- selectedRowCell: {
- borderRadius: '4px',
- border: '2px solid' + theme.palette.primary.main,
- backgroundColor: theme.palette.primary.light + ' !important'
- },
- gridCellThumb: {
- backgroundRepeat: 'no-repeat',
- backgroundPosition: 'center'
- },
- gridCellTitle: {
- padding: 5,
- minHeight: 20
- },
- gridCellTags: {
- padding: 0,
- paddingTop: 5,
- zIndex: 100,
- maxHeight: 100,
- overflowY: 'auto',
- overflowX: 'hidden',
- opacity: 0.6
- },
- gridCellDescription: {
- padding: 2,
- margin: 2,
- backgroundColor: theme.palette.background.paper,
- opacity: 0.6,
- borderRadius: 5
- },
- gridFileExtension: {
- flex: 1,
- padding: 5,
- marginRight: 5,
- maxWidth: 50,
- minWidth: 40,
- minHeight: 16,
- borderRadius: 3,
- borderWidth: 1,
- color: 'white',
- // color: theme.palette.getContrastText(),
- textAlign: 'center'
- },
- rowFileExtension: {
- flex: 1,
- padding: 5,
- marginTop: 5,
- marginRight: 5,
- marginLeft: 5,
- borderRadius: 3,
- maxWidth: 45,
- minHeight: 15,
- borderWidth: 1,
- color: 'white',
- textTransform: 'uppercase',
- fontSize: 12,
- fontWeight: 'bold',
- // color: theme.palette.getContrastText(),
- textAlign: 'center'
- },
- gridSizeDate: {
- overflow: AppConfig.isFirefox ? 'auto' : 'overlay',
- flex: 3,
- textAlign: 'right',
- whiteSpace: 'nowrap',
- marginRight: 5,
- paddingTop: 5
- },
- gridDetails: {
- display: 'flex',
- whiteSpace: 'nowrap'
- },
- rowFolder: {
- color: 'white',
- padding: 5,
- marginRight: 5,
- marginTop: 5,
- minHeight: 10,
- height: 20,
- borderRadius: 3
- },
- gridFolder: {
- color: 'white',
- padding: 5,
- marginRight: 5,
- minHeight: 10,
- height: 20,
- borderRadius: 3
- },
- topToolbar: {
- paddingLeft: 5,
- paddingRight: 5,
- minHeight: 40,
- height: 53,
- backgroundColor: theme.palette.background.default,
- borderBottom: '1px solid ' + theme.palette.divider,
- width: '100%',
- overflowX: AppConfig.isFirefox ? 'auto' : 'overlay'
- }
-});
diff --git a/app/reducers/index.js b/app/reducers/index.js
index c6ec8454a..88c7ffa26 100644
--- a/app/reducers/index.js
+++ b/app/reducers/index.js
@@ -16,7 +16,7 @@
*
* @flow
*/
-import { persistCombineReducers, createMigrate } from 'redux-persist';
+import { persistCombineReducers } from 'redux-persist';
import { routerReducer as router } from 'react-router-redux';
import getStoredStateMigrateV4 from 'redux-persist/lib/integration/getStoredStateMigrateV4';
// import autoMergeLevel2 from 'redux-persist/lib/stateReconciler/autoMergeLevel2';
diff --git a/app/reducers/locations.js b/app/reducers/locations.js
index 488ac9264..5997c39d5 100644
--- a/app/reducers/locations.js
+++ b/app/reducers/locations.js
@@ -19,9 +19,7 @@
import uuidv1 from 'uuid';
import { immutablySwapItems } from '../utils/misc';
-import PlatformIO from '../services/platform-io';
import { actions as AppActions } from '../reducers/app';
-import AppConfig from '../config';
export const types = {
ADD_LOCATION: 'APP/ADD_LOCATION',
@@ -61,6 +59,7 @@ export default (state: Array<Location> = initialState, action: Object) => {
case types.ADD_LOCATION: {
if (action.location.isDefault) {
state.forEach(location => {
+ // eslint-disable-next-line no-param-reassign
location.isDefault = false;
});
}
@@ -80,6 +79,7 @@ export default (state: Array<Location> = initialState, action: Object) => {
indexForEditing = index;
}
if (action.location.isDefault) {
+ // eslint-disable-next-line no-param-reassign
location.isDefault = false;
}
});
diff --git a/app/reducers/settings.js b/app/reducers/settings.js
index 2672cbced..cdbb49fa7 100644
--- a/app/reducers/settings.js
+++ b/app/reducers/settings.js
@@ -69,7 +69,7 @@ export const types = {
SET_FIRST_RUN: 'SETTINGS/SET_FIRST_RUN'
};
-export default (state = defaultSettings, action) => {
+export default (state: Object = defaultSettings, action: any) => {
switch (action.type) {
case types.UPGRADE_SETTINGS: {
const mergedKeyBindings = defaultSettings.keyBindings.map(x =>
@@ -239,7 +239,9 @@ export default (state = defaultSettings, action) => {
case types.SET_ZOOM_IN: {
let zoomLevel = state.zoomFactor;
const offSet = 0.1;
- if (zoomLevel.toPrecision(2) <= zoomLevel + offSet * 4) {
+ const correctedOffset = offSet * 4;
+ const threshold = zoomLevel + correctedOffset;
+ if (zoomLevel.toPrecision(2) <= threshold) {
zoomLevel += offSet;
PlatformIO.setZoomFactorElectron(zoomLevel);
}
@@ -416,14 +418,16 @@ export const actions = {
lastPublishedVersion
}),
checkForUpdate: () => (
- dispatch: (actions: Object) => void,
- getState: () => Object
+ dispatch: (actions: Object) => void
+ // getState: () => Object
) => {
- const { settings } = getState();
+ // const { settings } = getState();
getLastVersionPromise()
.then(lastVersion => {
console.log('Last version on server: ' + lastVersion);
+ // $FlowFixMe
const newVersion = semver.coerce(lastVersion); // lastVersion '3.0.5' ;
+ // $FlowFixMe
const currentVersion = semver.coerce(versionMeta.version);
// const lastPublishedVersion = semver.coerce(settings.lastPublishedVersion);
if (semver.valid(newVersion) && semver.gt(newVersion, currentVersion)) {