Skip to content

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

optimize-MoveOrCopyFilesDialog-and-selected-entries (#2050)

Stanimir55e15b2b5ca6
diff --git a/src/renderer/components/DirectoryListView.tsx b/src/renderer/components/DirectoryListView.tsx
index a2f909493..472ca177c 100644
--- a/src/renderer/components/DirectoryListView.tsx
+++ b/src/renderer/components/DirectoryListView.tsx
@@ -1,27 +1,32 @@
import React, { useRef, useState, useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import Button from '@mui/material/Button';
-import NewFolderIcon from '@mui/icons-material/CreateNewFolder';
import Select from '@mui/material/Select';
import MenuItem from '@mui/material/MenuItem';
+import FormControl from '@mui/material/FormControl';
import List from '@mui/material/List';
import ListItemText from '@mui/material/ListItemText';
import ListItem from '@mui/material/ListItem';
import ListItemIcon from '@mui/material/ListItemIcon';
-import FolderIcon from '@mui/icons-material/FolderOpen';
import { locationType } from '@tagspaces/tagspaces-common/misc';
import { extractContainingDirectoryPath } from '@tagspaces/tagspaces-common/paths';
import { getShowUnixHiddenEntries } from '-/reducers/settings';
import AppConfig from '-/AppConfig';
import { TS } from '-/tagspaces.namespace';
import { actions as AppActions, AppDispatch } from '-/reducers/app';
-import { ParentFolderIcon } from '-/components/CommonIcons';
+import {
+ ParentFolderIcon,
+ NewFolderIcon,
+ FolderOutlineIcon as FolderIcon,
+} from '-/components/CommonIcons';
import { getLocations } from '-/reducers/locations';
import PlatformIO from '-/services/platform-facade';
import { useTranslation } from 'react-i18next';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
import { useLocationIndexContext } from '-/hooks/useLocationIndexContext';
import { useFSWatcherContext } from '-/hooks/useFSWatcherContext';
+import i18n from '-/services/i18n';
+import Typography from '@mui/material/Typography';
interface Props {
setTargetDir: (dirPath: string) => void;
@@ -77,19 +82,32 @@ function DirectoryListView(props: Props) {
return null;
}
return (
- <Select
- onChange={handleLocationChange}
+ <FormControl
fullWidth
- value={chosenLocationId.current}
+ variant="standard"
+ style={{
+ flexFlow: 'nowrap',
+ alignItems: 'center',
+ }}
>
- {locations
- .filter((loc) => loc.type === locationType.TYPE_LOCAL)
- .map((location: TS.Location) => (
- <MenuItem key={location.uuid} value={location.uuid}>
- <span style={{ width: '100%' }}>{location.name}</span>
- </MenuItem>
- ))}
- </Select>
+ <Typography style={{ display: 'inline' }} variant="subtitle2">
+ {t('location')}:&nbsp;
+ </Typography>
+ <Select
+ fullWidth
+ style={{ display: 'inline' }}
+ onChange={handleLocationChange}
+ value={chosenLocationId.current}
+ >
+ {locations
+ .filter((loc) => loc.type === locationType.TYPE_LOCAL)
+ .map((location: TS.Location) => (
+ <MenuItem key={location.uuid} value={location.uuid}>
+ <span style={{ width: '100%' }}>{location.name}</span>
+ </MenuItem>
+ ))}
+ </Select>
+ </FormControl>
);
}
@@ -194,6 +212,7 @@ function DirectoryListView(props: Props) {
dense
style={{
borderRadius: 5,
+ border: '1px solid gray',
maxHeight: 300,
overflowY: 'auto',
}}
diff --git a/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx b/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx
index 732ab8afd..c94163fb0 100644
--- a/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx
+++ b/src/renderer/components/dialogs/MoveCopyFilesDialog.tsx
@@ -3,6 +3,7 @@ import { useDispatch, useSelector } from 'react-redux';
import { formatBytes } from '@tagspaces/tagspaces-common/misc';
import Paper from '@mui/material/Paper';
import Button from '@mui/material/Button';
+import Box from '@mui/material/Box';
import List from '@mui/material/List';
import ListItem from '@mui/material/ListItem';
import ListItemIcon from '@mui/material/ListItemIcon';
@@ -53,24 +54,28 @@ function MoveCopyFilesDialog(props: Props) {
const [entriesExistPath, setEntriesExistPath] = useState<string[]>(undefined);
const dirProp = useRef({});
- const [ignored, forceUpdate] = useReducer((x) => x + 1, 0);
+ const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
const { open, entries, onClose } = props;
- let allEntries = entries && entries.length > 0 ? entries : selectedEntries;
+ const allEntries = useRef<TS.FileSystemEntry[]>(
+ entries && entries.length > 0 ? entries : selectedEntries,
+ );
- const selectedFiles = allEntries
- ? allEntries
+ const selectedFiles = allEntries.current
+ ? allEntries.current
.filter((fsEntry) => fsEntry.isFile)
.map((fsentry) => fsentry.path)
: [];
- const selectedDirs = allEntries
- ? allEntries
+ const selectedDirs = allEntries.current
+ ? allEntries.current
.filter((fsEntry) => !fsEntry.isFile)
.map((fsentry) => fsentry.path)
: [];
useEffect(() => {
+ allEntries.current =
+ entries && entries.length > 0 ? entries : selectedEntries;
// getDirProperties have Electron impl only
if (
selectedDirs.length > 0 &&
@@ -217,12 +222,10 @@ function MoveCopyFilesDialog(props: Props) {
overflowY: 'auto',
width: 550,
maxHeight: 200,
- marginLeft: -15,
- marginBottom: 20,
}}
>
- {allEntries.length > 0 &&
- allEntries.map((entry) => (
+ {allEntries.current.length > 0 &&
+ allEntries.current.map((entry) => (
<ListItem title={entry.path} key={entry.path}>
<ListItemIcon>
{entry.isFile ? <FileIcon /> : <FolderIcon />}
@@ -239,19 +242,21 @@ function MoveCopyFilesDialog(props: Props) {
</ListItem>
))}
</List>
- {targetPath ? (
- <Typography variant="subtitle2">
- {t('moveCopyToPath') + ': ' + targetPath}
- </Typography>
- ) : (
- <Typography variant="subtitle2">
- {t('chooseTargetLocationAndPath')}
- </Typography>
- )}
<DirectoryListView
setTargetDir={setTargetPath}
currentDirectoryPath={currentDirectoryPath}
/>
+ <Box style={{ marginTop: 10 }}>
+ {targetPath ? (
+ <Typography variant="subtitle2">
+ {t('moveCopyToPath') + ': ' + targetPath}
+ </Typography>
+ ) : (
+ <Typography variant="subtitle2">
+ {t('chooseTargetLocationAndPath')}
+ </Typography>
+ )}
+ </Box>
</DialogContent>
<DialogActions
style={fullScreen ? { padding: '10px 30px 30px 30px' } : {}}
diff --git a/src/renderer/components/dialogs/MoveOrCopyFilesDialog.tsx b/src/renderer/components/dialogs/MoveOrCopyFilesDialog.tsx
index 863fb1e17..e4714efa7 100644
--- a/src/renderer/components/dialogs/MoveOrCopyFilesDialog.tsx
+++ b/src/renderer/components/dialogs/MoveOrCopyFilesDialog.tsx
@@ -48,7 +48,7 @@ interface Props {
}
function MoveOrCopyFilesDialog(props: Props) {
- const { open, onClose } = props;
+ const { open, onClose, selectedFiles } = props;
const { t } = useTranslation();
const theme = useTheme();
@@ -57,45 +57,6 @@ function MoveOrCopyFilesDialog(props: Props) {
const { currentDirectoryPath } = useDirectoryContentContext();
const fullScreen = useMediaQuery(theme.breakpoints.down('md'));
- /*
- const handleMoveCopyFiles = (files: Array<any>, move = false) => {
- const promises = [];
- for (const file of files) {
- if (move) {
- promises.push(
- renameFilePromise(
- file.path,
- cleanTrailingDirSeparator(currentDirectoryPath) +
- AppConfig.dirSeparator +
- file.name,
- )
- .then(() => true)
- .catch((error) => {
- console.log('renameFilePromise', error);
- }),
- );
- } else {
- promises.push(
- copyFilePromise(
- file.path,
- cleanTrailingDirSeparator(currentDirectoryPath) +
- AppConfig.dirSeparator +
- file.name,
- )
- .then(() => true)
- .catch((error) => {
- console.log('copyFilePromise', error);
- }),
- );
- }
- }
- Promise.all(promises)
- .then(() => openDirectory(currentDirectoryPath))
- .catch((error) => {
- console.log('promises', error);
- });
- }; */
-
return (
<Dialog
open={open}
@@ -121,9 +82,9 @@ function MoveOrCopyFilesDialog(props: Props) {
>
<Typography variant="subtitle2">{t('selectedFiles')}</Typography>
<List dense style={{ width: 550, marginLeft: -15 }}>
- {props.selectedFiles &&
- props.selectedFiles.length > 0 &&
- props.selectedFiles.map((file) => (
+ {selectedFiles &&
+ selectedFiles.length > 0 &&
+ selectedFiles.map((file) => (
<ListItem title={file.path} key={file.path}>
<ListItemIcon>
<FileIcon />
@@ -138,21 +99,18 @@ function MoveOrCopyFilesDialog(props: Props) {
<DialogActions
style={fullScreen ? { padding: '10px 30px 30px 30px' } : {}}
>
- <Button
- data-tid="closeMoveOrCopyDialog"
- onClick={() => props.onClose()}
- >
+ <Button data-tid="closeMoveOrCopyDialog" onClick={() => onClose()}>
{t('core:cancel')}
</Button>
<Button
onClick={() => {
- if (props.selectedFiles) {
+ if (selectedFiles) {
moveFiles(
- props.selectedFiles.map((file) => file.path),
+ selectedFiles.map((file) => file.path),
currentDirectoryPath,
);
}
- props.onClose();
+ onClose();
}}
data-tid="confirmMoveFilesTID"
color="primary"
@@ -162,13 +120,13 @@ function MoveOrCopyFilesDialog(props: Props) {
</Button>
<Button
onClick={() => {
- if (props.selectedFiles) {
+ if (selectedFiles) {
copyFiles(
- props.selectedFiles.map((file) => file.path),
+ selectedFiles.map((file) => file.path),
currentDirectoryPath,
);
}
- props.onClose();
+ onClose();
}}
data-tid="confirmCopyFilesTID"
color="primary"
diff --git a/src/renderer/content/ProTeaserSlides.tsx b/src/renderer/content/ProTeaserSlides.tsx
index 565c70509..5676dc1b2 100644
--- a/src/renderer/content/ProTeaserSlides.tsx
+++ b/src/renderer/content/ProTeaserSlides.tsx
@@ -79,7 +79,19 @@ export function getProTeaserSlides(t) {
title: 'TagSpaces Pro - FolderViz Perspective',
description: (
<>
- <p>FolderViz is still in development and has a preview status</p>
+ <p>
+ FolderViz represent the structure of the current folder as a tree.
+ Currently it supports the following views:
+ </p>
+ <ul>
+ <li>Horizontal Tree</li>
+ <li>Radial Tree</li>
+ <li>Treemap</li>
+ </ul>
+ <small>
+ <b>Note:</b> This perspective is still in development and has a
+ preview status.
+ </small>
</>
),
ctaURL: Links.documentationLinks.foldervizPerspective,
diff --git a/src/renderer/hooks/OpenedEntryContextProvider.tsx b/src/renderer/hooks/OpenedEntryContextProvider.tsx
index c88802e1c..0ccd71622 100644
--- a/src/renderer/hooks/OpenedEntryContextProvider.tsx
+++ b/src/renderer/hooks/OpenedEntryContextProvider.tsx
@@ -198,8 +198,7 @@ export const OpenedEntryContextProvider = ({
if (actions && actions.length > 0) {
for (const action of actions) {
if (action.action === 'add') {
- if (action.open) {
- //action.entry.isFile && action.entry.isNewFile) {
+ if (action.open && action.entry.isFile && action.entry.isNewFile) {
openFsEntry(action.entry, true);
}
} else if (action.action === 'delete') {
diff --git a/src/renderer/hooks/SelectedEntryContextProvider.tsx b/src/renderer/hooks/SelectedEntryContextProvider.tsx
index c754b901e..6fead7f9f 100644
--- a/src/renderer/hooks/SelectedEntryContextProvider.tsx
+++ b/src/renderer/hooks/SelectedEntryContextProvider.tsx
@@ -66,12 +66,7 @@ export const SelectedEntryContextProvider = ({
let selected = [...selectedEntries.current];
for (const action of actions) {
if (action.action === 'add') {
- if (action.entry.isFile) {
- selected.push(action.entry);
- } /*else if (selectedEntries.current.length === 0) {
- //todo tmp fix don't change selection if copy dialog with selected entry is opened
- selected.push(action.entry);
- }*/
+ selected.push(action.entry);
} else if (action.action === 'delete') {
let index = selectedEntries.current.findIndex(
(e) => e.path === action.entry.path,