Skip to content

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

feat: add download multiple files functionality for web

Ilian Sapundshievbb5f65f48f44
diff --git a/src/renderer/components/CommonIcons.tsx b/src/renderer/components/CommonIcons.tsx
index 587f7874b..152303d5d 100644
--- a/src/renderer/components/CommonIcons.tsx
+++ b/src/renderer/components/CommonIcons.tsx
@@ -131,3 +131,5 @@ export { default as StopIcon } from '@mui/icons-material/Stop';
export { default as PauseIcon } from '@mui/icons-material/Pause';
export { default as SaveIcon } from '@mui/icons-material/Save';
+
+export { default as DownloadIcon } from '@mui/icons-material/DownloadForOffline';
diff --git a/src/renderer/components/EntryContainerMenu.tsx b/src/renderer/components/EntryContainerMenu.tsx
index 6a2f8e071..0925411cf 100644
--- a/src/renderer/components/EntryContainerMenu.tsx
+++ b/src/renderer/components/EntryContainerMenu.tsx
@@ -24,11 +24,11 @@ import {
ParentFolderIcon,
ReloadIcon,
CloseIcon,
+ DownloadIcon,
} from '-/components/CommonIcons';
import ExpandIcon from '@mui/icons-material/SettingsEthernet';
import OpenNativelyIcon from '@mui/icons-material/Launch';
import FullScreenIcon from '@mui/icons-material/ZoomOutMap';
-import FileDownloadIcon from '@mui/icons-material/AssignmentReturned';
import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
import MenuKeyBinding from '-/components/menus/MenuKeyBinding';
import {
@@ -215,7 +215,7 @@ function EntryContainerMenu(props: Props) {
onClick={() => downloadFile()}
>
<ListItemIcon>
- <FileDownloadIcon />
+ <DownloadIcon />
</ListItemIcon>
<ListItemText primary={t('core:downloadFile')} />
</MenuItem>,
diff --git a/src/renderer/perspectives/grid/components/MainToolbar.tsx b/src/renderer/perspectives/grid/components/MainToolbar.tsx
index 9fb12f92e..13836078c 100644
--- a/src/renderer/perspectives/grid/components/MainToolbar.tsx
+++ b/src/renderer/perspectives/grid/components/MainToolbar.tsx
@@ -19,13 +19,18 @@
import React from 'react';
import { alpha, useTheme } from '@mui/material/styles';
import { useDispatch, useSelector } from 'react-redux';
+import { saveAs } from 'file-saver';
import { Toolbar, Box, Divider, Badge } from '@mui/material/';
import Tooltip from '-/components/Tooltip';
import IconButton from '@mui/material/IconButton';
import SortingIcon from '@mui/icons-material/SwapVerticalCircle';
import TagIcon from '@mui/icons-material/LocalOffer';
import ShareIcon from '@mui/icons-material/Share';
-import { SelectedIcon, UnSelectedIcon } from '-/components/CommonIcons';
+import {
+ SelectedIcon,
+ UnSelectedIcon,
+ DownloadIcon,
+} from '-/components/CommonIcons';
import CopyIcon from '@mui/icons-material/FileCopy';
import DeleteIcon from '@mui/icons-material/Delete';
import ExportIcon from '@mui/icons-material/AssignmentReturn';
@@ -46,6 +51,7 @@ import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';
import { usePerspectiveSettingsContext } from '-/hooks/usePerspectiveSettingsContext';
+import PlatformIO from '-/services/platform-facade';
interface Props {
prefixDataTID?: string;
@@ -86,6 +92,28 @@ function MainToolbar(props: Props) {
return openEntry(currentDirectoryPath, true);
}
+ function multipleDownload() {
+ selectedEntries?.forEach((entry) => {
+ if (entry.isFile) {
+ const cleanedPath = entry.path.startsWith('/')
+ ? entry.path.substr(1)
+ : entry.path;
+ const url = PlatformIO.getURLforPath(cleanedPath);
+ fetch(url)
+ .then((res) => res.blob()) // Gets the response and returns it as a blob
+ .then((blob) => {
+ saveAs(blob, entry.name);
+ });
+ }
+ });
+ }
+
+ const showDownloadButton =
+ AppConfig.isWeb &&
+ selectedEntries?.length > 0 &&
+ // (PlatformIO.haveObjectStoreSupport() || PlatformIO.haveWebDavSupport()) &&
+ !AppConfig.isCordovaAndroid; // saveAs do not work on Android
+
return (
<Toolbar
style={{
@@ -118,7 +146,6 @@ function MainToolbar(props: Props) {
onClick={() => {
loadParentDirectoryContent();
}}
- // size="large"
>
<ParentFolderIcon />
</IconButton>
@@ -130,7 +157,6 @@ function MainToolbar(props: Props) {
<IconButton
data-tid={prefixDataTID + 'PerspectiveSelectAllFiles'}
onClick={toggleSelectAllFiles}
- // size="large"
>
{selectedEntries.length > 1 ? <SelectedIcon /> : <UnSelectedIcon />}
</IconButton>
@@ -140,7 +166,6 @@ function MainToolbar(props: Props) {
aria-label={t('core:directoryPropertiesTitle')}
data-tid="openFolderProperties"
onClick={showProperties}
- // size="large"
>
<FolderPropertiesIcon />
</IconButton>
@@ -157,7 +182,6 @@ function MainToolbar(props: Props) {
aria-label={t('core:tagSelectedEntries')}
data-tid={prefixDataTID + 'PerspectiveAddRemoveTags'}
onClick={openAddRemoveTagsDialog}
- // size="large"
>
<TagIcon />
</IconButton>
@@ -174,7 +198,6 @@ function MainToolbar(props: Props) {
aria-label={t('core:copyMoveSelectedEntries')}
data-tid={prefixDataTID + 'PerspectiveCopySelectedFiles'}
onClick={openMoveCopyFilesDialog}
- // size="large"
>
<CopyIcon />
</IconButton>
@@ -208,7 +231,6 @@ function MainToolbar(props: Props) {
data-tid={prefixDataTID + 'PerspectiveShareFiles'}
onClick={openShareFilesDialog}
disabled={selectedEntries.length < 1}
- // size="large"
>
<ShareIcon />
</IconButton>
@@ -224,11 +246,20 @@ function MainToolbar(props: Props) {
onClick={(e) => {
handleSortingMenu(e);
}}
- // size="large"
>
<SortingIcon />
</IconButton>
</Tooltip>
+ {showDownloadButton && (
+ <Tooltip title={t('core:downloadFiles')}>
+ <IconButton
+ data-tid={prefixDataTID + 'PerspectiveDownloadMultipleMenuTID'}
+ onClick={multipleDownload}
+ >
+ <DownloadIcon />
+ </IconButton>
+ </Tooltip>
+ )}
{Pro &&
!AppConfig.isCordovaAndroid && ( // SaveAs do not worlk on Android
<Tooltip title={t('core:exportCsv')}>
@@ -236,7 +267,6 @@ function MainToolbar(props: Props) {
data-tid={prefixDataTID + 'PerspectiveExportCsvMenuTID'}
onClick={handleExportCsvMenu}
style={{ transform: 'scale(-1, 1)' }}
- // size="large"
>
<ExportIcon />
</IconButton>
@@ -258,7 +288,6 @@ function MainToolbar(props: Props) {
<IconButton
data-tid={prefixDataTID + 'PerspectiveOptionsMenu'}
onClick={openSettings}
- // size="large"
>
<Badge
color="primary"