Skip to content

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

Refactor to use useDispatch and useSelector (#1954)

Stanimiraf7a1eb84735
diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml
index 63508d928..cee39f59b 100644
--- a/.github/workflows/pull_request.yml
+++ b/.github/workflows/pull_request.yml
@@ -78,7 +78,7 @@ jobs:
- name: Checkout TagspacesPro
uses: actions/checkout@v2
with:
- ref: develop
+ ref: Refactor-to-use-useDispatch-and-useSelector-v2
repository: tagspaces/tagspacespro
token: ${{ secrets.CHECKOUT_TSPRO }}
path: extensions/tagspacespro
diff --git a/app/app.global.css b/app/app.global.css
index 9dbdc3f56..530405558 100644
--- a/app/app.global.css
+++ b/app/app.global.css
@@ -8,7 +8,6 @@
@import '~react-image-gallery/styles/css/image-gallery.css';
@import '~@tagspaces/tagspaces-md/lib/milkdown.css';
-
/* Needed to disable border on focused HotKey element */
div[tabindex='-1']:focus {
outline: 0;
diff --git a/app/components/DirectoryListView.tsx b/app/components/DirectoryListView.tsx
index 5a7132148..dcb86176e 100644
--- a/app/components/DirectoryListView.tsx
+++ b/app/components/DirectoryListView.tsx
@@ -1,6 +1,5 @@
import React, { useRef, useState, useEffect } from 'react';
-import { connect } from 'react-redux';
-import { bindActionCreators } from 'redux';
+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';
@@ -16,7 +15,11 @@ import { getShowUnixHiddenEntries } from '-/reducers/settings';
import AppConfig from '-/AppConfig';
import i18n from '-/services/i18n';
import { TS } from '-/tagspaces.namespace';
-import { actions as AppActions, getCurrentLocationId } from '-/reducers/app';
+import {
+ actions as AppActions,
+ AppDispatch,
+ getCurrentLocationId
+} from '-/reducers/app';
import { ParentFolderIcon } from '-/components/CommonIcons';
import { getLocations } from '-/reducers/locations';
import PlatformIO from '-/services/platform-facade';
@@ -24,20 +27,13 @@ import { Pro } from '-/pro';
interface Props {
setTargetDir: (dirPath: string) => void;
- locations: Array<TS.Location>;
- currentLocationId: string;
- toggleCreateDirectoryDialog: (props: any) => void;
- showUnixHiddenEntries: boolean;
currentDirectoryPath?: string;
- watchForChanges: () => void;
}
function DirectoryListView(props: Props) {
- const {
- locations,
- currentLocationId,
- showUnixHiddenEntries,
- currentDirectoryPath
- } = props;
+ const { currentDirectoryPath, setTargetDir } = props;
+ const locations: Array<TS.Location> = useSelector(getLocations);
+ const currentLocationId: string = useSelector(getCurrentLocationId);
+ const showUnixHiddenEntries: boolean = useSelector(getShowUnixHiddenEntries);
const chosenLocationId = useRef<string>(currentLocationId);
const chosenDirectory = useRef<string>(currentDirectoryPath);
const [directoryContent, setDirectoryContent] = useState<
@@ -57,6 +53,8 @@ function DirectoryListView(props: Props) {
}
}, [chosenLocationId.current]);
+ const dispatch: AppDispatch = useDispatch();
+
const handleLocationChange = (event: React.ChangeEvent<HTMLInputElement>) => {
chosenLocationId.current = event.target.value;
const chosenLocation = locations.find(
@@ -64,11 +62,11 @@ function DirectoryListView(props: Props) {
);
if (chosenLocation) {
listDirectory(chosenLocation.path);
- props.setTargetDir(chosenLocation.path);
+ setTargetDir(chosenLocation.path);
}
};
- function getLocations() {
+ function getDirLocations() {
const currentLocation = locations.find(
location => location.uuid === chosenLocationId.current
);
@@ -129,7 +127,7 @@ function DirectoryListView(props: Props) {
data-tid={'MoveTarget' + entry.name}
title={'Navigate to: ' + entry.path}
onClick={() => {
- props.setTargetDir(entry.path);
+ setTargetDir(entry.path);
}}
onDoubleClick={() => {
listDirectory(entry.path);
@@ -149,7 +147,7 @@ function DirectoryListView(props: Props) {
return (
<div style={{ marginTop: 10 }}>
- {getLocations()}
+ {getDirLocations()}
<Button
variant="text"
startIcon={<ParentFolderIcon />}
@@ -163,7 +161,7 @@ function DirectoryListView(props: Props) {
}
const parentDir = extractContainingDirectoryPath(currentPath);
listDirectory(parentDir);
- props.setTargetDir(parentDir);
+ setTargetDir(parentDir);
}
}}
>
@@ -178,15 +176,17 @@ function DirectoryListView(props: Props) {
if (Pro && Pro.Watcher) {
Pro.Watcher.stopWatching();
}
- props.toggleCreateDirectoryDialog({
- rootDirPath: chosenDirectory.current,
- callback: newDirPath => {
- listDirectory(chosenDirectory.current);
- props.setTargetDir(newDirPath);
- props.watchForChanges();
- },
- reflect: false
- });
+ dispatch(
+ AppActions.toggleCreateDirectoryDialog({
+ rootDirPath: chosenDirectory.current,
+ callback: newDirPath => {
+ listDirectory(chosenDirectory.current);
+ setTargetDir(newDirPath);
+ dispatch(AppActions.watchForChanges());
+ },
+ reflect: false
+ })
+ );
}}
>
{i18n.t('core:newSubdirectory')}
@@ -205,25 +205,4 @@ function DirectoryListView(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- locations: getLocations(state),
- currentLocationId: getCurrentLocationId(state),
- showUnixHiddenEntries: getShowUnixHiddenEntries(state)
- };
-}
-
-function mapActionCreatorsToProps(dispatch) {
- return bindActionCreators(
- {
- toggleCreateDirectoryDialog: AppActions.toggleCreateDirectoryDialog,
- watchForChanges: AppActions.watchForChanges
- },
- dispatch
- );
-}
-
-export default connect(
- mapStateToProps,
- mapActionCreatorsToProps
-)(DirectoryListView);
+export default DirectoryListView;
diff --git a/app/components/DirectoryTreeView.tsx b/app/components/DirectoryTreeView.tsx
index 1a1a7b320..a38b45bec 100644
--- a/app/components/DirectoryTreeView.tsx
+++ b/app/components/DirectoryTreeView.tsx
@@ -17,6 +17,7 @@
*/
import React, { useState, forwardRef, useImperativeHandle, Ref } from 'react';
+import { useDispatch, useSelector } from 'react-redux';
import Table from 'rc-table';
import FolderIcon from '@mui/icons-material/FolderOpen';
import { locationType } from '@tagspaces/tagspaces-common/misc';
@@ -25,25 +26,14 @@ import DragItemTypes from '-/components/DragItemTypes';
import PlatformIO from '-/services/platform-facade';
import TargetTableMoveFileBox from '-/components/TargetTableMoveFileBox';
import { TS } from '-/tagspaces.namespace';
+import { actions as AppActions, AppDispatch } from '-/reducers/app';
+import { getShowUnixHiddenEntries } from '-/reducers/settings';
interface Props {
classes: any;
- loadDirectoryContent: (
- path: string,
- generateThumbnails: boolean,
- loadDirMeta?: boolean
- ) => void;
location: TS.Location;
- data?: any;
- isReadOnlyMode?: boolean;
- showUnixHiddenEntries: boolean;
- showNotification?: (
- text: string,
- notificationType: string,
- autohide: boolean
- ) => void;
+ //data?: any;
handleFileMoveDrop: (item, monitor) => void;
- changeLocation: (loc: TS.Location) => void;
}
export interface DirectoryTreeViewRef {
@@ -54,8 +44,11 @@ export interface DirectoryTreeViewRef {
const DirectoryTreeView = forwardRef(
(props: Props, ref: Ref<DirectoryTreeViewRef>) => {
+ const { classes, location, handleFileMoveDrop } = props;
const [data, setData] = useState(undefined);
const [isExpanded, setExpanded] = useState(false);
+ const showUnixHiddenEntries = useSelector(getShowUnixHiddenEntries);
+ const dispatch: AppDispatch = useDispatch();
useImperativeHandle(ref, () => ({
changeLocation(location: TS.Location) {
@@ -109,16 +102,13 @@ const DirectoryTreeView = forwardRef(
); */
const renderBodyRow = props => {
- if (
- AppConfig.isElectron ||
- props.location.type !== locationType.TYPE_CLOUD
- ) {
+ if (AppConfig.isElectron || location.type !== locationType.TYPE_CLOUD) {
// DnD to S3 location is not permitted in web browser without <input> element
return (
<TargetTableMoveFileBox
accepts={[DragItemTypes.FILE]}
- onDrop={props.handleFileMoveDrop}
- location={props.location}
+ onDrop={handleFileMoveDrop}
+ location={location}
{...props}
/>
);
@@ -136,7 +126,7 @@ const DirectoryTreeView = forwardRef(
marginRight: 6,
marginBottom: -8
}}
- className={props.classes.icon}
+ className={classes.icon}
/>
{field && field.length > 25 ? field.substr(0, 25) + '...' : field}
</span>
@@ -172,8 +162,8 @@ const DirectoryTreeView = forwardRef(
PlatformIO.enableObjectStoreSupport(subDir)
.then(() => {
loadSubDirectories(subDir);
- props.changeLocation(subDir);
- props.loadDirectoryContent(subDir.path, true, true);
+ dispatch(AppActions.changeLocation(subDir));
+ dispatch(AppActions.loadDirectoryContent(subDir.path, true, true));
return true;
})
.catch(error => {
@@ -182,8 +172,8 @@ const DirectoryTreeView = forwardRef(
} else if (subDir.type === locationType.TYPE_LOCAL) {
PlatformIO.disableObjectStoreSupport();
loadSubDirectories(subDir);
- props.changeLocation(subDir);
- props.loadDirectoryContent(subDir.path, true, true);
+ dispatch(AppActions.changeLocation(subDir));
+ dispatch(AppActions.loadDirectoryContent(subDir.path, true, true));
}
};
@@ -269,7 +259,7 @@ const DirectoryTreeView = forwardRef(
if (
entry.name === AppConfig.metaFolder ||
entry.name.endsWith('/' + AppConfig.metaFolder) ||
- (!props.showUnixHiddenEntries && entry.name.startsWith('.'))
+ (!showUnixHiddenEntries && entry.name.startsWith('.'))
) {
return true;
}
@@ -388,7 +378,7 @@ const DirectoryTreeView = forwardRef(
if (isExpanded && data != undefined) {
return (
<Table
- key={props.location.uuid}
+ key={location.uuid}
// defaultExpandAllRows
// className={classes.locationListArea}
components={{
@@ -398,7 +388,7 @@ const DirectoryTreeView = forwardRef(
showHeader={false}
// className="table"
rowKey="path"
- data={data[props.location.uuid]}
+ data={data[location.uuid]}
columns={columns}
indentSize={20}
expandable={{ onExpand }}
@@ -408,7 +398,7 @@ const DirectoryTreeView = forwardRef(
onRow={(record, index) => ({
index,
location: record,
- handleFileMoveDrop: props.handleFileMoveDrop
+ handleFileMoveDrop: handleFileMoveDrop
})}
/>
);
diff --git a/app/components/EntryContainer.tsx b/app/components/EntryContainer.tsx
index d17abaa9f..2ed56a61c 100644
--- a/app/components/EntryContainer.tsx
+++ b/app/components/EntryContainer.tsx
@@ -1689,7 +1689,6 @@ function EntryContainer(props: Props) {
<AddRemoveTagsDialog
open={isEditTagsModalOpened}
onClose={() => setEditTagsModalOpened(false)}
- addTags={addTags}
removeTags={removeTags}
removeAllTags={removeAllTags}
selectedEntries={openedFile ? [openedFile] : []}
diff --git a/app/components/FolderContainer.tsx b/app/components/FolderContainer.tsx
index aed45804d..6376b7622 100644
--- a/app/components/FolderContainer.tsx
+++ b/app/components/FolderContainer.tsx
@@ -210,7 +210,6 @@ interface Props {
setSearchQuery: (searchQuery: TS.SearchQuery) => void;
enterSearchMode: () => void;
exitSearchMode: () => void;
- openURLExternally?: (url: string, skipConfirmation: boolean) => void;
language: string;
// editedEntryPaths: Array<TS.EditedEntryPath>;
goBack: () => void;
@@ -714,8 +713,7 @@ function mapActionCreatorsToProps(dispatch) {
setCurrentDirectoryColor: AppActions.setCurrentDirectoryColor,
enterSearchMode: AppActions.enterSearchMode,
exitSearchMode: AppActions.exitSearchMode,
- setSearchQuery: LocationIndexActions.setSearchQuery,
- openURLExternally: AppActions.openURLExternally
+ setSearchQuery: LocationIndexActions.setSearchQuery
},
dispatch
);
diff --git a/app/components/HelpFeedbackPanel.tsx b/app/components/HelpFeedbackPanel.tsx
index b8bb8508f..484f8b7e4 100644
--- a/app/components/HelpFeedbackPanel.tsx
+++ b/app/components/HelpFeedbackPanel.tsx
@@ -17,6 +17,7 @@
*/
import React from 'react';
+import { useSelector } from 'react-redux';
import withStyles from '@mui/styles/withStyles';
import classNames from 'classnames';
import Typography from '@mui/material/Typography';
@@ -42,12 +43,12 @@ import i18n from '-/services/i18n';
import { KeyShortcutsIcon, HelpIcon } from '-/components/CommonIcons';
import Links from '-/content/links';
import { Pro } from '-/pro';
+import { openURLExternally } from '-/services/utils-io';
+import { getCurrentLanguage } from '-/reducers/settings';
interface Props {
classes?: any;
theme?: any;
- language: string;
- openURLExternally: (url: string, skipConfirmation?: boolean) => void;
toggleAboutDialog?: () => void;
toggleKeysDialog: () => void;
toggleOnboardingDialog: () => void;
@@ -57,9 +58,9 @@ interface Props {
}
function HelpFeedbackPanel(props: Props) {
+ const language = useSelector(getCurrentLanguage);
const {
classes,
- openURLExternally,
toggleAboutDialog,
toggleKeysDialog,
toggleOnboardingDialog,
diff --git a/app/components/HowToStart.tsx b/app/components/HowToStart.tsx
index 3b8869e7c..58e79f6b2 100644
--- a/app/components/HowToStart.tsx
+++ b/app/components/HowToStart.tsx
@@ -11,6 +11,7 @@ import Typography from '@mui/material/Typography';
import i18n from '-/services/i18n';
import Links from '-/content/links';
import { ProSign } from '-/components/HelperComponents';
+import { openURLExternally } from '-/services/utils-io';
export const styles: any = (theme: any) => ({
recentTitle: {
@@ -41,11 +42,10 @@ function clearHighlights() {
interface Props {
theme: any;
classes: any;
- openURLExternally: (url: string, skipConfirmation?: boolean) => void;
}
function HowToStart(props: Props) {
- const { classes, openURLExternally, theme } = props;
+ const { classes, theme } = props;
const steps = [
{
label: 'Introduction',
diff --git a/app/components/LocationManager.tsx b/app/components/LocationManager.tsx
index 9583cade0..57b6cc484 100644
--- a/app/components/LocationManager.tsx
+++ b/app/components/LocationManager.tsx
@@ -17,22 +17,16 @@
*/
import React, { useEffect, useRef, useState } from 'react';
-import { bindActionCreators } from 'redux';
-import { connect } from 'react-redux';
+import { useDispatch, useSelector } from 'react-redux';
import withStyles from '@mui/styles/withStyles';
import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
import { List } from '@mui/material';
-import AppConfig from '-/AppConfig';
import styles from '-/components/SidePanels.css';
import LocationManagerMenu from '-/components/menus/LocationManagerMenu';
import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
import { actions as LocationActions, getLocations } from '-/reducers/locations';
-import { actions as AppActions, isLoading } from '-/reducers/app';
-import {
- getCurrentLanguage,
- getPersistTagsInSidecarFile,
- isDesktopMode
-} from '-/reducers/settings';
+import { actions as AppActions, AppDispatch, isLoading } from '-/reducers/app';
+import { getCurrentLanguage } from '-/reducers/settings';
import i18n from '-/services/i18n';
import LoadingLazy from '-/components/LoadingLazy';
import LocationView from '-/components/LocationView';
@@ -56,20 +50,7 @@ function CreateEditLocationDialogAsync(props) {
interface Props {
classes?: any;
style?: any;
- locations: Array<TS.Location>;
- hideDrawer?: () => void;
- openURLExternally: (path: string) => void;
- toggleOpenLinkDialog: () => void;
- setDefaultLocations: () => void;
- addLocations: (locations: Array<TS.Location>) => void;
- editLocation: () => void;
- removeLocation: (location: TS.Location) => void;
- moveLocation: (uuid: string, position: number) => void;
- isDesktop: boolean;
- isPersistTagsInSidecar: boolean;
reduceHeightBy: number;
- toggleLocationDialog: () => void;
- isLoading: boolean;
show: boolean;
}
@@ -81,6 +62,10 @@ type SubFolder = {
};
function LocationManager(props: Props) {
+ const dispatch: AppDispatch = useDispatch();
+ const locations: Array<TS.Location> = useSelector(getLocations);
+ const loading: boolean = useSelector(isLoading);
+ //const language: string = useSelector(getCurrentLanguage);
const fileInputRef = useRef<HTMLInputElement>(null);
const [selectedLocation, setSelectedLocation] = useState<TS.Location>(null);
const [isEditLocationDialogOpened, setEditLocationDialogOpened] = useState<
@@ -103,11 +88,11 @@ function LocationManager(props: Props) {
Pro && Pro.UI ? Pro.UI.ImportLocationsDialog : false;
useEffect(() => {
- if (props.locations.length < 1) {
+ if (locations.length < 1) {
// init locations
- props.setDefaultLocations();
+ dispatch(LocationActions.setDefaultLocations());
}
- }, []); // props.locations]);
+ }, [locations]);
function handleFileInputChange(selection: any) {
const target = selection.currentTarget;
@@ -122,10 +107,12 @@ function LocationManager(props: Props) {
return;
}
- props.moveLocation(result.draggableId, result.destination.index);
+ dispatch(
+ LocationActions.moveLocation(result.draggableId, result.destination.index)
+ );
};
- const { classes, reduceHeightBy, isLoading, show } = props;
+ const { classes, reduceHeightBy, show } = props;
return (
<div
className={classes.panel}
@@ -134,7 +121,7 @@ function LocationManager(props: Props) {
flexDirection: 'column'
}}
>
- {isLoading &&
+ {loading &&
(PlatformIO.haveObjectStoreSupport() ||
PlatformIO.haveWebDavSupport()) && (
<>
@@ -170,9 +157,10 @@ function LocationManager(props: Props) {
// importLocations={() => setImportLocationsDialogOpened(true)}
exportLocations={() => setExportLocationsDialogOpened(true)}
classes={classes}
- openURLExternally={props.openURLExternally}
- showCreateLocationDialog={props.toggleLocationDialog}
- toggleOpenLinkDialog={props.toggleOpenLinkDialog}
+ showCreateLocationDialog={() =>
+ dispatch(AppActions.toggleLocationDialog())
+ }
+ toggleOpenLinkDialog={() => dispatch(AppActions.toggleOpenLinkDialog())}
/>
<List
className={classes.locationListArea}
@@ -191,7 +179,7 @@ function LocationManager(props: Props) {
ref={provided.innerRef}
/* style={getListStyle(snapshot.isDraggingOver)} */
>
- {props.locations.map((location, index) => (
+ {locations.map((location, index) => (
<Draggable
key={location.uuid}
draggableId={location.uuid}
@@ -209,9 +197,8 @@ function LocationManager(props: Props) {
>
<LocationView
key={location.uuid}
- classes={props.classes}
+ classes={classes}
location={location}
- hideDrawer={props.hideDrawer}
setEditLocationDialogOpened={
setEditLocationDialogOpened
}
@@ -243,8 +230,9 @@ function LocationManager(props: Props) {
open={isEditLocationDialogOpened}
onClose={() => setEditLocationDialogOpened(false)}
location={selectedLocation}
- editLocation={props.editLocation}
- isPersistTagsInSidecar={props.isPersistTagsInSidecar}
+ editLocation={location =>
+ dispatch(LocationActions.editLocation(location))
+ }
/>
)}
{isDeleteLocationDialogOpened && (
@@ -257,7 +245,7 @@ function LocationManager(props: Props) {
})}
confirmCallback={result => {
if (result && selectedLocation) {
- props.removeLocation(selectedLocation);
+ dispatch(LocationActions.removeLocation(selectedLocation));
}
}}
cancelDialogTID="cancelDeleteLocationDialog"
@@ -268,9 +256,7 @@ function LocationManager(props: Props) {
<ExportLocationsDialog
open={isExportLocationsDialogOpened}
onClose={() => setExportLocationsDialogOpened(false)}
- locations={props.locations.filter(
- location => !location.isNotEditable
- )}
+ locations={locations.filter(location => !location.isNotEditable)}
/>
)}
{ImportLocationsDialog && importFile && (
@@ -278,42 +264,12 @@ function LocationManager(props: Props) {
open={Boolean(importFile)}
onClose={() => setImportFile(undefined)}
importFile={importFile}
- addLocations={props.addLocations}
- locations={props.locations}
+ addLocations={loc => dispatch(LocationActions.addLocations(loc))}
+ locations={locations}
/>
)}
</div>
);
}
-function mapStateToProps(state) {
- return {
- locations: getLocations(state),
- isDesktop: isDesktopMode(state),
- isLoading: isLoading(state),
- isPersistTagsInSidecar: getPersistTagsInSidecarFile(state),
- language: getCurrentLanguage(state)
- };
-}
-
-function mapDispatchToProps(dispatch) {
- return bindActionCreators(
- {
- setDefaultLocations: LocationActions.setDefaultLocations,
- addLocations: LocationActions.addLocations,
- editLocation: LocationActions.editLocation,
- removeLocation: LocationActions.removeLocation,
- moveLocation: LocationActions.moveLocation,
- toggleOpenLinkDialog: AppActions.toggleOpenLinkDialog,
- openURLExternally: AppActions.openURLExternally,
- toggleLocationDialog: AppActions.toggleLocationDialog
- },
- dispatch
- );
-}
-
-export default connect(
- mapStateToProps,
- mapDispatchToProps
- // @ts-ignore
-)(withStyles(styles)(LocationManager));
+export default withStyles(styles)(LocationManager);
diff --git a/app/components/LocationView.tsx b/app/components/LocationView.tsx
index 9c23c340d..ee94d87a6 100644
--- a/app/components/LocationView.tsx
+++ b/app/components/LocationView.tsx
@@ -17,8 +17,7 @@
*/
import React, { useRef, useState } from 'react';
-import { bindActionCreators } from 'redux';
-import { connect } from 'react-redux';
+import { useDispatch, useSelector } from 'react-redux';
import withStyles from '@mui/styles/withStyles';
import Tooltip from '-/components/Tooltip';
import ListItem from '@mui/material/ListItem';
@@ -29,12 +28,12 @@ import Typography from '@mui/material/Typography';
import IconButton from '@mui/material/IconButton';
import { LocalLocationIcon, CloudLocationIcon } from '-/components/CommonIcons';
import DefaultLocationIcon from '@mui/icons-material/Highlight';
-import { Progress } from 'aws-sdk/clients/s3';
import { locationType } from '@tagspaces/tagspaces-common/misc';
import AppConfig from '-/AppConfig';
import styles from './SidePanels.css';
import {
actions as AppActions,
+ AppDispatch,
getCurrentLocationId,
isReadOnlyMode
} from '../reducers/app';
@@ -56,38 +55,11 @@ import { TS } from '-/tagspaces.namespace';
interface Props {
classes: any;
location: TS.Location;
- currentLocationId: string;
- openLocation: (location: TS.Location) => void;
- loadDirectoryContent: (
- path: string,
- generateThumbnails: boolean,
- loadDirMeta?: boolean
- ) => void;
- setSelectedEntries: (selectedEntries: Array<Object>) => void;
- hideDrawer: () => void;
- isReadOnlyMode: boolean;
- showNotification: (
- text: string,
- notificationType: string,
- autohide: boolean
- ) => void;
- resetProgress: () => void;
- uploadFiles: (
- files: Array<string>,
- destination: string,
- onUploadProgress?: (progress: Progress, response: any) => void
- ) => Promise<Array<TS.FileSystemEntry>>;
- onUploadProgress: (progress: Progress, response: any) => void;
- reflectCreateEntries: (fsEntries: Array<TS.FileSystemEntry>) => void;
- toggleUploadDialog: () => void;
- moveFiles: (files: Array<string>, destination: string) => void;
- showUnixHiddenEntries: boolean;
+ hideDrawer?: () => void;
setEditLocationDialogOpened: (open: boolean) => void;
setDeleteLocationDialogOpened: (open: boolean) => void;
selectedLocation: TS.Location;
setSelectedLocation: (loc: TS.Location) => void;
- changeLocation: (loc: TS.Location) => void;
- exitSearchMode: () => void;
}
function LocationView(props: Props) {
@@ -97,10 +69,25 @@ function LocationView(props: Props) {
setLocationDirectoryContextMenuAnchorEl
] = useState<null | HTMLElement>(null);
- const { location } = props;
+ const dispatch: AppDispatch = useDispatch();
+ const language = useSelector(getCurrentLanguage);
+ const currentLocationId: string = useSelector(getCurrentLocationId);
+ const readOnlyMode = useSelector(isReadOnlyMode);
+
+ const {
+ classes,
+ location,
+ hideDrawer,
+ setSelectedLocation,
+ setEditLocationDialogOpened,
+ setDeleteLocationDialogOpened,
+ selectedLocation
+ } = props;
const isCloudLocation = location.type === locationType.TYPE_CLOUD;
- const handleLocationIconClick = event => {
+ const handleLocationIconClick = (
+ event: React.MouseEvent<HTMLSpanElement, MouseEvent>
+ ) => {
event.preventDefault();
event.stopPropagation();
if (directoryTreeRef.current) {
@@ -109,20 +96,23 @@ function LocationView(props: Props) {
};
const handleLocationClick = () => {
- if (location.uuid === props.currentLocationId) {
+ if (location.uuid === currentLocationId) {
// the same location click
- props.loadDirectoryContent(
- PlatformIO.getLocationPath(location),
- true,
- true
+
+ dispatch(
+ AppActions.loadDirectoryContent(
+ PlatformIO.getLocationPath(location),
+ true,
+ true
+ )
);
} else {
// this.directoryTreeRef[location.uuid].loadSubDir(location, 1);
- props.setSelectedEntries([]);
- props.exitSearchMode();
- props.openLocation(location);
- if (props.hideDrawer) {
- props.hideDrawer();
+ dispatch(AppActions.setSelectedEntries([]));
+ dispatch(AppActions.exitSearchMode());
+ dispatch(AppActions.openLocation(location));
+ if (hideDrawer) {
+ hideDrawer();
}
}
};
@@ -135,7 +125,11 @@ function LocationView(props: Props) {
event.preventDefault();
event.stopPropagation();
setLocationDirectoryContextMenuAnchorEl(event.currentTarget);
- props.setSelectedLocation(location);
+ setSelectedLocation(location);
+ };
+
+ const onUploadProgress = (progress, response) => {
+ dispatch(AppActions.onUploadProgress(progress, response));
};
/**
@@ -155,27 +149,33 @@ function LocationView(props: Props) {
} else {
arrPath.push(path);
}
- if (props.isReadOnlyMode) {
- props.showNotification(
- i18n.t('core:dndDisabledReadOnlyMode'),
- 'error',
- true
+ if (readOnlyMode) {
+ dispatch(
+ AppActions.showNotification(
+ i18n.t('core:dndDisabledReadOnlyMode'),
+ 'error',
+ true
+ )
);
return;
}
if (!AppConfig.isWin && !path.startsWith('/')) {
- props.showNotification(
- i18n.t('Moving file not possible'),
- 'error',
- true
+ dispatch(
+ AppActions.showNotification(
+ i18n.t('Moving file not possible'),
+ 'error',
+ true
+ )
);
return;
}
if (AppConfig.isWin && !path.substr(1).startsWith(':')) {
- props.showNotification(
- i18n.t('Moving file not possible'),
- 'error',
- true
+ dispatch(
+ AppActions.showNotification(
+ i18n.t('Moving file not possible'),
+ 'error',
+ true
+ )
);
return;
}
@@ -184,11 +184,7 @@ function LocationView(props: Props) {
if (targetPath === undefined) {
targetPath = targetLocation.path;
}
- /* if (item.children && item.children.props && item.children.props.path) {
- targetPath = item.children.props.path;
- } else {
- targetPath = item.children[1].props.record.path;
- } */
+
if (monitor && targetPath !== undefined && targetLocation !== undefined) {
// TODO handle monitor -> isOver and change folder icon
console.log('Dropped files: ' + path);
@@ -196,12 +192,13 @@ function LocationView(props: Props) {
// TODO Webdav
PlatformIO.enableObjectStoreSupport(targetLocation)
.then(() => {
- props.resetProgress();
- props.toggleUploadDialog();
- props
- .uploadFiles(arrPath, targetPath, props.onUploadProgress)
+ dispatch(AppActions.resetProgress());
+ dispatch(AppActions.toggleUploadDialog());
+ dispatch(
+ IOActions.uploadFiles(arrPath, targetPath, onUploadProgress)
+ )
.then((fsEntries: Array<TS.FileSystemEntry>) => {
- props.reflectCreateEntries(fsEntries);
+ dispatch(AppActions.reflectCreateEntries(fsEntries));
return true;
})
.catch(error => {
@@ -214,9 +211,9 @@ function LocationView(props: Props) {
});
} else if (targetLocation.type === locationType.TYPE_LOCAL) {
PlatformIO.disableObjectStoreSupport();
- props.moveFiles(arrPath, targetPath);
+ dispatch(IOActions.moveFiles(arrPath, targetPath));
}
- props.setSelectedEntries([]);
+ dispatch(AppActions.setSelectedEntries([]));
}
}
};
@@ -246,7 +243,7 @@ function LocationView(props: Props) {
paddingLeft: 5,
paddingRight: 5
}}
- className={props.classes.header}
+ className={classes.header}
data-tid="locationTitleElement"
noWrap
>
@@ -261,9 +258,9 @@ function LocationView(props: Props) {
<>
{locationDirectoryContextMenuAnchorEl && (
<LocationContextMenu
- setEditLocationDialogOpened={props.setEditLocationDialogOpened}
- setDeleteLocationDialogOpened={props.setDeleteLocationDialogOpened}
- selectedLocation={props.selectedLocation}
+ setEditLocationDialogOpened={setEditLocationDialogOpened}
+ setDeleteLocationDialogOpened={setDeleteLocationDialogOpened}
+ selectedLocation={selectedLocation}
locationDirectoryContextMenuAnchorEl={
locationDirectoryContextMenuAnchorEl
}
@@ -276,9 +273,9 @@ function LocationView(props: Props) {
<ListItem
data-tid={'location_' + location.name.replace(/ /g, '_')}
className={
- props.currentLocationId === location.uuid
- ? props.classes.listItemSelected
- : props.classes.listItem
+ currentLocationId === location.uuid
+ ? classes.listItemSelected
+ : classes.listItem
}
button
onClick={handleLocationClick}
@@ -301,14 +298,14 @@ function LocationView(props: Props) {
style={{
cursor: 'pointer'
}}
- className={props.classes.icon}
+ className={classes.icon}
/>
) : (
<LocalLocationIcon
style={{
cursor: 'pointer'
}}
- className={props.classes.icon}
+ className={classes.icon}
/>
)}
</Tooltip>
@@ -347,48 +344,12 @@ function LocationView(props: Props) {
<DirectoryTreeView
key={'tree_' + location.uuid}
ref={directoryTreeRef}
- classes={props.classes}
- loadDirectoryContent={props.loadDirectoryContent}
+ classes={classes}
location={location}
- showUnixHiddenEntries={props.showUnixHiddenEntries}
handleFileMoveDrop={handleFileMoveDrop}
- changeLocation={props.changeLocation}
/>
</>
);
}
-function mapStateToProps(state) {
- return {
- currentLocationId: getCurrentLocationId(state),
- isReadOnlyMode: isReadOnlyMode(state),
- showUnixHiddenEntries: getShowUnixHiddenEntries(state),
- language: getCurrentLanguage(state)
- };
-}
-
-function mapDispatchToProps(dispatch) {
- return bindActionCreators(
- {
- showNotification: AppActions.showNotification,
- toggleUploadDialog: AppActions.toggleUploadDialog,
- reflectCreateEntries: AppActions.reflectCreateEntries,
- resetProgress: AppActions.resetProgress,
- uploadFiles: IOActions.uploadFiles,
- moveFiles: IOActions.moveFiles,
- onUploadProgress: AppActions.onUploadProgress,
- setSelectedEntries: AppActions.setSelectedEntries,
- openLocation: AppActions.openLocation,
- loadDirectoryContent: AppActions.loadDirectoryContent,
- changeLocation: AppActions.changeLocation,
- exitSearchMode: AppActions.exitSearchMode
- },
- dispatch
- );
-}
-
-export default connect(
- mapStateToProps,
- mapDispatchToProps
- // @ts-ignore
-)(withStyles(styles)(React.memo(LocationView)));
+export default withStyles(styles)(React.memo(LocationView));
diff --git a/app/components/MainSearchField.tsx b/app/components/MainSearchField.tsx
index 1556e4b24..4538d7ad1 100644
--- a/app/components/MainSearchField.tsx
+++ b/app/components/MainSearchField.tsx
@@ -16,7 +16,7 @@
*
*/
-import React, { useEffect, useRef, useState } from 'react';
+import React from 'react';
import { Theme } from '@mui/material/styles';
import withStyles from '@mui/styles/withStyles';
import createStyles from '@mui/styles/createStyles';
diff --git a/app/components/MobileNavigation.tsx b/app/components/MobileNavigation.tsx
index be30dec02..d0999f755 100644
--- a/app/components/MobileNavigation.tsx
+++ b/app/components/MobileNavigation.tsx
@@ -17,8 +17,7 @@
*/
import React, { useState } from 'react';
-import { connect } from 'react-redux';
-import { bindActionCreators } from 'redux';
+import { useDispatch, useSelector } from 'react-redux';
import classNames from 'classnames';
import Box from '@mui/material/Box';
import Tooltip from '-/components/Tooltip';
@@ -46,18 +45,14 @@ import HelpFeedbackPanel from '-/components/HelpFeedbackPanel';
import i18n from '-/services/i18n';
import {
actions as AppActions,
- isSettingsDialogOpened,
isLocationManagerPanelOpened,
isTagLibraryPanelOpened,
isSearchPanelOpened,
isHelpFeedbackPanelOpened,
- isReadOnlyMode,
- getDirectoryPath
+ AppDispatch,
+ currentUser
} from '../reducers/app';
-import {
- actions as SettingsActions,
- getCurrentLanguage
-} from '-/reducers/settings';
+import { actions as SettingsActions } from '-/reducers/settings';
import StoredSearches from '-/components/StoredSearches';
import UserDetailsPopover from '-/components/UserDetailsPopover';
import { CreateFileIcon, LocalLocationIcon } from '-/components/CommonIcons';
@@ -72,63 +67,48 @@ const styles: any = (theme: any) => ({
interface Props {
classes: any;
- language: string;
- toggleProTeaser: (slidePage?: string) => void;
- toggleOnboardingDialog: () => void;
- toggleNewEntryDialog: () => void;
- toggleAboutDialog: () => void;
- toggleKeysDialog: () => void;
- toggleSettingsDialog: () => void;
- isSettingsDialogOpened: () => void;
- isLocationManagerPanelOpened: boolean;
- openLocationManagerPanel: () => void;
- isTagLibraryPanelOpened: boolean;
- openTagLibraryPanel: () => void;
- isSearchPanelOpened: boolean;
- openSearchPanel: () => void;
- isHelpFeedbackPanelOpened: boolean;
- openHelpFeedbackPanel: () => void;
- // closeAllVerticalPanels: () => void;
- toggleLocationDialog: () => void;
- openURLExternally: (url: string, skipConfirmation?: boolean) => void;
- switchTheme: () => void;
hideDrawer?: () => void;
- isReadOnlyMode: boolean;
- showNotification: (message: string) => void;
- directoryPath: string;
- user: CognitoUserInterface;
width?: number;
- theme: any;
}
function MobileNavigation(props: Props) {
+ const dispatch: AppDispatch = useDispatch();
+
+ const isLocationManagerPanelOpenedSelector = useSelector(
+ isLocationManagerPanelOpened
+ );
+ const isTagLibraryPanelOpenedSelector = useSelector(isTagLibraryPanelOpened);
+ const isSearchPanelOpenedSelector = useSelector(isSearchPanelOpened);
+ const isHelpFeedbackPanelOpenedSelector = useSelector(
+ isHelpFeedbackPanelOpened
+ );
+ const cognitoUser: CognitoUserInterface = useSelector(currentUser);
+
const [showTeaserBanner, setShowTeaserBanner] = useState<boolean>(true);
const [anchorUser, setAnchorUser] = useState<HTMLButtonElement | null>(null);
const showProTeaser = !Pro && showTeaserBanner;
- const {
- classes,
- toggleNewEntryDialog,
- toggleLocationDialog,
- toggleOnboardingDialog,
- toggleSettingsDialog,
- toggleKeysDialog,
- toggleAboutDialog,
- openLocationManagerPanel,
- openTagLibraryPanel,
- openSearchPanel,
- openHelpFeedbackPanel,
- showNotification,
- hideDrawer,
- openURLExternally,
- directoryPath,
- width,
- theme,
- switchTheme,
- user,
- language
- } = props;
+ const { classes, hideDrawer, width } = props;
+
+ const toggleNewEntryDialog = () =>
+ dispatch(AppActions.toggleNewEntryDialog());
+ // const toggleLocationDialog = () => dispatch(AppActions.toggleLocationDialog());
+ const toggleOnboardingDialog = () =>
+ dispatch(AppActions.toggleOnboardingDialog());
+ const toggleSettingsDialog = () =>
+ dispatch(AppActions.toggleSettingsDialog());
+ const toggleKeysDialog = () => dispatch(AppActions.toggleKeysDialog());
+ const toggleAboutDialog = () => dispatch(AppActions.toggleAboutDialog());
+ const openLocationManagerPanel = () =>
+ dispatch(AppActions.openLocationManagerPanel());
+ const openTagLibraryPanel = () => dispatch(AppActions.openTagLibraryPanel());
+ const openSearchPanel = () => dispatch(AppActions.openSearchPanel());
+ const openHelpFeedbackPanel = () =>
+ dispatch(AppActions.openHelpFeedbackPanel());
+ const toggleProTeaser = () => dispatch(AppActions.toggleProTeaser());
+ const switchTheme = () => dispatch(SettingsActions.switchTheme());
+
return (
<Box
style={{
@@ -205,19 +185,17 @@ function MobileNavigation(props: Props) {
</ButtonGroup>
<LocationManager
reduceHeightBy={170}
- show={props.isLocationManagerPanelOpened}
+ show={isLocationManagerPanelOpenedSelector}
/>
- {props.isTagLibraryPanelOpened && <TagLibrary reduceHeightBy={170} />}
- {props.isSearchPanelOpened && <StoredSearches reduceHeightBy={170} />}
- {props.isHelpFeedbackPanelOpened && (
+ {isTagLibraryPanelOpenedSelector && <TagLibrary reduceHeightBy={170} />}
+ {isSearchPanelOpenedSelector && <StoredSearches reduceHeightBy={170} />}
+ {isHelpFeedbackPanelOpenedSelector && (
<HelpFeedbackPanel
- language={language}
reduceHeightBy={170}
- openURLExternally={openURLExternally}
toggleAboutDialog={toggleAboutDialog}
toggleKeysDialog={toggleKeysDialog}
toggleOnboardingDialog={toggleOnboardingDialog}
- toggleProTeaser={() => props.toggleProTeaser()}
+ toggleProTeaser={toggleProTeaser}
/>
)}
</Box>
@@ -228,9 +206,8 @@ function MobileNavigation(props: Props) {
>
{showProTeaser && (
<ProTeaser
- toggleProTeaser={props.toggleProTeaser}
+ toggleProTeaser={toggleProTeaser}
setShowTeaserBanner={setShowTeaserBanner}
- openURLExternally={openURLExternally}
/>
)}
<Tooltip title={i18n.t('core:settings')}>
@@ -251,7 +228,7 @@ function MobileNavigation(props: Props) {
<ToggleButton
onClick={openLocationManagerPanel}
className={
- props.isLocationManagerPanelOpened
+ isLocationManagerPanelOpenedSelector
? classNames(classes.button, classes.selectedButton)
: classes.button
}
@@ -266,7 +243,7 @@ function MobileNavigation(props: Props) {
data-tid="tagLibrary"
onClick={openTagLibraryPanel}
className={
- props.isTagLibraryPanelOpened
+ isTagLibraryPanelOpenedSelector
? classNames(classes.button, classes.selectedButton)
: classes.button
}
@@ -280,7 +257,7 @@ function MobileNavigation(props: Props) {
data-tid="quickAccessButton"
onClick={openSearchPanel}
className={
- props.isSearchPanelOpened
+ isSearchPanelOpenedSelector
? classNames(classes.button, classes.selectedButton)
: classes.button
}
@@ -294,7 +271,7 @@ function MobileNavigation(props: Props) {
data-tid="helpFeedback"
onClick={openHelpFeedbackPanel}
className={
- props.isHelpFeedbackPanelOpened
+ isHelpFeedbackPanelOpenedSelector
? classNames(classes.button, classes.selectedButton)
: classes.button
}
@@ -304,7 +281,7 @@ function MobileNavigation(props: Props) {
</ToggleButton>
</Tooltip>
</ToggleButtonGroup>
- {user ? (
+ {cognitoUser ? (
<>
<Tooltip title={i18n.t('core:userAccount')}>
<IconButton
@@ -350,44 +327,4 @@ function MobileNavigation(props: Props) {
</Box>
);
}
-
-function mapStateToProps(state) {
- return {
- isSettingsDialogOpened: isSettingsDialogOpened(state),
- isLocationManagerPanelOpened: isLocationManagerPanelOpened(state),
- isTagLibraryPanelOpened: isTagLibraryPanelOpened(state),
- isSearchPanelOpened: isSearchPanelOpened(state),
- isHelpFeedbackPanelOpened: isHelpFeedbackPanelOpened(state),
- isReadOnlyMode: isReadOnlyMode(state),
- directoryPath: getDirectoryPath(state),
- user: state.app.user,
- language: getCurrentLanguage(state)
- };
-}
-
-function mapActionCreatorsToProps(dispatch) {
- return bindActionCreators(
- {
- toggleNewEntryDialog: AppActions.toggleNewEntryDialog,
- toggleOnboardingDialog: AppActions.toggleOnboardingDialog,
- toggleSettingsDialog: AppActions.toggleSettingsDialog,
- toggleProTeaser: AppActions.toggleProTeaser,
- toggleAboutDialog: AppActions.toggleAboutDialog,
- toggleKeysDialog: AppActions.toggleKeysDialog,
- openLocationManagerPanel: AppActions.openLocationManagerPanel,
- openTagLibraryPanel: AppActions.openTagLibraryPanel,
- openSearchPanel: AppActions.openSearchPanel,
- toggleLocationDialog: AppActions.toggleLocationDialog,
- openHelpFeedbackPanel: AppActions.openHelpFeedbackPanel,
- openURLExternally: AppActions.openURLExternally,
- showNotification: AppActions.showNotification,
- switchTheme: SettingsActions.switchTheme
- },
- dispatch
- );
-}
-
-export default connect(
- mapStateToProps,
- mapActionCreatorsToProps
-)(withStyles(styles)(MobileNavigation));
+export default withStyles(styles)(MobileNavigation);
diff --git a/app/components/ProTeaser.tsx b/app/components/ProTeaser.tsx
index c967d75f8..ee4fddf7e 100644
--- a/app/components/ProTeaser.tsx
+++ b/app/components/ProTeaser.tsx
@@ -28,15 +28,15 @@ import ProTeaserImage from '-/assets/images/pro-teaser.svg';
import ProTextLogo from '-/assets/images/text-logo-pro.svg';
import i18n from '../services/i18n';
import Links from '-/content/links';
+import { openURLExternally } from '-/services/utils-io';
interface Props {
toggleProTeaser: (slidePage?: string) => void;
setShowTeaserBanner: (teaserVisibility: boolean) => void;
- openURLExternally: (url: string, skipConfirmation?: boolean) => void;
}
function ProTeaser(props: Props) {
- const { toggleProTeaser, setShowTeaserBanner, openURLExternally } = props;
+ const { toggleProTeaser, setShowTeaserBanner } = props;
return (
<>
<CardContent
diff --git a/app/components/Revisions.tsx b/app/components/Revisions.tsx
index b3b9de96a..72d550143 100644
--- a/app/components/Revisions.tsx
+++ b/app/components/Revisions.tsx
@@ -21,21 +21,19 @@ import {
getBackupFileLocation,
extractContainingDirectoryPath
} from '@tagspaces/tagspaces-common/paths';
-import Typography from '@mui/material/Typography';
import Tooltip from '-/components/Tooltip';
-import withStyles from '@mui/styles/withStyles';
import {
actions as AppActions,
+ AppDispatch,
getOpenedFiles,
OpenedEntry
} from '-/reducers/app';
-import { connect } from 'react-redux';
+import { useSelector, useDispatch } from 'react-redux';
import { getCurrentLanguage } from '-/reducers/settings';
import PlatformIO from '-/services/platform-facade';
import { TS } from '-/tagspaces.namespace';
import { format, formatDistanceToNow } from 'date-fns';
import i18n from '-/services/i18n';
-import { bindActionCreators } from 'redux';
import DeleteIcon from '@mui/icons-material/Delete';
import PreviewIcon from '@mui/icons-material/Preview';
import RestoreIcon from '@mui/icons-material/Restore';
@@ -54,28 +52,20 @@ import {
import { Pro } from '-/pro';
import FilePreviewDialog from '-/components/dialogs/FilePreviewDialog';
-interface Props {
- // openedFile: OpenedEntry;
- openedFiles: Array<OpenedEntry>;
- updateOpenedFile: (
- entryPath: string,
- fsEntryMeta: any // FileSystemEntryMeta
- ) => Promise<boolean>;
- theme: any;
-}
-
const initialRowsPerPage = 10;
-function Revisions(props: Props) {
- const [rows, setRows] = useState<Array<TS.FileSystemEntry>>();
- const [page, setPage] = React.useState<number>(0);
+function Revisions() {
+ const dispatch: AppDispatch = useDispatch();
+ const language = useSelector(getCurrentLanguage);
+ const openedFiles: Array<OpenedEntry> = useSelector(getOpenedFiles);
+ const [rows, setRows] = useState<Array<TS.FileSystemEntry>>([]);
+ const [page, setPage] = useState<number>(0);
const [rowsPerPage, setRowsPerPage] = React.useState<number>(
initialRowsPerPage
);
const [previewDialogEntry, setPreviewDialogEntry] = useState<
- TS.FileSystemEntry
+ TS.FileSystemEntry | undefined
>(undefined);
- const { openedFiles, theme } = props;
// const [ignored, forceUpdate] = useReducer(x => x + 1, 0);
useEffect(() => {
@@ -106,7 +96,7 @@ function Revisions(props: Props) {
);
}
- const handleChangePage = (event: unknown, newPage: number) => {
+ const handleChangePage = (_event: unknown, newPage: number) => {
setPage(newPage);
};
@@ -145,37 +135,40 @@ function Revisions(props: Props) {
).then(() =>
PlatformIO.copyFilePromiseOverwrite(revisionPath, openedFile.path).then(
() =>
- props.updateOpenedFile(openedFile.path, {
- ...openedFile,
- editMode: false,
- shouldReload: !openedFile.shouldReload
- })
+ dispatch(
+ AppActions.updateOpenedFile(openedFile.path, {
+ ...openedFile,
+ editMode: false,
+ shouldReload: !openedFile.shouldReload
+ })
+ )
)
);
}
function titleFormat(lmdt) {
- if (lmdt) {
- return format(lmdt, 'dd.MM.yyyy HH:mm:ss');
- }
- return '';
+ return lmdt ? format(lmdt, 'dd.MM.yyyy HH:mm:ss') : '';
}
function cellFormat(lmdt) {
- if (lmdt) {
- return formatDistanceToNow(lmdt, {
- includeSeconds: true,
- addSuffix: true
- // locale: https://date-fns.org/v2.29.3/docs/formatDistanceToNow#usage
- });
- }
- return '';
+ return lmdt
+ ? formatDistanceToNow(lmdt, {
+ includeSeconds: true,
+ addSuffix: true
+ // locale: https://date-fns.org/v2.29.3/docs/formatDistanceToNow#usage
+ })
+ : '';
}
+ const paginatedRows = React.useMemo(
+ () => rows.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage),
+ [rows, page, rowsPerPage]
+ );
+
return (
<Paper
sx={{ width: '100%', overflow: 'hidden', height: 'calc(100% - 30px)' }}
>
- {rows && rows.length > initialRowsPerPage && (
+ {rows.length > initialRowsPerPage && (
<TablePagination
rowsPerPageOptions={[10, 25]}
component="div"
@@ -224,67 +217,56 @@ function Revisions(props: Props) {
</TableRow>
</TableHead>
<TableBody>
- {rows &&
- rows
- .slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
- .map(row => (
- <TableRow
- data-tid={openedFiles[0].uuid}
- key={row.path}
- sx={{ '&:last-child td, &:last-child th': { border: 0 } }}
- >
- <TableCell
- component="th"
- scope="row"
+ {paginatedRows.map(row => (
+ <TableRow
+ data-tid={openedFiles[0].uuid}
+ key={row.path}
+ sx={{ '&:last-child td, &:last-child th': { border: 0 } }}
+ >
+ <TableCell
+ component="th"
+ scope="row"
+ onClick={() => setPreviewDialogEntry(row)}
+ >
+ {row.name}
+ </TableCell>
+ <TableCell align="right" title={titleFormat(row.lmdt)}>
+ {cellFormat(row.lmdt)}
+ </TableCell>
+ <TableCell align="right">
+ <Tooltip title={i18n.t('core:view')}>
+ <IconButton
+ aria-label="view revision"
onClick={() => setPreviewDialogEntry(row)}
+ data-tid="viewRevisionTID"
+ size="large"
>
- {row.name}
- </TableCell>
- <TableCell align="right" title={titleFormat(row.lmdt)}>
- {cellFormat(row.lmdt)}
- </TableCell>
- <TableCell align="right">
- <Tooltip title={i18n.t('core:view')}>
- <IconButton
- aria-label="view revision"
- onClick={() => setPreviewDialogEntry(row)}
- data-tid="viewRevisionTID"
- size="large"
- >
- <PreviewIcon color="primary" />
- </IconButton>
- </Tooltip>
- <Tooltip title={i18n.t('core:restore')}>
- <IconButton
- aria-label="restore revision"
- onClick={() =>
- confirm(
- 'The content of the current file will be replaced with the content of the selected revision. Do you want to continue?'
- ) && restoreRevision(row.path)
- }
- data-tid="restoreRevisionTID"
- size="large"
- >
- <RestoreIcon color="primary" />
- </IconButton>
- </Tooltip>
- <Tooltip title={i18n.t('core:delete')}>
- <IconButton
- aria-label="delete revision"
- onClick={() =>
- confirm(
- 'The selected revision will be deleted. Do you want to continue?'
- ) && deleteRevision(row.path)
- }
- data-tid="deleteRevisionTID"
- size="large"
- >
- <DeleteIcon color="primary" />
- </IconButton>
- </Tooltip>
- </TableCell>
- </TableRow>
- ))}
+ <PreviewIcon color="primary" />
+ </IconButton>
+ </Tooltip>
+ <Tooltip title={i18n.t('core:restore')}>
+ <IconButton
+ aria-label="restore revision"
+ onClick={() => restoreRevision(row.path)}
+ data-tid="restoreRevisionTID"
+ size="large"
+ >
+ <RestoreIcon color="primary" />
+ </IconButton>
+ </Tooltip>
+ <Tooltip title={i18n.t('core:delete')}>
+ <IconButton
+ aria-label="delete revision"
+ onClick={() => deleteRevision(row.path)}
+ data-tid="deleteRevisionTID"
+ size="large"
+ >
+ <DeleteIcon color="primary" />
+ </IconButton>
+ </Tooltip>
+ </TableCell>
+ </TableRow>
+ ))}
</TableBody>
</Table>
</TableContainer>
@@ -297,22 +279,4 @@ function Revisions(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- language: getCurrentLanguage(state),
- openedFiles: getOpenedFiles(state)
- };
-}
-
-function mapActionCreatorsToProps(dispatch) {
- return bindActionCreators(
- {
- updateOpenedFile: AppActions.updateOpenedFile
- },
- dispatch
- );
-}
-export default connect(
- mapStateToProps,
- mapActionCreatorsToProps
-)(withStyles(undefined, { withTheme: true })(Revisions));
+export default Revisions;
diff --git a/app/components/SearchAutocomplete.tsx b/app/components/SearchAutocomplete.tsx
index 1d423ccdd..b2d87544d 100644
--- a/app/components/SearchAutocomplete.tsx
+++ b/app/components/SearchAutocomplete.tsx
@@ -17,8 +17,7 @@
*/
import React, { useEffect, useReducer, useRef, useState } from 'react';
-import { bindActionCreators } from 'redux';
-import { connect } from 'react-redux';
+import { useSelector, useDispatch } from 'react-redux';
import { format, formatDistanceToNow } from 'date-fns';
import withStyles from '@mui/styles/withStyles';
import makeStyles from '@mui/styles/makeStyles';
@@ -32,6 +31,7 @@ import AdvancedSearchIcon from '@mui/icons-material/TuneOutlined';
import DropDownIcon from '@mui/icons-material/ArrowDropDownOutlined';
import {
actions as AppActions,
+ AppDispatch,
getDirectoryPath,
isSearchMode
} from '../reducers/app';
@@ -41,7 +41,6 @@ import {
getSearchQuery
} from '../reducers/location-index';
import {
- isDesktopMode,
getMaxSearchResults,
getShowUnixHiddenEntries,
getCurrentLanguage
@@ -73,40 +72,12 @@ import CloseIcon from '@mui/icons-material/Close';
import { getTagLibrary } from '-/services/taglibrary-utils';
import { getSearches } from '-/reducers/searches';
import { getSearchOptions } from '-/components/SearchOptionsMenu';
-import { SearchIcon } from '-/components/CommonIcons';
import { dataTidFormat } from '-/services/test';
interface Props {
style?: any;
theme: any;
- watchForChanges: () => void;
- searchLocationIndex: (searchQuery: TS.SearchQuery) => void;
- createLocationsIndexes: () => void;
- searchAllLocations: (searchQuery: TS.SearchQuery) => void;
- // loadDirectoryContent: (path: string, generateThumbnails: boolean, loadDirMeta?: boolean) => void;
- openURLExternally: (url: string) => void;
- searchQuery: TS.SearchQuery; // () => any;
- // openCurrentDirectory: () => void;
- setSearchQuery: (searchQuery: TS.SearchQuery) => void;
- openLink: (url: string, options?: any) => void;
- currentDirectory: string;
- maxSearchResults: number;
- indexing: boolean;
- showUnixHiddenEntries: boolean;
- isDesktop: boolean;
open: boolean;
- locations: TS.Location[];
- currentLocation: TS.Location;
- openLocationById: (locationId: string) => void;
- changeLocationByID: (locationId: string) => void;
- isSearchMode: boolean;
- exitSearchMode: () => void;
- setSearchFilter: (filter) => void;
- // currentLocationId: string;
- openFsEntry: (fsEntry: TS.FileSystemEntry) => void;
- searches: Array<TS.SearchQuery>;
- switchLocationTypeByID: (locationId: string) => Promise<string | null>;
- // editedEntryPaths: Array<TS.EditedEntryPath>;
textQuery: string;
setTextQuery: (value: string) => void;
setAnchorSearch: (el: HTMLButtonElement) => void;
@@ -122,6 +93,27 @@ const useStyles = makeStyles(theme => ({
}));
function SearchAutocomplete(props: Props) {
+ const dispatch: AppDispatch = useDispatch();
+ const indexing = useSelector(isIndexing);
+ const searchQuery: TS.SearchQuery = useSelector(getSearchQuery);
+ // const isDesktop = useSelector(isDesktopMode);
+ const currentDirectory = useSelector(getDirectoryPath);
+ const maxSearchResults = useSelector(getMaxSearchResults);
+ const showUnixHiddenEntries = useSelector(getShowUnixHiddenEntries);
+ const language = useSelector(getCurrentLanguage);
+ const locations: TS.Location[] = useSelector(getLocations);
+ const currentLocation: TS.Location = useSelector(getCurrentLocation);
+ const searchMode: boolean = useSelector(isSearchMode);
+ const searches: Array<TS.SearchQuery> = useSelector(getSearches);
+
+ const openLinkDispatch = (link, options) =>
+ dispatch(AppActions.openLink(link, options));
+ const openLocationByIdDispatch = locationId =>
+ dispatch(AppActions.openLocationById(locationId));
+ const openFsEntryDispatch = fsEntry =>
+ dispatch(AppActions.openFsEntry(fsEntry));
+
+ const { setTextQuery, textQuery, open, theme, setAnchorSearch } = props;
// const [, forceUpdate] = useReducer(x => x + 1, 0);
const [
openSavedSearches,
@@ -129,12 +121,9 @@ function SearchAutocomplete(props: Props) {
] = useState<null | HTMLElement>(null);
const searchOptions = useRef<Array<SearchOptionType>>(getSearchOptions());
const currentOptions = useRef<string>(undefined);
- // const textQuery = useRef<string>(props.searchQuery.textQuery || ''); // rethink to use inputValue instead
// const textQueryMask = useRef<string>('');
const fileTypes = useRef<Array<string>>(
- props.searchQuery.fileTypes
- ? props.searchQuery.fileTypes
- : FileTypeGroups.any
+ searchQuery.fileTypes ? searchQuery.fileTypes : FileTypeGroups.any
);
const [ignored, forceUpdate] = useReducer(x => x + 1, 0);
@@ -148,39 +137,32 @@ function SearchAutocomplete(props: Props) {
const actionValues = useRef<Array<SearchOptionType>>(
[] //parseSearchQuery(textQueryMask.current)
);
- // const inputValue = useRef<string>(props.searchQuery.textQuery || ''); //getInputValue());
-
- // const searchBoxing = useRef<'location' | 'folder' | 'global'>(
- // props.searchQuery.searchBoxing ? props.searchQuery.searchBoxing : 'location'
- // );
const [searchBoxing, setSearchBoxing] = useState<ScopeType>(
- props.searchQuery.searchBoxing || 'location'
+ searchQuery.searchBoxing || 'location'
);
const searchType = useRef<'fuzzy' | 'semistrict' | 'strict'>(
- props.searchQuery.searchType ? props.searchQuery.searchType : 'fuzzy'
+ searchQuery.searchType ? searchQuery.searchType : 'fuzzy'
);
const lastModified = useRef<string>(
- props.searchQuery.lastModified ? props.searchQuery.lastModified : ''
+ searchQuery.lastModified ? searchQuery.lastModified : ''
);
const tagTimePeriod = useRef<string>('');
const tagTimePeriodHelper = useRef<string>(' ');
const tagTimePeriodFrom = useRef<number | null>(
- props.searchQuery.tagTimePeriodFrom
- ? props.searchQuery.tagTimePeriodFrom
- : null
+ searchQuery.tagTimePeriodFrom ? searchQuery.tagTimePeriodFrom : null
);
const tagTimePeriodTo = useRef<number | null>(
- props.searchQuery.tagTimePeriodTo ? props.searchQuery.tagTimePeriodTo : null
+ searchQuery.tagTimePeriodTo ? searchQuery.tagTimePeriodTo : null
);
const [tagPlaceLat, setTagPlaceLat] = useState<number | null>(null);
const [tagPlaceLong, setTagPlaceLong] = useState<number | null>(null);
// const [tagPlaceRadius, setTagPlaceRadius] = useState<number>(0);
const forceIndexing = useRef<boolean>(
- props.searchQuery.forceIndexing ? props.searchQuery.forceIndexing : false
+ searchQuery.forceIndexing ? searchQuery.forceIndexing : false
);
const fileSize = useRef<string>(
- props.searchQuery.fileSize ? props.searchQuery.fileSize : ''
+ searchQuery.fileSize ? searchQuery.fileSize : ''
);
// const mainSearchField = useRef<HTMLInputElement>(null);
@@ -189,24 +171,13 @@ function SearchAutocomplete(props: Props) {
const firstRender = useFirstRender();
const historyKeys = Pro && Pro.history ? Pro.history.historyKeys : {};
- /*useEffect(() => {
- // Handle CHANGE LOCATION IN SEARCH MODE
- if (!firstRender) {
- if (props.isSearchMode && Object.keys(props.searchQuery).length > 0) {
- // if (props.open && (inputValue.current.length > 0 || actionValues.current.length > 0)
- // executeSearch(); // will execute the same searchQuery in new location
- props.exitSearchMode();
- }
- }
- }, [props.currentLocation]);*/
-
useEffect(() => {
if (!firstRender) {
- if (!props.isSearchMode) {
+ if (!searchMode) {
clearSearch();
}
}
- }, [props.isSearchMode]);
+ }, [searchMode]);
/* let searchBoxingName = i18n.t('location');
if (searchBoxing === 'global') {
@@ -216,13 +187,13 @@ function SearchAutocomplete(props: Props) {
}*/
useEffect(() => {
- if (Object.keys(props.searchQuery).length > 0) {
+ if (Object.keys(searchQuery).length > 0) {
let emptySearch = true;
const actions: SearchOptionType[] = [];
// textQueryMask.current = '';
- if (props.searchQuery.tagsAND && props.searchQuery.tagsAND.length > 0) {
- props.searchQuery.tagsAND.forEach(tag => {
+ if (searchQuery.tagsAND && searchQuery.tagsAND.length > 0) {
+ searchQuery.tagsAND.forEach(tag => {
// textQueryMask.current += ' +' + tag.title;
actions.push({
@@ -232,8 +203,8 @@ function SearchAutocomplete(props: Props) {
});
emptySearch = false;
}
- if (props.searchQuery.tagsOR && props.searchQuery.tagsOR.length > 0) {
- props.searchQuery.tagsOR.forEach(tag => {
+ if (searchQuery.tagsOR && searchQuery.tagsOR.length > 0) {
+ searchQuery.tagsOR.forEach(tag => {
// textQueryMask.current += ' |' + tag.title;
actions.push({
action: SearchQueryComposition.TAG_OR.shortName,
@@ -242,8 +213,8 @@ function SearchAutocomplete(props: Props) {
});
emptySearch = false;
}
- if (props.searchQuery.tagsNOT && props.searchQuery.tagsNOT.length > 0) {
- props.searchQuery.tagsNOT.forEach(tag => {
+ if (searchQuery.tagsNOT && searchQuery.tagsNOT.length > 0) {
+ searchQuery.tagsNOT.forEach(tag => {
// textQueryMask.current += ' -' + tag.title;
actions.push({
action: SearchQueryComposition.TAG_NOT.shortName,
@@ -254,54 +225,37 @@ function SearchAutocomplete(props: Props) {
}
// inputValue.current = getInputValue();
- let textQuery = '';
- if (props.searchQuery.textQuery) {
- props.setTextQuery(props.searchQuery.textQuery);
- textQuery = props.searchQuery.textQuery;
+ let txtQuery = '';
+ if (searchQuery.textQuery) {
+ setTextQuery(searchQuery.textQuery);
+ txtQuery = searchQuery.textQuery;
emptySearch = false;
- } else if (props.textQuery) {
- textQuery = props.textQuery;
+ } else if (textQuery) {
+ txtQuery = textQuery;
emptySearch = false;
}
- const searchQuery = {
- ...props.searchQuery,
- textQuery: textQuery
- };
-
- /*if (mainSearchField.current) {
- mainSearchField.current.value =
- inputValue.current +
- (textQueryMask.current ? ' ' + textQueryMask.current.trim() : '');
- }*/
- if (
- props.searchQuery.searchBoxing
- // && props.searchQuery.searchBoxing !== 'location'
- ) {
- setSearchBoxing(props.searchQuery.searchBoxing);
- // searchBoxing.current = props.searchQuery.searchBoxing;
+ if (searchQuery.searchBoxing) {
+ setSearchBoxing(searchQuery.searchBoxing);
emptySearch = false;
actions.push({
action: SearchQueryComposition.SCOPE.fullName,
label:
SearchQueryComposition.SCOPE.fullName +
' ' +
- props.searchQuery.searchBoxing
+ searchQuery.searchBoxing
});
}
if (
- props.searchQuery.fileTypes &&
+ searchQuery.fileTypes &&
JSON.stringify(searchQuery.fileTypes) !==
JSON.stringify(FileTypeGroups.any)
) {
- fileTypes.current = props.searchQuery.fileTypes;
+ fileTypes.current = searchQuery.fileTypes;
emptySearch = false;
let keyFileType;
Object.entries(FileTypeGroups).forEach(([key, value]) => {
- if (
- JSON.stringify(value) ===
- JSON.stringify(props.searchQuery.fileTypes)
- ) {
+ if (JSON.stringify(value) === JSON.stringify(searchQuery.fileTypes)) {
keyFileType = key;
}
});
@@ -312,54 +266,51 @@ function SearchAutocomplete(props: Props) {
' ' +
(keyFileType
? i18n.t('core:' + keyFileType)
- : props.searchQuery.fileTypes)
+ : searchQuery.fileTypes)
});
}
- if (
- props.searchQuery.searchType
- // && props.searchQuery.searchType !== accuracy.fuzzy
- ) {
- searchType.current = props.searchQuery.searchType;
+ if (searchQuery.searchType) {
+ searchType.current = searchQuery.searchType;
emptySearch = false;
actions.push({
action: SearchQueryComposition.ACCURACY.fullName,
label:
SearchQueryComposition.ACCURACY.fullName +
' ' +
- i18n.t('core:' + props.searchQuery.searchType)
+ i18n.t('core:' + searchQuery.searchType)
});
}
- if (props.searchQuery.lastModified) {
- lastModified.current = props.searchQuery.lastModified;
+ if (searchQuery.lastModified) {
+ lastModified.current = searchQuery.lastModified;
emptySearch = false;
actions.push({
action: SearchQueryComposition.LAST_MODIFIED.fullName,
label:
SearchQueryComposition.LAST_MODIFIED.fullName +
' ' +
- i18n.t('core:' + props.searchQuery.lastModified)
+ i18n.t('core:' + searchQuery.lastModified)
});
}
- if (props.searchQuery.tagTimePeriodFrom) {
- tagTimePeriodFrom.current = props.searchQuery.tagTimePeriodFrom;
+ if (searchQuery.tagTimePeriodFrom) {
+ tagTimePeriodFrom.current = searchQuery.tagTimePeriodFrom;
emptySearch = false;
}
- if (props.searchQuery.tagTimePeriodTo) {
- tagTimePeriodTo.current = props.searchQuery.tagTimePeriodTo;
+ if (searchQuery.tagTimePeriodTo) {
+ tagTimePeriodTo.current = searchQuery.tagTimePeriodTo;
emptySearch = false;
}
- if (props.searchQuery.forceIndexing) {
- forceIndexing.current = props.searchQuery.forceIndexing;
+ if (searchQuery.forceIndexing) {
+ forceIndexing.current = searchQuery.forceIndexing;
}
- if (props.searchQuery.fileSize) {
- fileSize.current = props.searchQuery.fileSize;
+ if (searchQuery.fileSize) {
+ fileSize.current = searchQuery.fileSize;
emptySearch = false;
actions.push({
action: SearchQueryComposition.SIZE.fullName,
label:
SearchQueryComposition.SIZE.fullName +
' ' +
- i18n.t('core:' + props.searchQuery.fileSize)
+ i18n.t('core:' + searchQuery.fileSize)
});
}
if (!emptySearch) {
@@ -373,17 +324,21 @@ function SearchAutocomplete(props: Props) {
forceUpdate();
}
if (searchQuery.executeSearch) {
+ const sQuery = {
+ ...searchQuery,
+ textQuery: txtQuery
+ };
if (searchBoxing === 'global') {
- props.searchAllLocations(searchQuery);
+ dispatch(LocationIndexActions.searchAllLocations(sQuery));
} else {
- props.searchLocationIndex(searchQuery);
+ dispatch(LocationIndexActions.searchLocationIndex(sQuery));
}
}
} /*else {
clearSearch();
}*/
}
- }, [props.searchQuery]);
+ }, [searchQuery]);
/*function getInputValue() {
const txtQuery = removeActionsFromQuery(
@@ -420,14 +375,13 @@ function SearchAutocomplete(props: Props) {
}
} else if (event.key === 'Escape' || event.keyCode === 27) {
clearSearch();
- // props.openCurrentDirectory();
} else if (event.key === 'ArrowDown' || event.keyCode === 40) {
if (!isOpen.current) {
isOpen.current = true;
forceUpdate();
}
} else if (event.key === 'Backspace' || event.keyCode === 8) {
- if (props.textQuery.length === 0 && actionValues.current.length > 0) {
+ if (textQuery.length === 0 && actionValues.current.length > 0) {
actionValues.current = actionValues.current.slice(0, -1);
resetActions(actionValues.current);
isOpen.current = true;
@@ -439,7 +393,7 @@ function SearchAutocomplete(props: Props) {
};
function resetValues(exceptions: Array<SearchOptionType>) {
- props.setTextQuery('');
+ setTextQuery('');
if (
!exceptions.some(action =>
isAction(action.action, SearchQueryComposition.SCOPE)
@@ -485,11 +439,9 @@ function SearchAutocomplete(props: Props) {
}
const clearSearch = () => {
resetValues([]);
- props.setSearchQuery({});
- props.exitSearchMode();
- // props.setSearchResults([]);
- props.watchForChanges();
- // props.openCurrentDirectory();
+ dispatch(LocationIndexActions.setSearchQuery({}));
+ dispatch(AppActions.exitSearchMode());
+ dispatch(AppActions.watchForChanges());
};
function removeActionsFromQuery(
@@ -607,12 +559,11 @@ function SearchAutocomplete(props: Props) {
// don't execute search on search filter
return;
}
- let query = props.textQuery;
if (
- query.startsWith('ts:?ts') ||
- query.startsWith(AppConfig.tsProtocol + '?ts')
+ textQuery.startsWith('ts:?ts') ||
+ textQuery.startsWith(AppConfig.tsProtocol + '?ts')
) {
- props.openLink(query, { fullWidth: false });
+ openLinkDispatch(textQuery, { fullWidth: false });
clearSearch();
return;
}
@@ -633,8 +584,8 @@ function SearchAutocomplete(props: Props) {
// query = removeTagsFromQuery(tagsNOT, query, '-');
// query = removeActionsFromQuery(query, actionValues.current);
- const searchQuery: TS.SearchQuery = {
- textQuery: query,
+ const sQuery: TS.SearchQuery = {
+ textQuery: textQuery,
tagsAND,
tagsOR,
tagsNOT,
@@ -648,23 +599,20 @@ function SearchAutocomplete(props: Props) {
tagPlaceLat,
tagPlaceLong,
// tagPlaceRadius,
- maxSearchResults: props.maxSearchResults,
- currentDirectory: props.currentDirectory,
+ maxSearchResults: maxSearchResults,
+ currentDirectory: currentDirectory,
forceIndexing: forceIndexing.current,
- showUnixHiddenEntries: props.showUnixHiddenEntries,
+ showUnixHiddenEntries: showUnixHiddenEntries,
executeSearch: true
};
- if (!haveSearchFilters(searchQuery)) {
+ if (!haveSearchFilters(sQuery)) {
clearSearch();
- // props.openLocationById(props.currentLocationId);
} else {
- console.log('Search object: ' + JSON.stringify(searchQuery));
- props.setSearchQuery(searchQuery);
+ console.log('Search object: ' + JSON.stringify(sQuery));
+ dispatch(LocationIndexActions.setSearchQuery(sQuery));
}
};
- const { indexing, isDesktop, open, theme } = props;
-
/*function parseOptions(options: Array<any>) {
const parsed = [];
@@ -714,7 +662,7 @@ function SearchAutocomplete(props: Props) {
if (isAction(action, SearchActions.LOCATION)) {
if (currentOptions.current !== action) {
currentOptions.current = action;
- searchOptions.current = props.locations.map(location => {
+ searchOptions.current = locations.map(location => {
return {
id: location.uuid,
descr: location.path,
@@ -814,7 +762,7 @@ function SearchAutocomplete(props: Props) {
}
searchOptions.current = getOptions(
- props.searches,
+ searches,
i18n.t('core:savedSearchesTitle')
);
}
@@ -1010,11 +958,11 @@ function SearchAutocomplete(props: Props) {
}
actions.push(option);
} else if (option.action === ExecActions.OPEN_LOCATION) {
- props.exitSearchMode();
+ dispatch(AppActions.exitSearchMode());
// isOpen.current = false;
searchOptions.current = getSearchOptions();
currentOptions.current = undefined;
- props.openLocationById(option.id);
+ openLocationByIdDispatch(option.id);
return [];
} else if (isAction(option.action, SearchActions.FILTER)) {
actions.push(option);
@@ -1046,14 +994,14 @@ function SearchAutocomplete(props: Props) {
} else if (option.action === ExecActions.OPEN_HISTORY) {
if (option.searchQuery) {
if (option.id) {
- //if (props.currentLocation === undefined) {
- // props.openLocationById(option.id, true);
- // props.setSearchQuery(option.searchQuery);
- //} else {
- props.switchLocationTypeByID(option.id).then(() => {
- props.changeLocationByID(option.id);
- props.setSearchQuery(option.searchQuery);
- });
+ dispatch(AppActions.switchLocationTypeByID(option.id)).then(
+ () => {
+ dispatch(AppActions.changeLocationByID(option.id));
+ dispatch(
+ LocationIndexActions.setSearchQuery(option.searchQuery)
+ );
+ }
+ );
} else {
}
} else if (Pro && Pro.history) {
@@ -1065,10 +1013,10 @@ function SearchAutocomplete(props: Props) {
};
Pro.history.openItem(
item,
- props.currentLocation.uuid,
- props.openLink,
- props.openLocationById,
- props.openFsEntry
+ currentLocation.uuid,
+ openLinkDispatch,
+ openLocationByIdDispatch,
+ openFsEntryDispatch
);
}
searchOptions.current = getSearchOptions();
@@ -1085,10 +1033,10 @@ function SearchAutocomplete(props: Props) {
};
Pro.history.openItem(
item,
- props.currentLocation.uuid,
- props.openLink,
- props.openLocationById,
- props.openFsEntry
+ currentLocation.uuid,
+ openLinkDispatch,
+ openLocationByIdDispatch,
+ openFsEntryDispatch
);
}
searchOptions.current = getSearchOptions();
@@ -1096,7 +1044,9 @@ function SearchAutocomplete(props: Props) {
isOpen.current = false;
return [];
} else if (option.action === ExecActions.OPEN_SAVED_SEARCHES) {
- props.setSearchQuery(JSON.parse(option.fullName));
+ dispatch(
+ LocationIndexActions.setSearchQuery(JSON.parse(option.fullName))
+ );
searchOptions.current = getSearchOptions();
currentOptions.current = undefined;
isOpen.current = false;
@@ -1147,14 +1097,16 @@ function SearchAutocomplete(props: Props) {
actionValues.current,
SearchQueryComposition.TAG_NOT
);
- props.setSearchQuery({
- ...props.searchQuery,
- tagsAND,
- tagsOR,
- tagsNOT,
- executeSearch: false
- });
- props.setTextQuery('');
+ dispatch(
+ LocationIndexActions.setSearchQuery({
+ ...searchQuery,
+ tagsAND,
+ tagsOR,
+ tagsNOT,
+ executeSearch: false
+ })
+ );
+ setTextQuery('');
if (hasOptionsChanged) {
changeOptions(option.action);
}
@@ -1167,11 +1119,13 @@ function SearchAutocomplete(props: Props) {
const id = setActionLabel(SearchQueryComposition.TYPE, option);
if (id) {
fileTypes.current = option.descr.split(', ');
- props.setSearchQuery({
- ...props.searchQuery,
- fileTypes: fileTypes.current,
- executeSearch: false
- });
+ dispatch(
+ LocationIndexActions.setSearchQuery({
+ ...searchQuery,
+ fileTypes: fileTypes.current,
+ executeSearch: false
+ })
+ );
}
if (hasOptionsChanged) {
changeOptions(option.action);
@@ -1186,11 +1140,13 @@ function SearchAutocomplete(props: Props) {
const id = setActionLabel(SearchQueryComposition.SIZE, option);
if (id) {
fileSize.current = id;
- props.setSearchQuery({
- ...props.searchQuery,
- fileSize: id,
- executeSearch: false
- });
+ dispatch(
+ LocationIndexActions.setSearchQuery({
+ ...searchQuery,
+ fileSize: id,
+ executeSearch: false
+ })
+ );
}
if (hasOptionsChanged) {
changeOptions(option.action);
@@ -1210,11 +1166,13 @@ function SearchAutocomplete(props: Props) {
);
if (id) {
lastModified.current = id;
- props.setSearchQuery({
- ...props.searchQuery,
- lastModified: id,
- executeSearch: false
- });
+ dispatch(
+ LocationIndexActions.setSearchQuery({
+ ...searchQuery,
+ lastModified: id,
+ executeSearch: false
+ })
+ );
}
if (hasOptionsChanged) {
changeOptions(option.action);
@@ -1229,11 +1187,13 @@ function SearchAutocomplete(props: Props) {
const id = setActionLabel(SearchQueryComposition.SCOPE, option);
if (id) {
setSearchBoxing(scope[id]);
- props.setSearchQuery({
- ...props.searchQuery,
- searchBoxing: scope[id],
- executeSearch: false
- });
+ dispatch(
+ LocationIndexActions.setSearchQuery({
+ ...searchQuery,
+ searchBoxing: scope[id],
+ executeSearch: false
+ })
+ );
}
if (hasOptionsChanged) {
changeOptions(option.action);
@@ -1247,11 +1207,13 @@ function SearchAutocomplete(props: Props) {
const id = setActionLabel(SearchQueryComposition.ACCURACY, option);
if (id) {
searchType.current = accuracy[id];
- props.setSearchQuery({
- ...props.searchQuery,
- searchType: accuracy[id],
- executeSearch: false
- });
+ dispatch(
+ LocationIndexActions.setSearchQuery({
+ ...searchQuery,
+ searchType: accuracy[id],
+ executeSearch: false
+ })
+ );
}
if (hasOptionsChanged) {
changeOptions(option.action);
@@ -1259,7 +1221,7 @@ function SearchAutocomplete(props: Props) {
// executeSearch();
} else if (option.action === undefined) {
// text query
- props.setTextQuery(option.label);
+ setTextQuery(option.label);
const pAction = actions[actions.length - 1];
if (pAction && isAction(pAction.action, SearchActions.FILTER)) {
@@ -1267,7 +1229,7 @@ function SearchAutocomplete(props: Props) {
o => !(typeof o === 'object') && o.action === undefined
);
if (filterArr.length > 0) {
- props.setSearchFilter(filterArr.join(' '));
+ dispatch(AppActions.setSearchFilter(filterArr.join(' ')));
isOpen.current = false;
return actions;
}
@@ -1281,23 +1243,6 @@ function SearchAutocomplete(props: Props) {
return actions;
}
- /*function setTextQuery(actions) {
- let txtQuery = '';
- if (actions.length > 0) {
- actions.forEach(action => {
- if (
- action.action === ExecActions.TAG_SEARCH_AND ||
- ExecActions.TAG_SEARCH_OR ||
- ExecActions.TAG_SEARCH_NOT
- ) {
- txtQuery += ' ' + action.label;
- }
- });
- }
- textQuery.current =
- txtQuery.trim() + (inputValue.current ? ' ' + inputValue.current : '');
- }*/
-
function handleInputChange(event: any, value: string, reason: string) {
// handleChange(event, value.split(' '), 'createOption');
if (reason === 'input') {
@@ -1310,7 +1255,7 @@ function SearchAutocomplete(props: Props) {
const inputArr = valueArr.filter(
action => !actionValues.current.some(v => v.label === action)
);
- props.setTextQuery(inputArr.join(' '));
+ setTextQuery(inputArr.join(' '));
//textQuery.current += ' ' + inputValue.current;
forceUpdate();
} else if (reason === 'clear') {
@@ -1478,7 +1423,7 @@ function SearchAutocomplete(props: Props) {
data-tid="advancedSearch"
style={{ maxHeight: 35 }}
onClick={(event: React.MouseEvent<HTMLButtonElement>) => {
- props.setAnchorSearch(event.currentTarget);
+ setAnchorSearch(event.currentTarget);
}}
>
<AdvancedSearchIcon />
@@ -1544,7 +1489,7 @@ function SearchAutocomplete(props: Props) {
v.fullName ? v.fullName : v.label
)}
onChange={handleChange}
- inputValue={props.textQuery}
+ inputValue={textQuery}
onInputChange={handleInputChange}
open={isOpen.current}
/*onOpen={handleOpen}
@@ -1698,15 +1643,6 @@ function SearchAutocomplete(props: Props) {
onKeyDown={onKeyDownHandler}
disableClearable={true}
renderInput={params => {
- /*if (params.InputProps.startAdornment) {
- params.InputProps.startAdornment = [
- startAdornment,
- ...(Array.isArray(params.InputProps.startAdornment) &&
- params.InputProps.startAdornment)
- ];
- } else {
- params.InputProps.startAdornment = [startAdornment];
- }*/
if (params.InputProps.endAdornment) {
params.InputProps.endAdornment = [
params.InputProps.endAdornment,
@@ -1776,56 +1712,5 @@ function SearchAutocomplete(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- indexing: isIndexing(state),
- searchQuery: getSearchQuery(state),
- isDesktop: isDesktopMode(state),
- currentDirectory: getDirectoryPath(state),
- maxSearchResults: getMaxSearchResults(state),
- showUnixHiddenEntries: getShowUnixHiddenEntries(state),
- language: getCurrentLanguage(state),
- locations: getLocations(state),
- currentLocation: getCurrentLocation(state),
- isSearchMode: isSearchMode(state),
- //currentLocationId: getCurrentLocationId(state),
- searches: getSearches(state)
- // editedEntryPaths: getEditedEntryPaths(state)
- };
-}
-
-function mapDispatchToProps(dispatch) {
- return bindActionCreators(
- {
- searchAllLocations: LocationIndexActions.searchAllLocations,
- setSearchQuery: LocationIndexActions.setSearchQuery,
- searchLocationIndex: LocationIndexActions.searchLocationIndex,
- createLocationsIndexes: LocationIndexActions.createLocationsIndexes,
- // loadDirectoryContent: AppActions.loadDirectoryContent,
- openLink: AppActions.openLink,
- openURLExternally: AppActions.openURLExternally,
- // openCurrentDirectory: AppActions.openCurrentDirectory,
- watchForChanges: AppActions.watchForChanges,
- openLocationById: AppActions.openLocationById,
- changeLocationByID: AppActions.changeLocationByID,
- exitSearchMode: AppActions.exitSearchMode,
- setSearchFilter: AppActions.setSearchFilter,
- openFsEntry: AppActions.openFsEntry,
- switchLocationTypeByID: AppActions.switchLocationTypeByID
- },
- dispatch
- );
-}
-
-/*const areEqual = (prevProp, nextProp) =>
- nextProp.open === prevProp.open &&
- nextProp.language === prevProp.language &&
- nextProp.indexing === prevProp.indexing &&
- nextProp.searchQuery === prevProp.searchQuery &&
- nextProp.currentDirectory === prevProp.currentDirectory && */
-
// @ts-ignore
-export default connect(
- mapStateToProps,
- mapDispatchToProps
-)(withStyles(undefined, { withTheme: true })(SearchAutocomplete)); // (React.memo(SearchAutocomplete, areEqual));
+export default withStyles(undefined, { withTheme: true })(SearchAutocomplete);
diff --git a/app/components/SearchPopover.tsx b/app/components/SearchPopover.tsx
index a1cbec254..0d82bf403 100644
--- a/app/components/SearchPopover.tsx
+++ b/app/components/SearchPopover.tsx
@@ -86,6 +86,7 @@ import {
ArchiveIcon,
CloseIcon
} from '-/components/CommonIcons';
+import { openURLExternally } from '-/services/utils-io';
const SaveSearchDialog = Pro && Pro.UI ? Pro.UI.SaveSearchDialog : false;
@@ -99,7 +100,6 @@ interface Props {
generateThumbnails: boolean,
loadDirMeta?: boolean
) => void;
- openURLExternally: (url: string, skipConfirmation?: boolean) => void;
hideDrawer?: () => void;
searchQuery: TS.SearchQuery; // () => any;
setSearchResults: (entries: Array<any>) => void;
@@ -1086,7 +1086,7 @@ function SearchPopover(props: Props) {
variant="text"
data-tid="helpSearchButtonTID"
onClick={() =>
- props.openURLExternally(Links.documentationLinks.search, true)
+ openURLExternally(Links.documentationLinks.search, true)
}
>
{i18n.t('help')}
@@ -1151,7 +1151,6 @@ function mapDispatchToProps(dispatch) {
setSearchQuery: LocationIndexActions.setSearchQuery,
createLocationsIndexes: LocationIndexActions.createLocationsIndexes,
loadDirectoryContent: AppActions.loadDirectoryContent,
- openURLExternally: AppActions.openURLExternally,
setSearchResults: AppActions.setSearchResults,
exitSearchMode: AppActions.exitSearchMode
},
diff --git a/app/components/StoredSearches.tsx b/app/components/StoredSearches.tsx
index 61e0cf80e..71704cac0 100644
--- a/app/components/StoredSearches.tsx
+++ b/app/components/StoredSearches.tsx
@@ -77,7 +77,6 @@ interface Props {
// searchAllLocations: (searchQuery: TS.SearchQuery) => void;
showUnixHiddenEntries: boolean;
addSearches: (searches: Array<TS.SearchQuery>) => void;
- openURLExternally: (url: string) => void;
reduceHeightBy: number;
openFsEntry: (fsEntry: TS.FileSystemEntry) => void;
openLink: (url: string, options: any) => void;
@@ -260,7 +259,6 @@ function StoredSearches(props: Props) {
anchorEl={searchMenuAnchorEl}
open={Boolean(searchMenuAnchorEl)}
onClose={handleCloseSearchMenu}
- openURLExternally={props.openURLExternally}
exportSearches={() => {
setExportSearchesDialogOpened(true);
}}
@@ -637,7 +635,6 @@ function mapDispatchToProps(dispatch) {
setSearchQuery: LocationIndexActions.setSearchQuery,
// searchAllLocations: LocationIndexActions.searchAllLocations,
// searchLocationIndex: LocationIndexActions.searchLocationIndex,
- openURLExternally: AppActions.openURLExternally,
openFsEntry: AppActions.openFsEntry,
openLink: AppActions.openLink,
openLocationById: AppActions.openLocationById,
diff --git a/app/components/TagContainer.tsx b/app/components/TagContainer.tsx
index cb0ca1986..3c5739cd5 100644
--- a/app/components/TagContainer.tsx
+++ b/app/components/TagContainer.tsx
@@ -46,7 +46,7 @@ interface Props {
tagMode?: 'default' | 'display' | 'remove';
entryPath?: string;
deleteIcon?: Object;
- addTags?: (paths: Array<string>, tags: Array<TS.Tag>) => void;
+ addTags?: (paths: Array<string>, tags: Array<TS.Tag>, updateIndex?) => void;
moveTag?: (
tagTitle: string,
fromTagGroupId: TS.Uuid,
diff --git a/app/components/TagContainerDnd.tsx b/app/components/TagContainerDnd.tsx
index 7332685e0..56abf6311 100644
--- a/app/components/TagContainerDnd.tsx
+++ b/app/components/TagContainerDnd.tsx
@@ -197,7 +197,7 @@ interface Props {
isDragging?: boolean;
tagMode?: 'default' | 'display' | 'remove';
entryPath?: string;
- addTags?: (paths: Array<string>, tags: Array<TS.Tag>) => void;
+ addTags?: (paths: Array<string>, tags: Array<TS.Tag>, updateIndex?) => void;
addTag?: (tag: TS.Tag, parentTagGroupUuid: TS.Uuid) => void;
moveTag?: (
tagTitle: string,
diff --git a/app/components/TagLibrary.tsx b/app/components/TagLibrary.tsx
index d1c0bf0e6..cd1e2a8aa 100644
--- a/app/components/TagLibrary.tsx
+++ b/app/components/TagLibrary.tsx
@@ -17,8 +17,7 @@
*/
import React, { useCallback, useEffect, useRef, useState } from 'react';
-import { bindActionCreators } from 'redux';
-import { connect } from 'react-redux';
+import { useSelector, useDispatch } from 'react-redux';
import classNames from 'classnames';
import withStyles from '@mui/styles/withStyles';
import Typography from '@mui/material/Typography';
@@ -42,11 +41,14 @@ import i18n from '../services/i18n';
import {
actions as SettingsActions,
getCurrentLanguage,
+ getSaveTagInLocation,
getTagColor,
+ getTagGroupCollapsed,
getTagTextColor
} from '../reducers/settings';
import {
actions as AppActions,
+ AppDispatch,
getSelectedEntries,
isReadOnlyMode,
isTagLibraryChanged
@@ -64,7 +66,6 @@ import {
deleteTag,
editTag,
editTagGroup,
- exportTagGroups,
getAllTags,
getTagLibrary,
importTagGroups,
@@ -80,50 +81,31 @@ import useFirstRender from '-/utils/useFirstRender';
interface Props {
classes?: any;
style?: any;
- isReadOnly: boolean;
- tagTextColor: string;
- tagBackgroundColor: string;
- //tagGroups: Array<TS.TagGroup>;
- //allTags: Array<TS.Tag>;
- openURLExternally: (path: string) => void;
- toggleTagGroup: (uuid: string) => void;
- settingsVersion: number;
- // removeTagGroup: (uuid: string) => void;
- // moveTagGroupUp: (uuid: string) => void;
- // moveTagGroupDown: (uuid: string) => void;
- // sortTagGroup: (uuid: string) => void;
- collectTagsFromLocation: (tagGroup: TS.TagGroup) => void;
- addTags: () => void;
- // importTagGroups: (entries: Array<TS.TagGroup>, replace?: boolean) => void;
- // exportTagGroups: () => void;
- // createTagGroup: () => void;
- // addTag: () => void;
- // moveTag: () => void;
- /*changeTagOrder: (
- tagGroupUuid: TS.Uuid,
- fromIndex: number,
- toIndex: number
- ) => void;*/
- // editTagGroup: () => void;
- // editTag: () => void;
- // deleteTag: (tagTitle: string, parentTagGroupUuid: TS.Uuid) => void;
- showNotification: (
- text: string,
- notificationType?: string, // NotificationTypes
- autohide?: boolean
- ) => void;
- selectedEntries: Array<TS.FileSystemEntry>;
- tagGroupCollapsed: Array<string>;
- locations: Array<TS.Location>;
- saveTagInLocation: boolean;
- // moveTagGroup: (tagGroupUuid: TS.Uuid, position: number) => void;
reduceHeightBy: number;
- isTagLibraryChanged: boolean;
- switchLocationType: (locationId: string) => Promise<string | null>;
- switchCurrentLocationType: (currentLocationId) => Promise<boolean>;
}
function TagLibrary(props: Props) {
+ const dispatch: AppDispatch = useDispatch();
+ const tagBackgroundColor = useSelector(getTagColor);
+ const tagTextColor = useSelector(getTagTextColor);
+ const selectedEntries: Array<TS.FileSystemEntry> = useSelector(
+ getSelectedEntries
+ );
+ const readOnly = useSelector(isReadOnlyMode);
+ const tagGroupCollapsed: Array<string> = useSelector(getTagGroupCollapsed);
+ const locations: Array<TS.Location> = useSelector(getLocations);
+ const saveTagInLocation: boolean = useSelector(getSaveTagInLocation);
+ const tagLibraryChanged = useSelector(isTagLibraryChanged);
+ const language = useSelector(getCurrentLanguage);
+
+ const toggleTagGroupDispatch = uuid =>
+ dispatch(SettingsActions.toggleTagGroup(uuid));
+ const addTagsDispatch = (
+ paths: Array<string>,
+ tags: Array<TS.Tag>,
+ updateIndex
+ ) => dispatch(TaggingActions.addTags(paths, tags, updateIndex));
+
const [tagGroups, setTagGroups] = useState<Array<TS.TagGroup>>(
getTagLibrary()
);
@@ -168,7 +150,7 @@ function TagLibrary(props: Props) {
const firstRender = useFirstRender();
useEffect(() => {
- if (Pro && props.saveTagInLocation) {
+ if (Pro && saveTagInLocation) {
refreshTagsFromLocation();
}
}, []);
@@ -177,10 +159,10 @@ function TagLibrary(props: Props) {
if (!firstRender) {
setTagGroups(getTagLibrary());
}
- }, [props.isTagLibraryChanged]);
+ }, [tagLibraryChanged]);
const refreshTagsFromLocation = () => {
- props.locations.map(location =>
+ locations.map(location =>
Pro.MetaOperations.getTagGroups(location.path)
.then((tg: Array<TS.TagGroup>) => {
if (tg && tg.length > 0) {
@@ -294,7 +276,7 @@ function TagLibrary(props: Props) {
const renderTagGroup = (tagGroup, index) => {
// eslint-disable-next-line no-param-reassign
tagGroup.expanded = !(
- props.tagGroupCollapsed && props.tagGroupCollapsed.includes(tagGroup.uuid)
+ tagGroupCollapsed && tagGroupCollapsed.includes(tagGroup.uuid)
);
const isReadOnly = tagGroup.readOnly || isTagLibraryReadOnly;
return (
@@ -307,23 +289,23 @@ function TagLibrary(props: Props) {
setTagGroups(moveTagGroup(tagGroupUuid, position, tagGroups));
}}
handleTagGroupMenu={handleTagGroupMenu}
- toggleTagGroup={props.toggleTagGroup}
- locations={props.locations}
- tagGroupCollapsed={props.tagGroupCollapsed}
+ toggleTagGroup={toggleTagGroupDispatch}
+ locations={locations}
+ tagGroupCollapsed={tagGroupCollapsed}
isReadOnly={isReadOnly}
/>
<Collapse in={tagGroup.expanded} unmountOnExit>
<TagGroupContainer taggroup={tagGroup}>
{tagGroup.children &&
tagGroup.children.map((tag: TS.Tag, idx) => {
- if (props.isReadOnly) {
+ if (readOnly) {
return (
<TagContainer
key={tagGroup.uuid + tag.title}
tag={tag}
tagGroup={tagGroup}
handleTagMenu={handleTagMenuCallback}
- addTags={props.addTags}
+ addTags={addTagsDispatch}
/*moveTag={(
tagTitle: string,
fromTagGroupId: TS.Uuid,
@@ -336,7 +318,7 @@ function TagLibrary(props: Props) {
tagGroups
)
}*/
- selectedEntries={props.selectedEntries}
+ selectedEntries={selectedEntries}
/>
);
}
@@ -348,7 +330,7 @@ function TagLibrary(props: Props) {
tag={tag}
tagGroup={tagGroup}
handleTagMenu={handleTagMenuCallback}
- addTags={props.addTags}
+ addTags={addTagsDispatch}
moveTag={(
tagTitle: string,
fromTagGroupId: TS.Uuid,
@@ -377,7 +359,7 @@ function TagLibrary(props: Props) {
)
)
}
- selectedEntries={props.selectedEntries}
+ selectedEntries={selectedEntries}
/>
);
})}
@@ -394,19 +376,13 @@ function TagLibrary(props: Props) {
selectedTag.title,
selectedTagGroupEntry.uuid,
tagGroups,
- props.locations
+ locations
)
);
}
}
- const {
- classes,
- // allTags,
- showNotification,
- isReadOnly,
- reduceHeightBy
- } = props;
+ const { classes, reduceHeightBy } = props;
const allTags = getAllTags(tagGroups);
return (
@@ -452,11 +428,7 @@ function TagLibrary(props: Props) {
confirmCallback={result => {
if (result && selectedTagGroupEntry) {
setTagGroups(
- removeTagGroup(
- selectedTagGroupEntry.uuid,
- tagGroups,
- props.locations
- )
+ removeTagGroup(selectedTagGroupEntry.uuid, tagGroups, locations)
);
}
}}
@@ -469,22 +441,24 @@ function TagLibrary(props: Props) {
open={isCreateTagGroupDialogOpened}
onClose={() => setIsCreateTagGroupDialogOpened(false)}
createTagGroup={(entry: TS.TagGroup) => {
- const location: TS.Location = props.locations.find(
+ const location: TS.Location = locations.find(
l => l.uuid === entry.locationId
);
if (location) {
- props
- .switchLocationType(location.uuid)
- .then(currentLocationId => {
+ dispatch(LocationActions.switchLocationType(location.uuid)).then(
+ currentLocationId => {
setTagGroups(createTagGroup(entry, tagGroups, location));
- props.switchCurrentLocationType(currentLocationId);
- });
+ dispatch(
+ AppActions.switchCurrentLocationType(currentLocationId)
+ );
+ }
+ );
} else {
setTagGroups(createTagGroup(entry, tagGroups));
}
}}
- color={props.tagBackgroundColor}
- textcolor={props.tagTextColor}
+ color={tagBackgroundColor}
+ textcolor={tagTextColor}
/>
)}
{isCreateTagDialogOpened && (
@@ -492,9 +466,7 @@ function TagLibrary(props: Props) {
open={isCreateTagDialogOpened}
onClose={() => setIsCreateTagDialogOpened(false)}
addTag={(tag: any, parentTagGroupUuid: TS.Uuid) =>
- setTagGroups(
- addTag(tag, parentTagGroupUuid, tagGroups, props.locations)
- )
+ setTagGroups(addTag(tag, parentTagGroupUuid, tagGroups, locations))
}
selectedTagGroupEntry={selectedTagGroupEntry}
/>
@@ -504,7 +476,7 @@ function TagLibrary(props: Props) {
open={isEditTagGroupDialogOpened}
onClose={() => setIsEditTagGroupDialogOpened(false)}
editTagGroup={(entry: TS.TagGroup) =>
- setTagGroups(editTagGroup(entry, tagGroups, props.locations))
+ setTagGroups(editTagGroup(entry, tagGroups, locations))
}
selectedTagGroupEntry={selectedTagGroupEntry}
/>
@@ -528,7 +500,6 @@ function TagLibrary(props: Props) {
sortTagGroup={parentTagGroupUuid =>
setTagGroups(sortTagGroup(parentTagGroupUuid, tagGroups))
}
- collectTagsFromLocation={props.collectTagsFromLocation}
/>
)}
<TagLibraryMenu
@@ -539,11 +510,8 @@ function TagLibrary(props: Props) {
importTagGroups={(newGroups, replace) =>
setTagGroups(importTagGroups(newGroups, tagGroups, replace))
}
- exportTagGroups={tg => exportTagGroups(tg, props.settingsVersion)}
showCreateTagGroupDialog={showCreateTagGroupDialog}
- showNotification={showNotification}
- openURLExternally={props.openURLExternally}
- saveTagInLocation={props.saveTagInLocation}
+ saveTagInLocation={saveTagInLocation}
refreshTagsFromLocation={refreshTagsFromLocation}
/>
{Boolean(tagMenuAnchorEl) && (
@@ -554,7 +522,6 @@ function TagLibrary(props: Props) {
onClose={() => setTagMenuAnchorEl(null)}
showEditTagDialog={() => setIsEditTagDialogOpened(true)}
showDeleteTagDialog={() => setIsDeleteTagDialogOpened(true)}
- isReadOnlyMode={isReadOnly}
selectedTag={selectedTag}
/>
)}
@@ -568,13 +535,7 @@ function TagLibrary(props: Props) {
origTitle: string
) =>
setTagGroups(
- editTag(
- tag,
- parentTagGroupUuid,
- origTitle,
- tagGroups,
- props.locations
- )
+ editTag(tag, parentTagGroupUuid, origTitle, tagGroups, locations)
)
}
selectedTagGroupEntry={selectedTagGroupEntry}
@@ -619,54 +580,4 @@ function TagLibrary(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- // tagGroups: getTagGroups(state),
- tagBackgroundColor: getTagColor(state),
- tagTextColor: getTagTextColor(state),
- selectedEntries: getSelectedEntries(state),
- // allTags: getAllTags(state),
- isReadOnly: isReadOnlyMode(state),
- tagGroupCollapsed: state.settings.tagGroupCollapsed,
- locations: getLocations(state),
- saveTagInLocation: state.settings.saveTagInLocation,
- settingsVersion: state.settings.settingsVersion,
- language: getCurrentLanguage(state),
- isTagLibraryChanged: isTagLibraryChanged(state)
- };
-}
-
-function mapDispatchToProps(dispatch) {
- return bindActionCreators(
- {
- toggleTagGroup: SettingsActions.toggleTagGroup,
- // removeTagGroup: TagLibraryActions.removeTagGroup,
- // moveTagGroupUp: TagLibraryActions.moveTagGroupUp,
- // moveTagGroup: TagLibraryActions.moveTagGroup,
- // moveTagGroupDown: TagLibraryActions.moveTagGroupDown,
- // sortTagGroup: TagLibraryActions.sortTagGroup,
- // importTagGroups: TagLibraryActions.importTagGroups,
- // exportTagGroups: TagLibraryActions.exportTagGroups,
- // createTagGroup: TagLibraryActions.createTagGroup,
- // editTag: TagLibraryActions.editTag,
- // moveTag: TagLibraryActions.moveTag,
- // changeTagOrder: TagLibraryActions.changeTagOrder,
- // editTagGroup: TagLibraryActions.editTagGroup,
- // deleteTag: TagLibraryActions.deleteTag,
- // addTag: TagLibraryActions.addTag,
- addTags: TaggingActions.addTags,
- collectTagsFromLocation: TaggingActions.collectTagsFromLocation,
- openURLExternally: AppActions.openURLExternally,
- showNotification: AppActions.showNotification,
- switchLocationType: LocationActions.switchLocationType,
- switchCurrentLocationType: AppActions.switchCurrentLocationType
- },
- dispatch
- );
-}
-
-export default connect(
- mapStateToProps,
- mapDispatchToProps
- // @ts-ignore
-)(withStyles(styles)(TagLibrary));
+export default withStyles(styles)(TagLibrary);
diff --git a/app/components/TagsPreview.tsx b/app/components/TagsPreview.tsx
index dd3ae287c..22ee8fd1e 100644
--- a/app/components/TagsPreview.tsx
+++ b/app/components/TagsPreview.tsx
@@ -17,7 +17,7 @@
*/
import React, { useRef } from 'react';
-import { connect } from 'react-redux';
+import { useSelector } from 'react-redux';
import Tooltip from '-/components/Tooltip';
import { TS } from '-/tagspaces.namespace';
@@ -27,22 +27,19 @@ import {
getTagTextColor
} from '-/reducers/settings';
import i18n from '-/services/i18n';
-import {
- getAllTags,
- getTagColors,
- getTagLibrary
-} from '-/services/taglibrary-utils';
+import { getTagColors } from '-/services/taglibrary-utils';
interface Props {
tags: Array<TS.Tag>;
- // allTags?: Array<TS.Tag>;
- defaultTextColor?: string;
- defaultBackgroundColor?: string;
}
function TagsPreview(props: Props) {
- const { tags, defaultBackgroundColor, defaultTextColor } = props;
- const allTags = useRef<Array<TS.Tag>>(getAllTags(getTagLibrary()));
+ const defaultBackgroundColor = useSelector(getTagColor);
+ const defaultTextColor = useSelector(getTagTextColor);
+ const language = useSelector(getCurrentLanguage);
+
+ const { tags } = props;
+ // const allTags = useRef<Array<TS.Tag>>(getAllTags(getTagLibrary()));
if (!tags || tags.length < 1) {
return <></>;
}
@@ -104,13 +101,4 @@ function TagsPreview(props: Props) {
</Tooltip>
);
}
-
-function mapStateToProps(state) {
- return {
- // allTags: getAllTags(state),
- defaultBackgroundColor: getTagColor(state),
- defaultTextColor: getTagTextColor(state),
- language: getCurrentLanguage(state)
- };
-}
-export default connect(mapStateToProps)(TagsPreview);
+export default TagsPreview;
diff --git a/app/components/TagsSelect.tsx b/app/components/TagsSelect.tsx
index a2a1ef949..0775680a6 100644
--- a/app/components/TagsSelect.tsx
+++ b/app/components/TagsSelect.tsx
@@ -239,7 +239,6 @@ function TagsSelect(props: Props) {
selectedTag={selectedTag}
currentEntryPath={selectedEntryPath}
removeTags={handleRemoveTag}
- isReadOnlyMode={props.isReadOnlyMode}
/>
)}
</div>
diff --git a/app/components/UserDetailsPopover.tsx b/app/components/UserDetailsPopover.tsx
index bf0ca03fc..c1e0c9538 100644
--- a/app/components/UserDetailsPopover.tsx
+++ b/app/components/UserDetailsPopover.tsx
@@ -29,28 +29,29 @@ import Button from '@mui/material/Button';
import Auth from '@aws-amplify/auth';
import ExitToAppIcon from '@mui/icons-material/ExitToApp';
import withStyles from '@mui/styles/withStyles';
-import { connect } from 'react-redux';
+import { useSelector } from 'react-redux';
import { clearAllURLParams } from '-/utils/dom';
import i18n from '-/services/i18n';
import styles from '-/components/SidePanels.css';
import { Pro } from '-/pro';
+import { currentUser } from '-/reducers/app';
interface Props {
classes?: any;
theme?: any;
- user: CognitoUserInterface;
- // closeAllVerticalPanels: () => void;
onClose: () => void;
}
function UserDetailsPopover(props: Props) {
+ const { classes, theme, onClose } = props;
+ const cognitoUser: CognitoUserInterface = useSelector(currentUser);
const [isSetupTOTPOpened, setSetupTOTPOpened] = useState<boolean>(false);
const SetupTOTPDialog = Pro && Pro.UI ? Pro.UI.SetupTOTPDialog : false;
let email;
let initials;
- if (props.user && props.user.attributes && props.user.attributes.email) {
- ({ email } = props.user.attributes);
+ if (cognitoUser && cognitoUser.attributes && cognitoUser.attributes.email) {
+ ({ email } = cognitoUser.attributes);
const fullName = email.split('@')[0].split('.');
const firstName = fullName[0];
const lastName = fullName[fullName.length - 1];
@@ -65,12 +66,9 @@ function UserDetailsPopover(props: Props) {
const signOut = () => {
Auth.signOut();
clearAllURLParams();
- // props.closeAllVerticalPanels();
- props.onClose();
+ onClose();
};
- const { classes, theme } = props;
-
return (
<div
style={{
@@ -114,7 +112,7 @@ function UserDetailsPopover(props: Props) {
<SetupTOTPDialog
open={isSetupTOTPOpened}
onClose={() => setSetupTOTPOpened(false)}
- user={props.user}
+ user={cognitoUser}
confirmCallback={result => {
if (result) {
window.location.reload(); // TODO SOFTWARE_TOKEN_MFA is not refreshed in signed user without window.reload()
@@ -123,7 +121,7 @@ function UserDetailsPopover(props: Props) {
}}
/>
)}
- {'SOFTWARE_TOKEN_MFA'.indexOf(props.user.preferredMFA) === -1 ? (
+ {'SOFTWARE_TOKEN_MFA'.indexOf(cognitoUser.preferredMFA) === -1 ? (
<Tooltip title={i18n.t('core:setupTOTPHelp')}>
<Button
data-tid="setupTOTP"
@@ -148,7 +146,7 @@ function UserDetailsPopover(props: Props) {
className={classes.mainActionButton}
onClick={async () => {
try {
- await Auth.setPreferredMFA(props.user, 'NOMFA');
+ await Auth.setPreferredMFA(cognitoUser, 'NOMFA');
signOut();
} catch (error) {
console.error(error);
@@ -191,21 +189,4 @@ function UserDetailsPopover(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- user: state.app.user
- };
-}
-
-/* function mapDispatchToProps(dispatch) {
- return bindActionCreators(
- {
- closeAllVerticalPanels: AppActions.closeAllVerticalPanels
- },
- dispatch
- );
-} */
-
-export default connect(mapStateToProps)(
- withStyles(styles, { withTheme: true })(UserDetailsPopover)
-);
+export default withStyles(styles, { withTheme: true })(UserDetailsPopover);
diff --git a/app/components/WelcomePanel.tsx b/app/components/WelcomePanel.tsx
index 00e7cc38a..224fe1eb3 100644
--- a/app/components/WelcomePanel.tsx
+++ b/app/components/WelcomePanel.tsx
@@ -17,8 +17,7 @@
*/
import React, { useReducer } from 'react';
-import { connect } from 'react-redux';
-import { bindActionCreators } from 'redux';
+import { useSelector, useDispatch } from 'react-redux';
import withStyles from '@mui/styles/withStyles';
import Typography from '@mui/material/Typography';
import List from '@mui/material/List';
@@ -44,33 +43,23 @@ import {
KeyShortcutsIcon,
HelpIcon
} from '-/components/CommonIcons';
-import { actions as AppActions, getCurrentLocationId } from '-/reducers/app';
-import i18n from '-/services/i18n';
import {
- isFirstRun,
- getDesktopMode,
- actions as SettingsActions
-} from '-/reducers/settings';
+ actions as AppActions,
+ AppDispatch,
+ getCurrentLocationId
+} from '-/reducers/app';
+import i18n from '-/services/i18n';
+import { getDesktopMode } from '-/reducers/settings';
import Links from '-/content/links';
import { Pro } from '-/pro';
import { TS } from '-/tagspaces.namespace';
import { renderHistory } from '-/components/RenderHistory';
import HowToStart from '-/components/HowToStart';
+import { openURLExternally } from '-/services/utils-io';
interface Props {
theme: any;
classes: any;
- toggleNewFileDialog: () => void;
- toggleLocationDialog: () => void;
- toggleOpenLinkDialog: () => void;
- toggleKeysDialog: () => void;
- openURLExternally: (url: string, skipConfirmation?: boolean) => void;
- toggleAboutDialog: () => void;
- isDesktopMode: boolean;
- openFsEntry: (fsEntry: TS.FileSystemEntry) => void;
- openLink: (url: string, options: any) => void;
- openLocationById: (locationId: string) => void;
- currentLocationId: string;
}
export const styles: any = (theme: any) => ({
@@ -92,20 +81,26 @@ export const styles: any = (theme: any) => ({
});
function WelcomePanel(props: Props) {
- const {
- theme,
- classes,
- currentLocationId,
- openLink,
- openLocationById,
- openFsEntry,
- openURLExternally,
- toggleKeysDialog,
- toggleNewFileDialog,
- toggleLocationDialog,
- toggleOpenLinkDialog,
- isDesktopMode
- } = props;
+ const { theme, classes } = props;
+
+ const dispatch: AppDispatch = useDispatch();
+ const desktopMode = useSelector(getDesktopMode);
+ const currentLocationId = useSelector(getCurrentLocationId);
+
+ const toggleNewFileDialogDispatch = () =>
+ dispatch(AppActions.toggleNewFileDialog());
+ const toggleLocationDialogDispatch = () =>
+ dispatch(AppActions.toggleLocationDialog());
+ const toggleOpenLinkDialogDispatch = () =>
+ dispatch(AppActions.toggleOpenLinkDialog());
+ const toggleKeysDialogDispatch = () =>
+ dispatch(AppActions.toggleKeysDialog());
+ const openFsEntryDispatch = fsEntry =>
+ dispatch(AppActions.openFsEntry(fsEntry));
+ const openLinkDispatch = link => dispatch(AppActions.openLink(link));
+ const openLocationByIdDispatch = locationId =>
+ dispatch(AppActions.openLocationById(locationId));
+
const [ignored, forceUpdate] = useReducer(x => x + 1, 0);
const historyKeys = Pro && Pro.history ? Pro.history.historyKeys : {};
@@ -122,12 +117,12 @@ function WelcomePanel(props: Props) {
const showDelete = false;
const maxRecentItems = 5;
- function triggerOpenLocation() {
+ /*function triggerOpenLocation() {
const button = document.getElementById(
- isDesktopMode ? 'locationMenuButton' : 'mobileMenuButton'
+ desktopMode ? 'locationMenuButton' : 'mobileMenuButton'
);
button.click();
- }
+ }*/
function renderRecentItems() {
return (
@@ -149,9 +144,9 @@ function WelcomePanel(props: Props) {
fileOpenHistoryItems,
forceUpdate,
currentLocationId,
- openLink,
- openLocationById,
- openFsEntry,
+ openLinkDispatch,
+ openLocationByIdDispatch,
+ openFsEntryDispatch,
maxRecentItems,
showDelete
)}
@@ -170,10 +165,10 @@ function WelcomePanel(props: Props) {
historyKeys.fileEditKey,
fileEditHistoryItems,
forceUpdate,
- props.currentLocationId,
- props.openLink,
- props.openLocationById,
- props.openFsEntry,
+ currentLocationId,
+ openLinkDispatch,
+ openLocationByIdDispatch,
+ openFsEntryDispatch,
maxRecentItems,
showDelete
)}
@@ -192,10 +187,10 @@ function WelcomePanel(props: Props) {
historyKeys.folderOpenKey,
folderOpenHistoryItems,
forceUpdate,
- props.currentLocationId,
- props.openLink,
- props.openLocationById,
- props.openFsEntry,
+ currentLocationId,
+ openLinkDispatch,
+ openLocationByIdDispatch,
+ openFsEntryDispatch,
maxRecentItems,
showDelete
)}
@@ -227,7 +222,7 @@ function WelcomePanel(props: Props) {
role="button"
aria-hidden="true"
tabIndex={0}
- onClick={props.toggleAboutDialog}
+ onClick={() => dispatch(AppActions.toggleAboutDialog())}
>
<img src={WelcomeLogo} alt="Organize your files" />
</div>
@@ -240,7 +235,7 @@ function WelcomePanel(props: Props) {
className={classes.listItem}
/>
</ListItem> */}
- <ListItem onClick={toggleNewFileDialog}>
+ <ListItem onClick={toggleNewFileDialogDispatch}>
<ListItemIcon>
<CreateFileIcon />
</ListItemIcon>
@@ -249,7 +244,7 @@ function WelcomePanel(props: Props) {
className={classes.listItem}
/>
</ListItem>
- <ListItem onClick={toggleLocationDialog}>
+ <ListItem onClick={toggleLocationDialogDispatch}>
<ListItemIcon>
<LocalLocationIcon />
</ListItemIcon>
@@ -258,7 +253,7 @@ function WelcomePanel(props: Props) {
className={classes.listItem}
/>
</ListItem>
- <ListItem onClick={toggleOpenLinkDialog}>
+ <ListItem onClick={toggleOpenLinkDialogDispatch}>
<ListItemIcon>
<OpenLinkIcon />
</ListItemIcon>
@@ -281,7 +276,7 @@ function WelcomePanel(props: Props) {
className={classes.listItem}
/>
</ListItem>
- <ListItem onClick={toggleKeysDialog}>
+ <ListItem onClick={toggleKeysDialogDispatch}>
<ListItemIcon>
<KeyShortcutsIcon />
</ListItemIcon>
@@ -409,7 +404,7 @@ function WelcomePanel(props: Props) {
>
{renderQuickLinks()}
</Grid>
- {isDesktopMode && (
+ {desktopMode && (
<Grid item xs="auto" style={{ height: '100%' }}>
<div
style={{
@@ -422,7 +417,7 @@ function WelcomePanel(props: Props) {
backgroundColor: theme.palette.background.default
}}
>
- <HowToStart openURLExternally={openURLExternally} />
+ <HowToStart />
</div>
</Grid>
)}
@@ -448,33 +443,4 @@ function WelcomePanel(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- isFirstRun: isFirstRun(state),
- isDesktopMode: getDesktopMode(state),
- currentLocationId: getCurrentLocationId(state)
- };
-}
-
-function mapActionCreatorsToProps(dispatch) {
- return bindActionCreators(
- {
- setFirstRun: SettingsActions.setFirstRun,
- toggleNewFileDialog: AppActions.toggleNewFileDialog,
- toggleLocationDialog: AppActions.toggleLocationDialog,
- toggleOpenLinkDialog: AppActions.toggleOpenLinkDialog,
- openURLExternally: AppActions.openURLExternally,
- toggleKeysDialog: AppActions.toggleKeysDialog,
- toggleAboutDialog: AppActions.toggleAboutDialog,
- openFsEntry: AppActions.openFsEntry,
- openLink: AppActions.openLink,
- openLocationById: AppActions.openLocationById
- },
- dispatch
- );
-}
-
-export default connect(
- mapStateToProps,
- mapActionCreatorsToProps
-)(withStyles(styles, { withTheme: true })(WelcomePanel));
+export default withStyles(styles, { withTheme: true })(WelcomePanel);
diff --git a/app/components/dialogs/AboutDialog.tsx b/app/components/dialogs/AboutDialog.tsx
index d1c8a16eb..43bcf6549 100644
--- a/app/components/dialogs/AboutDialog.tsx
+++ b/app/components/dialogs/AboutDialog.tsx
@@ -38,10 +38,10 @@ import useMediaQuery from '@mui/material/useMediaQuery';
import useTheme from '@mui/styles/useTheme';
import AppConfig from '-/AppConfig';
import { Fullscreen } from '@mui/icons-material';
+import { openURLExternally } from '-/services/utils-io';
interface Props {
open: boolean;
- openURLExternally: (url: string, skipConfirmation?: boolean) => void;
toggleLicenseDialog: () => void;
toggleThirdPartyLibsDialog: () => void;
onClose: () => void;
@@ -62,7 +62,7 @@ function AboutDialog(props: Props) {
function checkForUpdates() {
if (updateAvailable) {
- props.openURLExternally(Links.links.downloadURL, true);
+ openURLExternally(Links.links.downloadURL, true);
} else {
getLastVersionPromise()
.then(lastVersion => {
@@ -187,7 +187,7 @@ function AboutDialog(props: Props) {
size="small"
color="primary"
onClick={() => {
- props.openURLExternally(imprintURL, true);
+ openURLExternally(imprintURL, true);
}}
>
Imprint
@@ -198,7 +198,7 @@ function AboutDialog(props: Props) {
size="small"
color="primary"
onClick={() => {
- props.openURLExternally(privacyURL, true);
+ openURLExternally(privacyURL, true);
}}
>
Privacy Policy
@@ -208,7 +208,7 @@ function AboutDialog(props: Props) {
size="small"
color="primary"
onClick={() => {
- props.openURLExternally(Links.links.changelogURL, true);
+ openURLExternally(Links.links.changelogURL, true);
}}
>
Changelog
@@ -231,7 +231,7 @@ function AboutDialog(props: Props) {
data-tid="checkForUpdates"
title={i18n.t('core:checkForNewVersion')}
onClick={() => {
- props.openURLExternally(Links.links.productsOverview, true);
+ openURLExternally(Links.links.productsOverview, true);
}}
color="primary"
// variant="outlined"
diff --git a/app/components/dialogs/AddRemoveTagsDialog.tsx b/app/components/dialogs/AddRemoveTagsDialog.tsx
index eb71a1c9a..39aaf2ce9 100644
--- a/app/components/dialogs/AddRemoveTagsDialog.tsx
+++ b/app/components/dialogs/AddRemoveTagsDialog.tsx
@@ -17,21 +17,20 @@
*/
import React, { useState } from 'react';
+import { useDispatch } from 'react-redux';
import Button from '@mui/material/Button';
-import Paper, { PaperProps } from '@mui/material/Paper';
+import Paper from '@mui/material/Paper';
import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';
import DialogTitle from '@mui/material/DialogTitle';
import List from '@mui/material/List';
import ListItem from '@mui/material/ListItem';
import ListItemIcon from '@mui/material/ListItemIcon';
-import ListSubheader from '@mui/material/ListSubheader';
import FolderIcon from '@mui/icons-material/FolderOpen';
import FileIcon from '@mui/icons-material/InsertDriveFileOutlined';
import Typography from '@mui/material/Typography';
import Dialog from '@mui/material/Dialog';
import DraggablePaper from '-/components/DraggablePaper';
-import AppConfig from '-/AppConfig';
import TagsSelect from '../TagsSelect';
import i18n from '-/services/i18n';
import {
@@ -43,17 +42,19 @@ import { TS } from '-/tagspaces.namespace';
import DialogCloseButton from '-/components/dialogs/DialogCloseButton';
import useTheme from '@mui/styles/useTheme';
import useMediaQuery from '@mui/material/useMediaQuery';
+import TaggingActions from '-/reducers/tagging-actions';
+import { AppDispatch } from '-/reducers/app';
interface Props {
open: boolean;
selectedEntries: Array<any>;
onClose: (clearSelection?: boolean) => void;
- addTags: (paths: Array<string>, tags: Array<TS.Tag>) => void;
removeTags: (paths: Array<string>, tags: Array<TS.Tag>) => void;
removeAllTags: (paths: Array<string>) => void;
}
function AddRemoveTagsDialog(props: Props) {
+ const dispatch: AppDispatch = useDispatch();
const [newlyAddedTags, setNewlyAddedTags] = useState<Array<TS.Tag>>([]);
const handleChange = (name: string, value: Array<TS.Tag>, action: string) => {
@@ -78,9 +79,11 @@ function AddRemoveTagsDialog(props: Props) {
const addTags = () => {
if (props.selectedEntries && props.selectedEntries.length > 0) {
- props.addTags(
- selectedEntries.map(entry => entry.path),
- newlyAddedTags
+ dispatch(
+ TaggingActions.addTags(
+ selectedEntries.map(entry => entry.path),
+ newlyAddedTags
+ )
);
}
onCloseDialog(true);
diff --git a/app/components/dialogs/AddTagToTagGroupDialog.tsx b/app/components/dialogs/AddTagToTagGroupDialog.tsx
index 86f748a40..0593694a9 100644
--- a/app/components/dialogs/AddTagToTagGroupDialog.tsx
+++ b/app/components/dialogs/AddTagToTagGroupDialog.tsx
@@ -17,7 +17,7 @@
*/
import React, { useState } from 'react';
-import { useSelector } from 'react-redux';
+import { useSelector, useDispatch } from 'react-redux';
import Button from '@mui/material/Button';
import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';
@@ -32,20 +32,19 @@ import DialogCloseButton from '-/components/dialogs/DialogCloseButton';
import i18n from '-/services/i18n';
import { getTagColor, getTagTextColor } from '-/reducers/settings';
import { TS } from '-/tagspaces.namespace';
-// import useTheme from '@mui/styles/useTheme';
-// import useMediaQuery from '@mui/material/useMediaQuery';
import { getTagLibrary } from '-/services/taglibrary-utils';
+import { actions as AppActions, AppDispatch } from '-/reducers/app';
interface Props {
open: boolean;
onClose: () => void;
- addTag: (tag: TS.Tag, uuid: string) => void;
selectedTag: TS.Tag;
defaultBackgroundColor?: string;
defaultTextColor?: string;
}
function AddTagToTagGroupDialog(props: Props) {
+ const dispatch: AppDispatch = useDispatch();
const [tagGroup, setTagGroup] = useState<string>(undefined);
const defaultBackgroundColor = useSelector(getTagColor);
const defaultTextColor = useSelector(getTagTextColor);
@@ -62,7 +61,7 @@ function AddTagToTagGroupDialog(props: Props) {
if (!selectedTag.color) {
selectedTag.color = defaultBackgroundColor;
}
- props.addTag(selectedTag, tagGroup);
+ dispatch(AppActions.addTag(selectedTag, tagGroup));
props.onClose();
};
diff --git a/app/components/dialogs/CreateDirectoryDialog.tsx b/app/components/dialogs/CreateDirectoryDialog.tsx
index af4ddf485..36498225c 100644
--- a/app/components/dialogs/CreateDirectoryDialog.tsx
+++ b/app/components/dialogs/CreateDirectoryDialog.tsx
@@ -17,8 +17,7 @@
*/
import React, { useState, useEffect, useRef } from 'react';
-import { connect } from 'react-redux';
-import { bindActionCreators } from 'redux';
+import { useDispatch } from 'react-redux';
import Button from '@mui/material/Button';
import TextField from '@mui/material/TextField';
import DialogActions from '@mui/material/DialogActions';
@@ -28,26 +27,21 @@ import FormControl from '@mui/material/FormControl';
import FormHelperText from '@mui/material/FormHelperText';
import Dialog from '@mui/material/Dialog';
import i18n from '-/services/i18n';
-import { actions as AppActions } from '-/reducers/app';
+import { actions as AppActions, AppDispatch } from '-/reducers/app';
import { joinPaths } from '@tagspaces/tagspaces-common/paths';
import DialogCloseButton from '-/components/dialogs/DialogCloseButton';
import PlatformIO from '-/services/platform-facade';
-import useTheme from '@mui/styles/useTheme';
-import useMediaQuery from '@mui/material/useMediaQuery';
interface Props {
open: boolean;
onClose: () => void;
selectedDirectoryPath: string;
- createDirectory: (
- directoryPath: string,
- reflect: boolean
- ) => Promise<boolean>;
callback?: (newDirPath: string) => void;
reflect?: boolean;
}
function CreateDirectoryDialog(props: Props) {
+ const dispatch: AppDispatch = useDispatch();
const [inputError, setInputError] = useState(false);
const isFirstRun = useRef(true);
const [disableConfirmButton, setDisableConfirmButton] = useState(true);
@@ -81,13 +75,16 @@ function CreateDirectoryDialog(props: Props) {
props.selectedDirectoryPath,
name
);
- props
- .createDirectory(dirPath, reflect !== undefined ? reflect : true)
- .then(() => {
- if (props.callback) {
- props.callback(dirPath);
- }
- });
+ dispatch(
+ AppActions.createDirectory(
+ dirPath,
+ reflect !== undefined ? reflect : true
+ )
+ ).then(() => {
+ if (props.callback) {
+ props.callback(dirPath);
+ }
+ });
resetState();
props.onClose();
}
@@ -166,18 +163,4 @@ function CreateDirectoryDialog(props: Props) {
);
}
-function mapActionCreatorsToProps(dispatch) {
- //: Dispatch<CreateDirectoryAction>) {
- return bindActionCreators(
- {
- createDirectory: AppActions.createDirectory
- },
- dispatch
- );
-}
-
-export default connect(
- undefined,
- mapActionCreatorsToProps
- // @ts-ignore
-)(CreateDirectoryDialog);
+export default CreateDirectoryDialog;
diff --git a/app/components/dialogs/CreateEditLocationDialog.tsx b/app/components/dialogs/CreateEditLocationDialog.tsx
index 1ccb5ab19..c9b7b1d2a 100644
--- a/app/components/dialogs/CreateEditLocationDialog.tsx
+++ b/app/components/dialogs/CreateEditLocationDialog.tsx
@@ -42,8 +42,7 @@ import RemoveIcon from '@mui/icons-material/RemoveCircleOutline';
import IdIcon from '@mui/icons-material/Abc';
import InputAdornment from '@mui/material/InputAdornment';
import IconButton from '@mui/material/IconButton';
-import { bindActionCreators } from 'redux';
-import { connect } from 'react-redux';
+import { useSelector, useDispatch } from 'react-redux';
import { locationType } from '@tagspaces/tagspaces-common/misc';
import AppConfig from '-/AppConfig';
import {
@@ -64,7 +63,11 @@ import DialogCloseButton from '-/components/dialogs/DialogCloseButton';
import InfoIcon from '-/components/InfoIcon';
import { ProLabel, BetaLabel, ProTooltip } from '-/components/HelperComponents';
import { actions as LocationActions, getLocations } from '-/reducers/locations';
-import { NotificationTypes, actions as AppActions } from '-/reducers/app';
+import {
+ NotificationTypes,
+ actions as AppActions,
+ AppDispatch
+} from '-/reducers/app';
import { getPersistTagsInSidecarFile, isDevMode } from '-/reducers/settings';
import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
import { actions as LocationIndexActions } from '-/reducers/location-index';
@@ -85,26 +88,20 @@ const styles: any = theme => ({
interface Props {
location?: TS.Location;
- locations: Array<TS.Location>;
open: boolean;
onClose: () => void;
classes: any;
- addLocation: (location: TS.Location, openAfterCreate?: boolean) => void;
editLocation?: (location: TS.Location) => void;
- isPersistTagsInSidecar: boolean;
- createLocationIndex: (location: TS.Location) => void;
- showNotification: (
- text: string,
- notificationType?: string, // NotificationTypes
- autohide?: boolean
- ) => void;
- isDevMode: boolean;
}
function CreateEditLocationDialog(props: Props) {
+ const dispatch: AppDispatch = useDispatch();
+ const isPersistTagsInSidecar = useSelector(getPersistTagsInSidecarFile);
+ const locations: Array<TS.Location> = useSelector(getLocations);
+ const devMode: boolean = useSelector(isDevMode);
const IgnorePatternDialog =
Pro && Pro.UI ? Pro.UI.IgnorePatternDialog : false;
- const { location, showNotification, locations } = props;
+ const { location } = props;
const [showSecretAccessKey, setShowSecretAccessKey] = useState<boolean>(
false
);
@@ -265,9 +262,11 @@ function CreateEditLocationDialog(props: Props) {
if (!locations.some(ln => ln.uuid === newId)) {
setNewUuid(newId);
} else {
- showNotification(
- 'Location with this ID already exists',
- NotificationTypes.error
+ dispatch(
+ AppActions.showNotification(
+ 'Location with this ID already exists',
+ NotificationTypes.error
+ )
);
}
}
@@ -416,8 +415,8 @@ function CreateEditLocationDialog(props: Props) {
loc = { ...loc, persistTagsInSidecarFile };
}
- if (!props.location && props.addLocation) {
- props.addLocation(loc);
+ if (!props.location) {
+ dispatch(LocationActions.addLocation(loc));
} else if (props.editLocation) {
loc.newuuid = newuuid;
props.editLocation(loc);
@@ -502,7 +501,7 @@ function CreateEditLocationDialog(props: Props) {
const currentTagsSetting =
props.location && props.location.persistTagsInSidecarFile !== null
? location.persistTagsInSidecarFile
- : props.isPersistTagsInSidecar;
+ : isPersistTagsInSidecar;
const disableLocationTypeSwitch: boolean = props.location !== undefined;
@@ -566,7 +565,7 @@ function CreateEditLocationDialog(props: Props) {
<MenuItem key="TYPE_CLOUD" value={locationType.TYPE_CLOUD}>
{i18n.t('core:objectStorage') + ' (AWS, MinIO, Wasabi,...)'}
</MenuItem>
- {Pro && props.isDevMode && (
+ {Pro && devMode && (
<MenuItem
key="TYPE_WEBDAV"
value={locationType.TYPE_WEBDAV}
@@ -628,7 +627,9 @@ function CreateEditLocationDialog(props: Props) {
content={i18n.t('core:fullTextIndexRegenerate')}
confirmCallback={result => {
if (result) {
- props.createLocationIndex(location);
+ dispatch(
+ LocationIndexActions.createLocationIndex(location)
+ );
} else {
setFullTextIndexConfirmDialogOpened(false);
}
@@ -1019,26 +1020,4 @@ function CreateEditLocationDialog(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- isPersistTagsInSidecar: getPersistTagsInSidecarFile(state),
- locations: getLocations(state),
- isDevMode: isDevMode(state)
- };
-}
-
-function mapDispatchToProps(dispatch) {
- return bindActionCreators(
- {
- addLocation: LocationActions.addLocation,
- createLocationIndex: LocationIndexActions.createLocationIndex,
- showNotification: AppActions.showNotification
- },
- dispatch
- );
-}
-
-export default connect(
- mapStateToProps,
- mapDispatchToProps
-)(withStyles(styles)(CreateEditLocationDialog));
+export default withStyles(styles)(CreateEditLocationDialog);
diff --git a/app/components/dialogs/EditTagGroupDialog.tsx b/app/components/dialogs/EditTagGroupDialog.tsx
index a3e4e1b9b..74080dc7a 100644
--- a/app/components/dialogs/EditTagGroupDialog.tsx
+++ b/app/components/dialogs/EditTagGroupDialog.tsx
@@ -28,7 +28,7 @@ import Switch from '@mui/material/Switch';
import Dialog from '@mui/material/Dialog';
import Select from '@mui/material/Select';
import MenuItem from '@mui/material/MenuItem';
-import { connect } from 'react-redux';
+import { useSelector } from 'react-redux';
import ColorPickerDialog from './ColorPickerDialog';
import i18n from '-/services/i18n';
import TransparentBackground from '../TransparentBackground';
@@ -36,8 +36,7 @@ import { TS } from '-/tagspaces.namespace';
import { getLocations } from '-/reducers/locations';
import { Pro } from '-/pro';
import DialogCloseButton from '-/components/dialogs/DialogCloseButton';
-import useTheme from '@mui/styles/useTheme';
-import useMediaQuery from '@mui/material/useMediaQuery';
+import { getSaveTagInLocation } from '-/reducers/settings';
const defaultTagGroupLocation = 'TAG_LIBRARY';
@@ -46,11 +45,12 @@ interface Props {
editTagGroup: (tagGroup: TS.TagGroup) => void;
selectedTagGroupEntry: TS.TagGroup;
onClose: () => void;
- locations: Array<TS.Location>;
- saveTagInLocation: boolean;
}
function EditTagGroupDialog(props: Props) {
+ const { editTagGroup, selectedTagGroupEntry, open, onClose } = props;
+ const locations: Array<TS.Location> = useSelector(getLocations);
+ const saveTagInLocation: boolean = useSelector(getSaveTagInLocation);
const [displayColorPicker, setDisplayColorPicker] = useState<boolean>(false);
const [displayTextColorPicker, setDisplayTextColorPicker] = useState<boolean>(
false
@@ -58,14 +58,13 @@ function EditTagGroupDialog(props: Props) {
const [inputError, setInputError] = useState<boolean>(false);
const [applyChanges, setApplyChanges] = useState<boolean>(false);
const [locationId, setLocationId] = useState<string>(
- props.selectedTagGroupEntry.locationId ?? defaultTagGroupLocation
+ selectedTagGroupEntry.locationId ?? defaultTagGroupLocation
);
- const [title, setTitle] = useState<string>(props.selectedTagGroupEntry.title);
- const [color, setColor] = useState<string>(props.selectedTagGroupEntry.color);
+ const [title, setTitle] = useState<string>(selectedTagGroupEntry.title);
+ const [color, setColor] = useState<string>(selectedTagGroupEntry.color);
const [textcolor, setTextcolor] = useState<string>(
- props.selectedTagGroupEntry.textcolor
+ selectedTagGroupEntry.textcolor
);
- const { selectedTagGroupEntry, onClose } = props;
useEffect(() => {
handleValidation();
@@ -99,7 +98,7 @@ function EditTagGroupDialog(props: Props) {
if (selectedTagGroupEntry && selectedTagGroupEntry.children) {
if (Pro && locationId !== selectedTagGroupEntry.locationId) {
- const location: TS.Location = props.locations.find(
+ const location: TS.Location = locations.find(
l => l.uuid === selectedTagGroupEntry.locationId
);
if (location) {
@@ -109,7 +108,7 @@ function EditTagGroupDialog(props: Props) {
);
}
}
- props.editTagGroup({
+ editTagGroup({
...selectedTagGroupEntry,
title,
color,
@@ -187,7 +186,7 @@ function EditTagGroupDialog(props: Props) {
</FormHelperText>
)}
</FormControl>
- {props.saveTagInLocation && (
+ {saveTagInLocation && (
<FormControl fullWidth={true} error={inputError}>
<FormHelperText style={styles.helpText}>
{i18n.t('core:tagGroupLocation')}
@@ -204,7 +203,7 @@ function EditTagGroupDialog(props: Props) {
>
{i18n.t('core:tagLibrary')}
</MenuItem>
- {props.locations.map(location => (
+ {locations.map(location => (
<MenuItem key={location.uuid} value={location.uuid}>
{i18n.t('core:location') + ': ' + location.name}
</MenuItem>
@@ -273,7 +272,7 @@ function EditTagGroupDialog(props: Props) {
const renderActions = () => (
<DialogActions>
- <Button onClick={props.onClose}>{i18n.t('core:cancel')}</Button>
+ <Button onClick={onClose}>{i18n.t('core:cancel')}</Button>
<Button
disabled={disableConfirmButton()}
onClick={onConfirm}
@@ -290,9 +289,9 @@ function EditTagGroupDialog(props: Props) {
// const fullScreen = useMediaQuery(theme.breakpoints.down('md'));
return (
<Dialog
- open={props.open}
+ open={open}
// fullScreen={fullScreen}
- onClose={props.onClose}
+ onClose={onClose}
onKeyDown={event => {
if (event.key === 'Enter' || event.keyCode === 13) {
event.preventDefault();
@@ -310,11 +309,4 @@ function EditTagGroupDialog(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- locations: getLocations(state),
- saveTagInLocation: state.settings.saveTagInLocation
- };
-}
-
-export default connect(mapStateToProps)(EditTagGroupDialog);
+export default EditTagGroupDialog;
diff --git a/app/components/dialogs/FilePreviewDialog.tsx b/app/components/dialogs/FilePreviewDialog.tsx
index 56da10726..212e03baf 100644
--- a/app/components/dialogs/FilePreviewDialog.tsx
+++ b/app/components/dialogs/FilePreviewDialog.tsx
@@ -24,7 +24,11 @@ import Dialog from '@mui/material/Dialog';
import DialogCloseButton from '-/components/dialogs/DialogCloseButton';
import { extractContainingDirectoryPath } from '@tagspaces/tagspaces-common/paths';
import DraggablePaper from '-/components/DraggablePaper';
-import { actions as AppActions, OpenedEntry } from '-/reducers/app';
+import {
+ actions as AppActions,
+ AppDispatch,
+ OpenedEntry
+} from '-/reducers/app';
import { TS } from '-/tagspaces.namespace';
import { findExtensionsForEntry } from '-/services/utils-io';
import {
@@ -32,28 +36,26 @@ import {
getCurrentTheme,
getSupportedFileTypes
} from '-/reducers/settings';
-import { connect } from 'react-redux';
+import { useSelector, useDispatch } from 'react-redux';
import i18n from '-/services/i18n';
import FileView from '-/components/FileView';
import useEventListener from '-/utils/useEventListener';
import PlatformIO from '-/services/platform-facade';
import AppConfig from '-/AppConfig';
-import { bindActionCreators } from 'redux';
import { actions as LocationActions } from '-/reducers/locations';
interface Props {
open: boolean;
onClose: () => void;
fsEntry: TS.FileSystemEntry;
- supportedFileTypes: Array<any>;
- currentTheme: string;
- switchCurrentLocationType: (currentLocationId) => Promise<boolean>;
- switchLocationType: (locationId: string) => Promise<string | null>;
}
function FilePreviewDialog(props: Props) {
const { open = false, onClose, fsEntry } = props;
- // const [fileOpenerURL, setFileOpenerURL] = useState<string>('about:blank');
+ const dispatch: AppDispatch = useDispatch();
+ const language = useSelector(getCurrentLanguage);
+ const supportedFileTypes = useSelector(getSupportedFileTypes);
+ const currentTheme = useSelector(getCurrentTheme);
const fileViewer: MutableRefObject<HTMLIFrameElement> = useRef<
HTMLIFrameElement
>(null);
@@ -65,7 +67,7 @@ function FilePreviewDialog(props: Props) {
const openedFile: OpenedEntry = fsEntry
? findExtensionsForEntry(
fsEntry.uuid,
- props.supportedFileTypes,
+ supportedFileTypes,
fsEntry.path,
fsEntry.isFile
)
@@ -73,7 +75,6 @@ function FilePreviewDialog(props: Props) {
useEventListener('message', e => {
if (typeof e.data === 'string') {
- // console.log(e.data);
try {
const dataObj = JSON.parse(e.data);
if (dataObj.eventID === eventID.current) {
@@ -96,7 +97,6 @@ function FilePreviewDialog(props: Props) {
) {
case 'loadDefaultTextContent':
if (!openedFile || !openedFile.path) {
- // || openedFile.changed) {
break;
}
textFilePath = openedFile.path;
@@ -109,64 +109,64 @@ function FilePreviewDialog(props: Props) {
fileViewer.current.contentWindow.setTheme
) {
// @ts-ignore call setContent from iframe
- fileViewer.current.contentWindow.setTheme(props.currentTheme);
+ fileViewer.current.contentWindow.setTheme(currentTheme);
}
- // TODO make loading index.html for folders configurable
- // if (!this.state.currentEntry.isFile) {
- // textFilePath += '/index.html';
- // }
- props
- .switchLocationType(openedFile.locationId)
- .then(currentLocationId => {
- PlatformIO.loadTextFilePromise(
- textFilePath,
- data.preview ? data.preview : false
- )
- .then(content => {
- const UTF8_BOM = '\ufeff';
- if (content.indexOf(UTF8_BOM) === 0) {
- // eslint-disable-next-line no-param-reassign
- content = content.substr(1);
- }
- let fileDirectory = extractContainingDirectoryPath(
- textFilePath,
- PlatformIO.getDirSeparator()
+
+ dispatch(
+ LocationActions.switchLocationType(openedFile.locationId)
+ ).then((currentLocationId: string) => {
+ PlatformIO.loadTextFilePromise(
+ textFilePath,
+ data.preview ? data.preview : false
+ )
+ .then(content => {
+ const UTF8_BOM = '\ufeff';
+ if (content.indexOf(UTF8_BOM) === 0) {
+ content = content.substr(1);
+ }
+ let fileDirectory = extractContainingDirectoryPath(
+ textFilePath,
+ PlatformIO.getDirSeparator()
+ );
+ if (AppConfig.isWeb) {
+ fileDirectory =
+ extractContainingDirectoryPath(
+ // eslint-disable-next-line no-restricted-globals
+ location.href,
+ PlatformIO.getDirSeparator()
+ ) +
+ '/' +
+ fileDirectory;
+ }
+ if (
+ fileViewer &&
+ fileViewer.current &&
+ fileViewer.current.contentWindow &&
+ // @ts-ignore
+ fileViewer.current.contentWindow.setContent
+ ) {
+ // @ts-ignore call setContent from iframe
+ fileViewer.current.contentWindow.setContent(
+ content,
+ fileDirectory,
+ !openedFile.editMode
+ );
+ }
+ if (currentLocationId) {
+ dispatch(
+ AppActions.switchCurrentLocationType(currentLocationId)
);
- if (AppConfig.isWeb) {
- fileDirectory =
- extractContainingDirectoryPath(
- // eslint-disable-next-line no-restricted-globals
- location.href,
- PlatformIO.getDirSeparator()
- ) +
- '/' +
- fileDirectory;
- }
- if (
- fileViewer &&
- fileViewer.current &&
- fileViewer.current.contentWindow &&
- // @ts-ignore
- fileViewer.current.contentWindow.setContent
- ) {
- // @ts-ignore call setContent from iframe
- fileViewer.current.contentWindow.setContent(
- content,
- fileDirectory,
- !openedFile.editMode
- );
- }
- if (currentLocationId) {
- return props.switchCurrentLocationType(currentLocationId);
- }
- })
- .catch(err => {
- console.warn('Error loading text content ' + err);
- if (currentLocationId) {
- return props.switchCurrentLocationType(currentLocationId);
- }
- });
- });
+ }
+ })
+ .catch(err => {
+ console.warn('Error loading text content ' + err);
+ if (currentLocationId) {
+ dispatch(
+ AppActions.switchCurrentLocationType(currentLocationId)
+ );
+ }
+ });
+ });
break;
}
};
@@ -205,14 +205,14 @@ function FilePreviewDialog(props: Props) {
flexGrow: 1
}}
>
- <p>{props.fsEntry.path}</p>
+ <p>{fsEntry.path}</p>
<FileView
key="FileViewPreviewID"
openedFile={openedFile}
fileViewer={fileViewer}
fileViewerContainer={fileViewerContainer}
height={'90%'}
- currentTheme={props.currentTheme}
+ currentTheme={currentTheme}
eventID={eventID.current}
/>
</DialogContent>
@@ -220,26 +220,4 @@ function FilePreviewDialog(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- language: getCurrentLanguage(state),
- supportedFileTypes: getSupportedFileTypes(state),
- currentTheme: getCurrentTheme(state)
- };
-}
-
-function mapActionCreatorsToProps(dispatch) {
- return bindActionCreators(
- {
- switchCurrentLocationType: AppActions.switchCurrentLocationType,
- switchLocationType: LocationActions.switchLocationType
- },
- dispatch
- );
-}
-
-export default connect(
- mapStateToProps,
- mapActionCreatorsToProps
- // @ts-ignore
-)(FilePreviewDialog);
+export default FilePreviewDialog;
diff --git a/app/components/dialogs/FileUploadDialog.tsx b/app/components/dialogs/FileUploadDialog.tsx
index db365e9d1..c62f9f656 100644
--- a/app/components/dialogs/FileUploadDialog.tsx
+++ b/app/components/dialogs/FileUploadDialog.tsx
@@ -23,9 +23,8 @@ import DialogContent from '@mui/material/DialogContent';
import DialogTitle from '@mui/material/DialogTitle';
import Dialog from '@mui/material/Dialog';
import CloseIcon from '@mui/icons-material/Close';
-import { connect } from 'react-redux';
+import { useSelector, useDispatch } from 'react-redux';
import { cleanFrontDirSeparator } from '@tagspaces/tagspaces-common/paths';
-import { bindActionCreators } from 'redux';
import Typography from '@mui/material/Typography';
import Box from '@mui/material/Box';
import { LinearProgress, Grid, Tooltip } from '@mui/material';
@@ -34,6 +33,7 @@ import PlatformIO from '-/services/platform-facade';
import DraggablePaper from '-/components/DraggablePaper';
import {
actions as AppActions,
+ AppDispatch,
getCurrentDirectoryPerspective,
getDirectoryPath,
getProgress
@@ -43,26 +43,23 @@ import i18n from '-/services/i18n';
import DialogCloseButton from '-/components/dialogs/DialogCloseButton';
import { PerspectiveIDs } from '-/perspectives';
import { getCurrentLocation } from '-/reducers/locations';
-import { TS } from '-/tagspaces.namespace';
interface Props {
open: boolean;
- progress?: Array<any>;
title: string;
onClose: () => void;
- clearUploadDialog: () => void;
- currentDirectoryPerspective: string;
- currentDirectoryPath: string;
- currentLocation: TS.Location;
- loadDirectoryContent: (
- path: string,
- generateThumbnails: boolean,
- loadDirMeta?: boolean
- ) => void;
}
function FileUploadDialog(props: Props) {
- const { open = false, onClose } = props;
+ const { open = false, title, onClose } = props;
+ const dispatch: AppDispatch = useDispatch();
+ const progress = useSelector(getProgress);
+ const currentDirectoryPerspective = useSelector(
+ getCurrentDirectoryPerspective
+ );
+ const currentDirectoryPath = useSelector(getDirectoryPath);
+ const currentLocation = useSelector(getCurrentLocation);
+
const targetPath = React.useRef<string>(getTargetPath());
function LinearProgressWithLabel(prop) {
@@ -81,8 +78,8 @@ function FileUploadDialog(props: Props) {
}
const stopAll = () => {
- if (props.progress) {
- props.progress.map(fileProgress => {
+ if (progress) {
+ progress.map(fileProgress => {
const { abort } = fileProgress;
if (abort !== undefined && typeof abort === 'function') {
abort();
@@ -95,7 +92,7 @@ function FileUploadDialog(props: Props) {
let haveProgress = false;
function getTargetPath() {
- const pathProgress = props.progress.find(fileProgress => fileProgress.path);
+ const pathProgress = progress.find(fileProgress => fileProgress.path);
if (pathProgress) {
return pathProgress.path;
}
@@ -103,43 +100,38 @@ function FileUploadDialog(props: Props) {
}
function getTargetURL() {
- if (props.currentLocation) {
- if (props.currentLocation.endpointURL) {
+ if (currentLocation) {
+ if (currentLocation.endpointURL) {
return (
- (props.currentLocation.endpointURL.endsWith('/')
- ? props.currentLocation.endpointURL
- : props.currentLocation.endpointURL + '/') +
- (props.currentLocation.path
- ? cleanFrontDirSeparator(props.currentLocation.path)
+ (currentLocation.endpointURL.endsWith('/')
+ ? currentLocation.endpointURL
+ : currentLocation.endpointURL + '/') +
+ (currentLocation.path
+ ? cleanFrontDirSeparator(currentLocation.path)
: '') +
- (props.currentDirectoryPath
- ? cleanFrontDirSeparator(props.currentDirectoryPath)
+ (currentDirectoryPath
+ ? cleanFrontDirSeparator(currentDirectoryPath)
: '')
);
- } else if (
- props.currentLocation.region &&
- props.currentLocation.bucketName
- ) {
+ } else if (currentLocation.region && currentLocation.bucketName) {
return (
'https://s3.' +
- props.currentLocation.region +
+ currentLocation.region +
'.amazonaws.com' +
- (props.currentLocation.bucketName
- ? '/' + props.currentLocation.bucketName
- : '') +
- (props.currentLocation.path
- ? '/' + cleanFrontDirSeparator(props.currentLocation.path)
+ (currentLocation.bucketName ? '/' + currentLocation.bucketName : '') +
+ (currentLocation.path
+ ? '/' + cleanFrontDirSeparator(currentLocation.path)
: '') +
- (props.currentDirectoryPath
- ? '/' + cleanFrontDirSeparator(props.currentDirectoryPath)
+ (currentDirectoryPath
+ ? '/' + cleanFrontDirSeparator(currentDirectoryPath)
: '')
);
}
}
if (targetPath.current) {
return targetPath.current;
- } else if (props.currentDirectoryPath) {
- return props.currentDirectoryPath;
+ } else if (currentDirectoryPath) {
+ return currentDirectoryPath;
}
return '/';
}
@@ -162,10 +154,7 @@ function FileUploadDialog(props: Props) {
id="draggable-dialog-title"
>
{i18n.t(
- 'core:' +
- (props.title && props.title.length > 0
- ? props.title
- : 'importDialogTitle')
+ 'core:' + (title && title.length > 0 ? title : 'importDialogTitle')
)}
<DialogCloseButton testId="closeFileUploadTID" onClose={onClose} />
</DialogTitle>
@@ -178,8 +167,8 @@ function FileUploadDialog(props: Props) {
}}
>
<p>{i18n.t('core:moveCopyToPath') + ': ' + getTargetURL()}</p>
- {props.progress &&
- props.progress
+ {progress &&
+ progress
.sort((a, b) => ('' + a.path).localeCompare(b.path))
.map(fileProgress => {
const percentage = fileProgress.progress;
@@ -248,9 +237,11 @@ function FileUploadDialog(props: Props) {
data-tid="uploadCloseAndClearTID"
onClick={() => {
onClose();
- props.clearUploadDialog();
- if (props.currentDirectoryPerspective === PerspectiveIDs.GRID) {
- props.loadDirectoryContent(props.currentDirectoryPath, false);
+ dispatch(AppActions.clearUploadDialog());
+ if (currentDirectoryPerspective === PerspectiveIDs.GRID) {
+ dispatch(
+ AppActions.loadDirectoryContent(currentDirectoryPath, false)
+ );
}
}}
color="primary"
@@ -260,7 +251,7 @@ function FileUploadDialog(props: Props) {
)}
<Button
data-tid="uploadMinimizeDialogTID"
- onClick={props.onClose}
+ onClick={onClose}
color="primary"
>
{i18n.t('core:minimize')}
@@ -277,21 +268,8 @@ function FileUploadDialog(props: Props) {
function mapStateToProps(state) {
return {
- progress: getProgress(state),
- currentDirectoryPerspective: getCurrentDirectoryPerspective(state),
- currentDirectoryPath: getDirectoryPath(state),
currentLocation: getCurrentLocation(state)
};
}
-function mapDispatchToProps(dispatch) {
- return bindActionCreators(
- {
- clearUploadDialog: AppActions.clearUploadDialog,
- loadDirectoryContent: AppActions.loadDirectoryContent
- },
- dispatch
- );
-}
-
-export default connect(mapStateToProps, mapDispatchToProps)(FileUploadDialog);
+export default FileUploadDialog;
diff --git a/app/components/dialogs/ImportExportTagGroupsDialog.tsx b/app/components/dialogs/ImportExportTagGroupsDialog.tsx
index 8e7dee1ac..85d53627d 100644
--- a/app/components/dialogs/ImportExportTagGroupsDialog.tsx
+++ b/app/components/dialogs/ImportExportTagGroupsDialog.tsx
@@ -36,6 +36,7 @@ import { TS } from '-/tagspaces.namespace';
import DialogCloseButton from '-/components/dialogs/DialogCloseButton';
import useTheme from '@mui/styles/useTheme';
import useMediaQuery from '@mui/material/useMediaQuery';
+import { exportTagGroups } from '-/services/taglibrary-utils';
interface Props {
open: boolean;
@@ -44,7 +45,6 @@ interface Props {
dialogModeImport: boolean;
showNotification?: (text: string) => void;
importTagGroups: (taggroups: Array<TS.TagGroup>) => void;
- exportTagGroups: (taggroups: Array<TS.TagGroup>) => void;
}
function ImportExportTagGroupsDialog(props: Props) {
@@ -84,7 +84,7 @@ function ImportExportTagGroupsDialog(props: Props) {
showNotification(i18n.t('core:successfullyImportedGroupTags'));
}
} else {
- props.exportTagGroups(groupList);
+ exportTagGroups(groupList);
if (isFunc(showNotification)) {
showNotification(i18n.t('core:successfullyExportedGroupTags'));
}
diff --git a/app/components/dialogs/KeyboardDialog.tsx b/app/components/dialogs/KeyboardDialog.tsx
index ce80b5947..152286222 100644
--- a/app/components/dialogs/KeyboardDialog.tsx
+++ b/app/components/dialogs/KeyboardDialog.tsx
@@ -17,7 +17,7 @@
*/
import React from 'react';
-import { connect } from 'react-redux';
+import { useSelector } from 'react-redux';
import Button from '@mui/material/Button';
import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';
@@ -47,12 +47,12 @@ const styles = theme => ({
interface Props {
open: boolean;
classes: any;
- keyBindings: Array<any>;
onClose: () => void;
}
function KeyboardDialog(props: Props) {
- const { open, onClose, keyBindings, classes } = props;
+ const { open, onClose, classes } = props;
+ const keyBindings = useSelector(getKeyBindingObject);
const theme = useTheme();
const fullScreen = useMediaQuery(theme.breakpoints.down('md'));
return (
@@ -102,10 +102,4 @@ function KeyboardDialog(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- keyBindings: getKeyBindingObject(state)
- };
-}
-
-export default connect(mapStateToProps)(withStyles(styles)(KeyboardDialog));
+export default withStyles(styles)(KeyboardDialog);
diff --git a/app/components/dialogs/MoveCopyFilesDialog.tsx b/app/components/dialogs/MoveCopyFilesDialog.tsx
index 765f37e37..9b10201a5 100644
--- a/app/components/dialogs/MoveCopyFilesDialog.tsx
+++ b/app/components/dialogs/MoveCopyFilesDialog.tsx
@@ -1,25 +1,5 @@
-/**
- * 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/>.
- *
- */
-
import React, { useState, useRef, useReducer, useEffect } from 'react';
-import { bindActionCreators } from 'redux';
-import { connect } from 'react-redux';
-import { Progress } from 'aws-sdk/clients/s3';
+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';
@@ -41,6 +21,7 @@ import useTheme from '@mui/styles/useTheme';
import useMediaQuery from '@mui/material/useMediaQuery';
import {
actions as AppActions,
+ AppDispatch,
getDirectoryPath,
getSelectedEntries
} from '-/reducers/app';
@@ -57,56 +38,29 @@ import {
interface Props {
open: boolean;
onClose: (clearSelection?: boolean) => void;
- currentDirectoryPath: string | null;
- copyFiles: (
- files: Array<string>,
- destination: string,
- onUploadProgress?: (progress: Progress, abort: () => void) => void
- ) => void;
- copyDirs: (
- dirs: Array<any>,
- destination: string,
- onUploadProgress?: (progress: Progress, abort: () => void) => void
- ) => void;
- moveFiles: (files: Array<string>, destination: string) => void;
- moveDirs: (
- dirs: Array<any>,
- destination: string,
- onUploadProgress?: (progress: Progress, abort: () => void) => void
- ) => void;
- selectedEntries: Array<TS.FileSystemEntry>;
// force to move/copy different entries from selected
entries?: Array<TS.FileSystemEntry>;
- onUploadProgress: (progress: Progress, abort: () => void) => void;
- toggleUploadDialog: (title?) => void;
- resetProgress: () => void;
}
function MoveCopyFilesDialog(props: Props) {
- // const [disableConfirmButton, setDisableConfirmButton] = useState(true);
+ const dispatch: AppDispatch = useDispatch();
+
+ const selectedEntries: Array<TS.FileSystemEntry> = useSelector(
+ getSelectedEntries
+ );
+ const currentDirectoryPath: string | null = useSelector(getDirectoryPath);
const [targetPath, setTargetPath] = useState(
- props.currentDirectoryPath ? props.currentDirectoryPath : ''
+ currentDirectoryPath ? currentDirectoryPath : ''
);
const isCopy = useRef<boolean>(true);
const [entriesExistPath, setEntriesExistPath] = useState<string[]>(undefined);
const dirProp = useRef({});
const [ignored, forceUpdate] = useReducer(x => x + 1, 0);
- const { open, onClose } = props;
+ const { open, entries, onClose } = props;
+
+ let allEntries = entries && entries.length > 0 ? entries : selectedEntries;
- let allEntries =
- props.entries && props.entries.length > 0
- ? props.entries
- : props.selectedEntries;
- /*props.entries && props.entries.length > 0
- ? [
- ...props.entries,
- ...props.selectedEntries.filter(
- e => !props.entries.some(en => en.path === e.path)
- )
- ]
- : props.selectedEntries;*/
- //let selectedFiles = props.selectedFiles ? props.selectedFiles : [];
const selectedFiles = allEntries
? allEntries.filter(fsEntry => fsEntry.isFile).map(fsentry => fsentry.path)
: [];
@@ -187,42 +141,49 @@ function MoveCopyFilesDialog(props: Props) {
handleMoveFiles();
}
}
+
function handleCopyFiles() {
- //if (!disableConfirmButton) {
- props.resetProgress();
- props.toggleUploadDialog('copyEntriesTitle');
+ dispatch(AppActions.resetProgress());
+ dispatch(AppActions.toggleUploadDialog('copyEntriesTitle'));
if (selectedFiles.length > 0) {
- props.copyFiles(selectedFiles, targetPath, props.onUploadProgress);
- //setDisableConfirmButton(true);
+ dispatch(
+ IOActions.copyFiles(selectedFiles, targetPath, onUploadProgress)
+ );
setTargetPath('');
}
if (selectedDirs.length > 0) {
- props.copyDirs(
- getEntriesCount(selectedDirs),
- targetPath,
- props.onUploadProgress
+ dispatch(
+ IOActions.copyDirs(
+ getEntriesCount(selectedDirs),
+ targetPath,
+ onUploadProgress
+ )
);
}
- props.onClose(true);
+ onClose(true);
}
+ const onUploadProgress = (progress, abort, fileName) => {
+ dispatch(AppActions.onUploadProgress(progress, abort, fileName));
+ };
+
function handleMoveFiles() {
- // if (!disableConfirmButton) {
if (selectedFiles.length > 0) {
- props.moveFiles(selectedFiles, targetPath);
- // setDisableConfirmButton(true);
+ dispatch(IOActions.moveFiles(selectedFiles, targetPath));
setTargetPath('');
}
if (selectedDirs.length > 0) {
- props.resetProgress();
- props.toggleUploadDialog('moveEntriesTitle');
- props.moveDirs(
- getEntriesCount(selectedDirs),
- targetPath,
- props.onUploadProgress
+ dispatch(AppActions.resetProgress());
+ dispatch(AppActions.toggleUploadDialog('moveEntriesTitle'));
+ dispatch(
+ IOActions.moveDirs(
+ getEntriesCount(selectedDirs),
+ targetPath,
+ onUploadProgress
+ )
);
}
- props.onClose(true);
+ onClose(true);
}
/*function selectDirectory() {
@@ -236,10 +197,6 @@ function MoveCopyFilesDialog(props: Props) {
});
}*/
- function onCloseDialog() {
- onClose();
- }
-
function formatFileExist(entries) {
if (entries !== undefined) {
return entries.join(', ');
@@ -252,7 +209,7 @@ function MoveCopyFilesDialog(props: Props) {
return (
<Dialog
open={open}
- onClose={onClose}
+ onClose={() => onClose()}
keepMounted
scroll="paper"
aria-labelledby="draggable-dialog-title"
@@ -261,7 +218,7 @@ function MoveCopyFilesDialog(props: Props) {
>
<DialogTitle style={{ cursor: 'move' }} id="draggable-dialog-title">
{i18n.t('core:copyMoveEntriesTitle')}
- <DialogCloseButton testId="closeMCFilesTID" onClose={onCloseDialog} />
+ <DialogCloseButton testId="closeMCFilesTID" onClose={() => onClose()} />
</DialogTitle>
<DialogContent style={{ overflow: 'hidden' }}>
<Typography variant="subtitle2">
@@ -306,13 +263,13 @@ function MoveCopyFilesDialog(props: Props) {
)}
<DirectoryListView
setTargetDir={setTargetPath}
- currentDirectoryPath={props.currentDirectoryPath}
+ currentDirectoryPath={currentDirectoryPath}
/>
</DialogContent>
<DialogActions
style={fullScreen ? { padding: '10px 30px 30px 30px' } : {}}
>
- <Button data-tid="closeMoveCopyDialog" onClick={() => props.onClose()}>
+ <Button data-tid="closeMoveCopyDialog" onClick={() => onClose()}>
{i18n.t('core:cancel')}
</Button>
<Tooltip
@@ -323,7 +280,7 @@ function MoveCopyFilesDialog(props: Props) {
disabled={
!targetPath ||
AppConfig.isAndroid ||
- targetPath === props.currentDirectoryPath
+ targetPath === currentDirectoryPath
}
onClick={() => handleCopyMove(false)}
color="primary"
@@ -360,7 +317,7 @@ function MoveCopyFilesDialog(props: Props) {
<Button
onClick={() => handleCopyMove(true)}
data-tid="confirmCopyFiles"
- disabled={!targetPath || targetPath === props.currentDirectoryPath}
+ disabled={!targetPath || targetPath === currentDirectoryPath}
color="primary"
variant="contained"
>
@@ -371,29 +328,4 @@ function MoveCopyFilesDialog(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- selectedEntries: getSelectedEntries(state),
- currentDirectoryPath: getDirectoryPath(state)
- };
-}
-
-function mapActionCreatorsToProps(dispatch) {
- return bindActionCreators(
- {
- copyFiles: IOActions.copyFiles,
- moveFiles: IOActions.moveFiles,
- moveDirs: IOActions.moveDirs,
- copyDirs: IOActions.copyDirs,
- toggleUploadDialog: AppActions.toggleUploadDialog,
- onUploadProgress: AppActions.onUploadProgress,
- resetProgress: AppActions.resetProgress
- },
- dispatch
- );
-}
-
-export default connect(
- mapStateToProps,
- mapActionCreatorsToProps
-)(MoveCopyFilesDialog);
+export default MoveCopyFilesDialog;
diff --git a/app/components/dialogs/OnboardingDialog.tsx b/app/components/dialogs/OnboardingDialog.tsx
index 62615d48f..7f9828fd5 100644
--- a/app/components/dialogs/OnboardingDialog.tsx
+++ b/app/components/dialogs/OnboardingDialog.tsx
@@ -17,8 +17,7 @@
*/
import React, { useState } from 'react';
-import { connect } from 'react-redux';
-import { bindActionCreators } from 'redux';
+import { useSelector, useDispatch } from 'react-redux';
import SwipeableViews from 'react-swipeable-views';
import Button from '@mui/material/Button';
import DialogActions from '@mui/material/DialogActions';
@@ -33,60 +32,66 @@ import ToggleButton from '@mui/material/ToggleButton';
import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';
import MobileStepper from '@mui/material/MobileStepper';
import Dialog from '@mui/material/Dialog';
-import AppConfig from '-/AppConfig';
import BrowserExtension from '-/assets/images/collectcontent.svg';
import WizardFinished from '-/assets/images/computer-desk.svg';
import ChooseTagging from '-/assets/images/abacus.svg';
import NewLook from '-/assets/images/desktop.svg';
import i18n from '-/services/i18n';
import {
- isFirstRun,
getCurrentTheme,
getPersistTagsInSidecarFile,
actions as SettingsActions
} from '-/reducers/settings';
-import { actions as AppActions } from '-/reducers/app';
import DialogCloseButton from '-/components/dialogs/DialogCloseButton';
import Links from '-/content/links';
import useTheme from '@mui/styles/useTheme';
import useMediaQuery from '@mui/material/useMediaQuery';
+import { openURLExternally } from '-/services/utils-io';
+import { AppDispatch } from '-/reducers/app';
interface Props {
classes: any;
open: boolean;
- isPersistTagsInSidecar: boolean;
- currentTheme: string;
- // setFirstRun: (isFirstRun: boolean) => void,
- setPersistTagsInSidecarFile: (isPersistTagsInSidecar: boolean) => void;
- setCurrentTheme: (theme: string) => void;
- openURLExternally: (url: string, skipConfirmation?: boolean) => void;
onClose: () => void;
}
function OnboardingDialog(props: Props) {
const [activeStep, setActiveStep] = useState(0);
const { open, onClose } = props;
+ const isPersistTagsInSidecar = useSelector(getPersistTagsInSidecarFile);
+ const currentTheme = useSelector(getCurrentTheme);
+ const dispatch: AppDispatch = useDispatch();
+ const setPersistTagsInSidecarFile = isPersistTagsInSidecar => {
+ dispatch(
+ SettingsActions.setPersistTagsInSidecarFile(isPersistTagsInSidecar)
+ );
+ };
const maxSteps = 4;
- function handleNext() {
+ const setCurrentTheme = theme => {
+ dispatch(SettingsActions.setCurrentTheme(theme));
+ };
+
+ const handleNext = () => {
setActiveStep(step => step + 1);
- }
+ };
- function handleBack() {
+ const handleBack = () => {
setActiveStep(step => step - 1);
- }
+ };
- function handleStepChange(step: number) {
+ const handleStepChange = step => {
setActiveStep(step);
- }
+ };
- function toggleTaggingType() {
- props.setPersistTagsInSidecarFile(!props.isPersistTagsInSidecar);
- }
+ const toggleTaggingType = () => {
+ setPersistTagsInSidecarFile(!isPersistTagsInSidecar);
+ };
const theme = useTheme();
const fullScreen = useMediaQuery(theme.breakpoints.down('md'));
+
return (
<Dialog
open={open}
@@ -126,10 +131,10 @@ function OnboardingDialog(props: Props) {
<Typography variant="h6">Try our dark theme!</Typography>
<Typography variant="h6">&nbsp;</Typography>
<ToggleButtonGroup
- value={props.currentTheme}
+ value={currentTheme}
exclusive
onChange={(event, theme) => {
- props.setCurrentTheme(theme);
+ setCurrentTheme(theme);
}}
style={{ boxShadow: 'none' }}
>
@@ -161,7 +166,7 @@ function OnboardingDialog(props: Props) {
>
<FormControlLabel
value="false"
- control={<Radio checked={!props.isPersistTagsInSidecar} />}
+ control={<Radio checked={!isPersistTagsInSidecar} />}
label={
<Typography
variant="subtitle1"
@@ -178,7 +183,7 @@ function OnboardingDialog(props: Props) {
<FormControlLabel
style={{ marginTop: 20 }}
value="true"
- control={<Radio checked={props.isPersistTagsInSidecar} />}
+ control={<Radio checked={isPersistTagsInSidecar} />}
label={
<Typography
variant="subtitle1"
@@ -231,7 +236,7 @@ function OnboardingDialog(props: Props) {
<Button
style={{ marginTop: 20 }}
onClick={() => {
- props.openURLExternally(Links.links.webClipper, true);
+ openURLExternally(Links.links.webClipper, true);
}}
variant="contained"
color="primary"
@@ -269,7 +274,7 @@ function OnboardingDialog(props: Props) {
activeStep === maxSteps - 1 ? (
<Button
size="small"
- onClick={props.onClose}
+ onClick={onClose}
variant="contained"
color="primary"
style={{ marginLeft: 5 }}
@@ -302,27 +307,4 @@ function OnboardingDialog(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- isFirstRun: isFirstRun(state),
- isPersistTagsInSidecar: getPersistTagsInSidecarFile(state),
- currentTheme: getCurrentTheme(state)
- };
-}
-
-function mapActionCreatorsToProps(dispatch) {
- return bindActionCreators(
- {
- setFirstRun: SettingsActions.setFirstRun,
- setPersistTagsInSidecarFile: SettingsActions.setPersistTagsInSidecarFile,
- setCurrentTheme: SettingsActions.setCurrentTheme,
- openURLExternally: AppActions.openURLExternally
- },
- dispatch
- );
-}
-
-export default connect(
- mapStateToProps,
- mapActionCreatorsToProps
-)(OnboardingDialog);
+export default OnboardingDialog;
diff --git a/app/components/dialogs/ProTeaserDialog.tsx b/app/components/dialogs/ProTeaserDialog.tsx
index 44fc6aa4e..d7dd34f3e 100644
--- a/app/components/dialogs/ProTeaserDialog.tsx
+++ b/app/components/dialogs/ProTeaserDialog.tsx
@@ -25,26 +25,23 @@ import DialogTitle from '@mui/material/DialogTitle';
import Typography from '@mui/material/Typography';
import MobileStepper from '@mui/material/MobileStepper';
import Dialog from '@mui/material/Dialog';
-import AppConfig from '-/AppConfig';
import i18n from '-/services/i18n';
import DialogCloseButton from '-/components/dialogs/DialogCloseButton';
import useTheme from '@mui/styles/useTheme';
import useMediaQuery from '@mui/material/useMediaQuery';
import { getProTeaserIndex } from '-/reducers/app';
-import { connect } from 'react-redux';
+import { useSelector } from 'react-redux';
import { getProTeaserSlides } from '-/content/ProTeaserSlides';
import Links from '-/content/links';
+import { openURLExternally } from '-/services/utils-io';
interface Props {
open: boolean;
- slideIndex: number;
- openURLExternally: (url: string, skipConfirmation: boolean) => void;
onClose: () => void;
}
interface SlideProps {
title: string;
- openURL?: (url: string, skipConfirmation: boolean) => void;
description?: '';
ctaURL?: string;
ctaTitle?: string;
@@ -69,8 +66,7 @@ function Slide(props: SlideProps) {
videoURL,
videoPosterUrl,
pictureHeight,
- pictureShadow,
- openURL
+ pictureShadow
} = props;
return (
<div
@@ -98,7 +94,7 @@ function Slide(props: SlideProps) {
<a
href="#"
onClick={() => {
- openURL(ctaURL, true);
+ openURLExternally(ctaURL, true);
}}
>
<img
@@ -130,17 +126,17 @@ function Slide(props: SlideProps) {
<br />
<Button
onClick={() => {
- openURL(Links.links.productsOverview, true);
+ openURLExternally(Links.links.productsOverview, true);
}}
variant="contained"
color="primary"
>
Compare TagSpaces Products
</Button>
- {ctaTitle && openURL && (
+ {ctaTitle && (
<Button
onClick={() => {
- openURL(ctaURL, true);
+ openURLExternally(ctaURL, true);
}}
style={{ marginLeft: 10 }}
variant="contained"
@@ -155,8 +151,9 @@ function Slide(props: SlideProps) {
}
function ProTeaserDialog(props: Props) {
+ const slideIndex = useSelector(getProTeaserIndex);
const [activeStep, setActiveStep] = useState<number>(
- props.slideIndex && props.slideIndex > -1 ? props.slideIndex : 0
+ slideIndex && slideIndex > -1 ? slideIndex : 0
);
const maxSteps = Object.keys(slidesEN).length;
@@ -173,14 +170,14 @@ function ProTeaserDialog(props: Props) {
setActiveStep(step);
};
- const { open, onClose, openURLExternally } = props;
+ const { open, onClose } = props;
const theme = useTheme();
const fullScreen = useMediaQuery(theme.breakpoints.down('md'));
const slides = [];
for (let index in slidesEN) {
- slides.push(<Slide {...slidesEN[index]} openURL={openURLExternally} />);
+ slides.push(<Slide {...slidesEN[index]} />);
}
return (
@@ -216,7 +213,7 @@ function ProTeaserDialog(props: Props) {
activeStep={activeStep}
nextButton={
activeStep === maxSteps - 1 ? (
- <Button size="small" onClick={props.onClose}>
+ <Button size="small" onClick={onClose}>
{i18n.t('core:closeButton')}
</Button>
) : (
@@ -240,9 +237,4 @@ function ProTeaserDialog(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- slideIndex: getProTeaserIndex(state)
- };
-}
-export default connect(mapStateToProps)(ProTeaserDialog);
+export default ProTeaserDialog;
diff --git a/app/components/dialogs/RenameEntryDialog.tsx b/app/components/dialogs/RenameEntryDialog.tsx
index 5084fcd2c..51abcfc94 100644
--- a/app/components/dialogs/RenameEntryDialog.tsx
+++ b/app/components/dialogs/RenameEntryDialog.tsx
@@ -17,8 +17,7 @@
*/
import React, { useReducer, useRef, useState } from 'react';
-import { bindActionCreators } from 'redux';
-import { connect } from 'react-redux';
+import { useDispatch, useSelector } from 'react-redux';
import Button from '@mui/material/Button';
import TextField from '@mui/material/TextField';
import DialogActions from '@mui/material/DialogActions';
@@ -35,7 +34,11 @@ import {
import DraggablePaper from '-/components/DraggablePaper';
import AppConfig from '-/AppConfig';
import i18n from '-/services/i18n';
-import { actions as AppActions, getLastSelectedEntry } from '-/reducers/app';
+import {
+ actions as AppActions,
+ AppDispatch,
+ getLastSelectedEntry
+} from '-/reducers/app';
import PlatformIO from '-/services/platform-facade';
import DialogCloseButton from '-/components/dialogs/DialogCloseButton';
import { dirNameValidation, fileNameValidation } from '-/services/utils-io';
@@ -43,43 +46,51 @@ import { dirNameValidation, fileNameValidation } from '-/services/utils-io';
interface Props {
open: boolean;
currentDirectoryPath?: string;
- lastSelectedEntry: any;
onClose: () => void;
- renameFile: (source: string, target: string) => void;
- renameDirectory: (directoryPath: string, newDirectoryName: string) => void;
}
function RenameEntryDialog(props: Props) {
+ const { open, onClose, currentDirectoryPath } = props;
const [inputError, setInputError] = useState<boolean>(false);
const disableConfirmButton = useRef<boolean>(true);
+ const lastSelectedEntry = useSelector(getLastSelectedEntry);
+ const dispatch: AppDispatch = useDispatch();
+
+ const renameFile = (source, target) => {
+ dispatch(AppActions.renameFile(source, target));
+ };
+
+ const renameDirectory = (directoryPath, newDirectoryName) => {
+ dispatch(AppActions.renameDirectory(directoryPath, newDirectoryName));
+ };
let defaultName = '';
let originPath;
let isFile;
- if (props.lastSelectedEntry) {
- ({ isFile } = props.lastSelectedEntry);
+ if (lastSelectedEntry) {
+ ({ isFile } = lastSelectedEntry);
if (isFile) {
defaultName = extractFileName(
- props.lastSelectedEntry.path,
+ lastSelectedEntry.path,
PlatformIO.getDirSeparator()
);
} else {
defaultName = extractDirectoryName(
- props.lastSelectedEntry.path,
+ lastSelectedEntry.path,
PlatformIO.getDirSeparator()
);
}
- originPath = props.lastSelectedEntry.path;
- } else if (props.currentDirectoryPath) {
+ originPath = lastSelectedEntry.path;
+ } else if (currentDirectoryPath) {
isFile = false;
defaultName = extractDirectoryName(
- props.currentDirectoryPath,
+ currentDirectoryPath,
PlatformIO.getDirSeparator()
);
- originPath = props.currentDirectoryPath;
+ originPath = currentDirectoryPath;
} else {
return (
- <Dialog open={props.open} onClose={props.onClose}>
+ <Dialog open={open} onClose={onClose}>
<DialogTitle>{i18n.t('core:noSelectedEntryError')}</DialogTitle>
</Dialog>
);
@@ -134,21 +145,19 @@ function RenameEntryDialog(props: Props) {
if (!disableConfirmButton.current) {
if (isFile) {
const fileDirectory = extractContainingDirectoryPath(
- props.lastSelectedEntry.path,
+ lastSelectedEntry.path,
PlatformIO.getDirSeparator()
);
const newFilePath =
fileDirectory + PlatformIO.getDirSeparator() + name.current;
- props.renameFile(originPath, newFilePath);
+ renameFile(originPath, newFilePath);
} else {
- props.renameDirectory(originPath, name.current);
+ renameDirectory(originPath, name.current);
}
- props.onClose();
+ onClose();
}
};
- const { open, onClose } = props;
-
return (
<Dialog
open={open}
@@ -195,7 +204,7 @@ function RenameEntryDialog(props: Props) {
</FormControl>
</DialogContent>
<DialogActions>
- <Button data-tid="closeRenameEntryDialog" onClick={props.onClose}>
+ <Button data-tid="closeRenameEntryDialog" onClick={onClose}>
{i18n.t('core:cancel')}
</Button>
<Button
@@ -212,23 +221,4 @@ function RenameEntryDialog(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- lastSelectedEntry: getLastSelectedEntry(state)
- };
-}
-
-function mapActionCreatorsToProps(dispatch) {
- return bindActionCreators(
- {
- renameFile: AppActions.renameFile,
- renameDirectory: AppActions.renameDirectory
- },
- dispatch
- );
-}
-
-export default connect(
- mapStateToProps,
- mapActionCreatorsToProps
-)(RenameEntryDialog);
+export default RenameEntryDialog;
diff --git a/app/components/dialogs/components/CreateDirectory.tsx b/app/components/dialogs/components/CreateDirectory.tsx
index 83123bfca..e53c9adc4 100644
--- a/app/components/dialogs/components/CreateDirectory.tsx
+++ b/app/components/dialogs/components/CreateDirectory.tsx
@@ -17,17 +17,19 @@
*/
import React, { useRef, useState } from 'react';
-import { connect } from 'react-redux';
-import { bindActionCreators } from 'redux';
+import { useDispatch } from 'react-redux';
import { saveAs } from 'file-saver';
import Button from '@mui/material/Button';
import ButtonGroup from '@mui/material/ButtonGroup';
import Grid from '@mui/material/Grid';
import withStyles from '@mui/styles/withStyles';
-import { Progress } from 'aws-sdk/clients/s3';
import AppConfig from '-/AppConfig';
import i18n from '-/services/i18n';
-import { actions as AppActions, NotificationTypes } from '-/reducers/app';
+import {
+ actions as AppActions,
+ AppDispatch,
+ NotificationTypes
+} from '-/reducers/app';
import IOActions from '-/reducers/io-actions';
import { TS } from '-/tagspaces.namespace';
import PlatformIO from '-/services/platform-facade';
@@ -46,38 +48,11 @@ const styles: any = () => ({
interface Props {
classes: any;
onClose: () => void;
- onUploadProgress: (progress: Progress, response: any) => void;
- toggleUploadDialog: () => void;
- resetProgress: () => void;
- setProgress: (path: string, progress: number, abort?: string) => void;
- downloadFile: (
- url: string,
- destination: string,
- onDownloadProgress?: (progress: Progress, response: any) => void
- ) => any;
- uploadFilesAPI: (
- files: Array<File>,
- destination: string,
- onUploadProgress?: (progress: Progress, response: any) => void
- ) => any;
- toggleCreateDirectoryDialog: () => void;
- reflectCreateEntries: (fsEntries: Array<TS.FileSystemEntry>) => void;
- showNotification: (
- message: string,
- notificationType?: string,
- autohide?: boolean
- ) => void;
- toggleLocationDialog: () => void;
}
function CreateDirectory(props: Props) {
- const {
- classes,
- onClose,
- showNotification,
- toggleCreateDirectoryDialog,
- toggleLocationDialog
- } = props;
+ const { classes, onClose } = props;
+ const dispatch: AppDispatch = useDispatch();
const { targetDirectoryPath } = useTargetPathContext();
const fileUrl = useRef<string>();
@@ -97,19 +72,23 @@ function CreateDirectory(props: Props) {
fileInput.click();
}
+ const onUploadProgress = (progress, abort, fileName) => {
+ dispatch(AppActions.onUploadProgress(progress, abort, fileName));
+ };
function handleFileInputChange(selection: any) {
// console.log("Selected File: "+JSON.stringify(selection.currentTarget.files[0]));
// const file = selection.currentTarget.files[0];
- props.resetProgress();
- props.toggleUploadDialog();
- props
- .uploadFilesAPI(
+ dispatch(AppActions.resetProgress());
+ dispatch(AppActions.toggleUploadDialog());
+ dispatch(
+ IOActions.uploadFilesAPI(
Array.from(selection.currentTarget.files),
targetDirectoryPath,
- props.onUploadProgress
+ onUploadProgress
)
- .then(fsEntries => {
- props.reflectCreateEntries(fsEntries);
+ )
+ .then((fsEntries: Array<TS.FileSystemEntry>) => {
+ dispatch(AppActions.reflectCreateEntries(fsEntries));
return true;
})
.catch(error => {
@@ -151,29 +130,38 @@ function CreateDirectory(props: Props) {
fileName = url.hostname + '-' + fileName + '.html';
}
if (PlatformIO.haveObjectStoreSupport() || AppConfig.isElectron) {
- props.resetProgress();
- props.toggleUploadDialog();
- props
- .downloadFile(
+ dispatch(AppActions.resetProgress());
+ dispatch(AppActions.toggleUploadDialog());
+ dispatch(
+ IOActions.downloadFile(
fileUrl.current,
targetDirectoryPath +
PlatformIO.getDirSeparator() +
decodeURIComponent(fileName),
- props.onUploadProgress
+ onUploadProgress
)
+ )
.then(() => {
if (PlatformIO.haveObjectStoreSupport()) {
// currently objectStore location in downloadFile use saveFilePromise and this function not have progress handling
- props.setProgress(fileUrl.current, 100);
+ dispatch(AppActions.setProgress(fileUrl.current, 100));
}
})
.catch(e => {
console.log('downloadFile error:', e);
- props.setProgress(fileUrl.current, -1, i18n.t('core:errorCORS'));
- showNotification(
- 'downloadFile error' + e.message,
- NotificationTypes.error,
- true
+ dispatch(
+ AppActions.setProgress(
+ fileUrl.current,
+ -1,
+ i18n.t('core:errorCORS')
+ )
+ );
+ dispatch(
+ AppActions.showNotification(
+ 'downloadFile error' + e.message,
+ NotificationTypes.error,
+ true
+ )
);
});
} else {
@@ -194,7 +182,7 @@ function CreateDirectory(props: Props) {
variant="outlined"
onClick={() => {
onClose();
- toggleLocationDialog();
+ dispatch(AppActions.toggleLocationDialog());
}}
className={classes.createButton}
data-tid="createLocationButton"
@@ -211,7 +199,7 @@ function CreateDirectory(props: Props) {
variant="outlined"
onClick={() => {
onClose();
- toggleCreateDirectoryDialog();
+ dispatch(AppActions.toggleCreateDirectoryDialog());
}}
className={classes.createButton}
data-tid="newSubDirectory"
@@ -279,25 +267,4 @@ function CreateDirectory(props: Props) {
);
}
-function mapActionCreatorsToProps(dispatch) {
- return bindActionCreators(
- {
- showNotification: AppActions.showNotification,
- reflectCreateEntries: AppActions.reflectCreateEntries,
- toggleCreateDirectoryDialog: AppActions.toggleCreateDirectoryDialog,
- uploadFilesAPI: IOActions.uploadFilesAPI,
- downloadFile: IOActions.downloadFile,
- onUploadProgress: AppActions.onUploadProgress,
- toggleUploadDialog: AppActions.toggleUploadDialog,
- resetProgress: AppActions.resetProgress,
- setProgress: AppActions.setProgress,
- toggleLocationDialog: AppActions.toggleLocationDialog
- },
- dispatch
- );
-}
-
-export default connect(
- undefined,
- mapActionCreatorsToProps
-)(withStyles(styles)(CreateDirectory));
+export default withStyles(styles)(CreateDirectory);
diff --git a/app/components/dialogs/components/CreateFile.tsx b/app/components/dialogs/components/CreateFile.tsx
index 03761d9db..3e7b8796b 100644
--- a/app/components/dialogs/components/CreateFile.tsx
+++ b/app/components/dialogs/components/CreateFile.tsx
@@ -17,8 +17,7 @@
*/
import React, { useReducer, useRef, useState } from 'react';
-import { connect } from 'react-redux';
-import { bindActionCreators } from 'redux';
+import { useSelector, useDispatch } from 'react-redux';
import Button from '@mui/material/Button';
import ButtonGroup from '@mui/material/ButtonGroup';
import Typography from '@mui/material/Typography';
@@ -30,8 +29,7 @@ import i18n from '-/services/i18n';
import {
actions as AppActions,
getDirectoryPath,
- getSelectedEntries,
- getCurrentDirectoryPerspective
+ AppDispatch
} from '-/reducers/app';
import { getFirstRWLocation } from '-/reducers/locations';
import { TS } from '-/tagspaces.namespace';
@@ -50,32 +48,17 @@ const styles: any = () => ({
});
interface Props {
- open: boolean;
+ //open: boolean;
classes: any;
- firstRWLocation: TS.Location;
- selectedEntries: Array<TS.FileSystemEntry>;
- currentDirectoryPath: string | null;
- currentDirectoryPerspective: string;
- openLocation: (location: TS.Location) => void;
- createFileAdvanced: (
- targetPath: string,
- fileName: string,
- content: string,
- fileType: string
- ) => void;
onClose: () => void;
}
function CreateFile(props: Props) {
- const {
- classes,
- onClose,
- createFileAdvanced,
- openLocation,
- currentDirectoryPath,
- firstRWLocation
- } = props;
+ const { classes, onClose } = props;
+ const dispatch: AppDispatch = useDispatch();
+ const firstRWLocation = useSelector(getFirstRWLocation);
+ const currentDirectoryPath: string | null = useSelector(getDirectoryPath);
const { targetDirectoryPath } = useTargetPathContext();
const fileName = useRef<string>(
@@ -92,18 +75,20 @@ function CreateFile(props: Props) {
function loadLocation() {
if (!currentDirectoryPath && firstRWLocation) {
- openLocation(firstRWLocation);
+ dispatch(AppActions.openLocation(firstRWLocation));
}
}
function createRichTextFile() {
if (targetDirectoryPath && !fileNameValidation(fileName.current)) {
loadLocation();
- createFileAdvanced(
- targetDirectoryPath,
- fileName.current,
- fileContent,
- 'html'
+ dispatch(
+ AppActions.createFileAdvanced(
+ targetDirectoryPath,
+ fileName.current,
+ fileContent,
+ 'html'
+ )
);
onClose();
}
@@ -112,11 +97,13 @@ function CreateFile(props: Props) {
function createTextFile() {
if (targetDirectoryPath && !fileNameValidation(fileName.current)) {
loadLocation();
- createFileAdvanced(
- targetDirectoryPath,
- fileName.current,
- fileContent,
- 'txt'
+ dispatch(
+ AppActions.createFileAdvanced(
+ targetDirectoryPath,
+ fileName.current,
+ fileContent,
+ 'txt'
+ )
);
onClose();
}
@@ -125,11 +112,13 @@ function CreateFile(props: Props) {
function createMarkdownFile() {
if (targetDirectoryPath && !fileNameValidation(fileName.current)) {
loadLocation();
- createFileAdvanced(
- targetDirectoryPath,
- fileName.current,
- fileContent,
- 'md'
+ dispatch(
+ AppActions.createFileAdvanced(
+ targetDirectoryPath,
+ fileName.current,
+ fileContent,
+ 'md'
+ )
);
onClose();
}
@@ -256,27 +245,4 @@ function CreateFile(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- firstRWLocation: getFirstRWLocation(state),
- //keyBindings: getKeyBindingObject(state),
- selectedEntries: getSelectedEntries(state),
- currentDirectoryPath: getDirectoryPath(state),
- currentDirectoryPerspective: getCurrentDirectoryPerspective(state)
- };
-}
-
-function mapActionCreatorsToProps(dispatch) {
- return bindActionCreators(
- {
- openLocation: AppActions.openLocation,
- createFileAdvanced: AppActions.createFileAdvanced
- },
- dispatch
- );
-}
-
-export default connect(
- mapStateToProps,
- mapActionCreatorsToProps
-)(withStyles(styles)(CreateFile));
+export default withStyles(styles)(CreateFile);
diff --git a/app/components/dialogs/settings/MapTileServerDialog.tsx b/app/components/dialogs/settings/MapTileServerDialog.tsx
index 2c9d4f0b9..bf64ddbbf 100644
--- a/app/components/dialogs/settings/MapTileServerDialog.tsx
+++ b/app/components/dialogs/settings/MapTileServerDialog.tsx
@@ -26,25 +26,23 @@ import TextField from '@mui/material/TextField';
import FormHelperText from '@mui/material/FormHelperText';
import FormControl from '@mui/material/FormControl';
import Switch from '@mui/material/Switch';
-import { connect } from 'react-redux';
-import { bindActionCreators } from 'redux';
+import { useDispatch } from 'react-redux';
import i18n from '-/services/i18n';
import useValidation from '-/utils/useValidation';
import { TS } from '-/tagspaces.namespace';
import { actions as SettingsActions } from '-/reducers/settings';
import DialogCloseButton from '-/components/dialogs/DialogCloseButton';
+import { AppDispatch } from '-/reducers/app';
interface Props {
open: boolean;
onClose: () => void;
tileServer: TS.MapTileServer;
isDefault: boolean;
- editTileServers: (tileServer: TS.MapTileServer, isDefault: boolean) => void;
- addTileServers: (tileServer: TS.MapTileServer, isDefault: boolean) => void;
- deleteTileServer: (uuid: string) => void;
}
function MapTileServerDialog(props: Props) {
+ const dispatch: AppDispatch = useDispatch();
const name = useRef<string>(props.tileServer.name);
const serverURL = useRef<string>(props.tileServer.serverURL);
const serverInfo = useRef<string>(props.tileServer.serverInfo);
@@ -74,24 +72,28 @@ function MapTileServerDialog(props: Props) {
const saveTileServer = () => {
if (validateForm()) {
if (props.tileServer.uuid) {
- props.editTileServers(
- {
- uuid: props.tileServer.uuid,
- name: name.current,
- serverInfo: serverInfo.current,
- serverURL: serverURL.current
- },
- isDefault.current
+ dispatch(
+ SettingsActions.editTileServers(
+ {
+ uuid: props.tileServer.uuid,
+ name: name.current,
+ serverInfo: serverInfo.current,
+ serverURL: serverURL.current
+ },
+ isDefault.current
+ )
);
} else {
- props.addTileServers(
- {
- uuid: props.tileServer.uuid,
- name: name.current,
- serverInfo: serverInfo.current,
- serverURL: serverURL.current
- },
- isDefault.current
+ dispatch(
+ SettingsActions.addTileServers(
+ {
+ uuid: props.tileServer.uuid,
+ name: name.current,
+ serverInfo: serverInfo.current,
+ serverURL: serverURL.current
+ },
+ isDefault.current
+ )
);
}
props.onClose();
@@ -172,7 +174,7 @@ function MapTileServerDialog(props: Props) {
}}
data-tid="deleteTileServerTID"
onClick={() => {
- props.deleteTileServer(props.tileServer.uuid);
+ dispatch(SettingsActions.deleteTileServer(props.tileServer.uuid));
props.onClose();
}}
>
@@ -209,18 +211,4 @@ function MapTileServerDialog(props: Props) {
);
}
-function mapActionCreatorsToProps(dispatch) {
- return bindActionCreators(
- {
- editTileServers: SettingsActions.editTileServers,
- addTileServers: SettingsActions.addTileServers,
- deleteTileServer: SettingsActions.deleteTileServer
- },
- dispatch
- );
-}
-
-export default connect(
- undefined,
- mapActionCreatorsToProps
-)(MapTileServerDialog);
+export default MapTileServerDialog;
diff --git a/app/components/dialogs/settings/SettingsAdvanced.tsx b/app/components/dialogs/settings/SettingsAdvanced.tsx
index 2da67dfc4..7da36168a 100644
--- a/app/components/dialogs/settings/SettingsAdvanced.tsx
+++ b/app/components/dialogs/settings/SettingsAdvanced.tsx
@@ -17,8 +17,7 @@
*/
import React, { useState } from 'react';
-import { connect } from 'react-redux';
-import { bindActionCreators } from 'redux';
+import { useSelector, useDispatch } from 'react-redux';
import withStyles from '@mui/styles/withStyles';
import List from '@mui/material/List';
import ListItem from '@mui/material/ListItem';
@@ -39,7 +38,6 @@ import {
actions as SettingsActions,
getSettings,
getMapTileServers,
- getEnableWS,
isDevMode
} from '-/reducers/settings';
import { TS } from '-/tagspaces.namespace';
@@ -50,6 +48,7 @@ import InfoIcon from '-/components/InfoIcon';
import { DeleteIcon } from '-/components/CommonIcons';
import { ListItemIcon } from '@mui/material';
import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
+import { AppDispatch } from '-/reducers/app';
const styles: any = {
root: {
@@ -70,50 +69,66 @@ const styles: any = {
interface Props {
classes: any;
- settings: any;
- setDesktopMode: (desktopMode: boolean) => void;
- setDevMode: (devMode: boolean) => void;
- isDevMode: boolean;
- setEnableWS: (enableWS: boolean) => void;
- setWarningOpeningFilesExternally: (
- warningOpeningFilesExternally: boolean
- ) => void;
- setSaveTagInLocation: (saveTagInLocation: boolean) => void;
- setRevisionsEnabled: (enabled: boolean) => void;
showResetSettings: (showDialog: boolean) => void;
- tileServers: Array<TS.MapTileServer>;
- setGeoTaggingFormat: (geoTaggingFormat: string) => void;
- setHistory: (key: string, value: number) => void;
- setPrefixTagContainer: (prefix: string) => void;
}
const historyKeys = Pro && Pro.history ? Pro.history.historyKeys : {};
function SettingsAdvanced(props: Props) {
+ const { classes, showResetSettings } = props;
+ const dispatch: AppDispatch = useDispatch();
+ const settings = useSelector(getSettings);
+ const tileServers: Array<TS.MapTileServer> = useSelector(getMapTileServers);
+ //const enableWS = useSelector(getEnableWS);
+ const devMode = useSelector(isDevMode);
const [tileServerDialog, setTileServerDialog] = useState<any>(undefined);
const [confirmDialogKey, setConfirmDialogKey] = useState<null | string>(null);
- const handleEditTileServerClick = (
- event: any,
- tileServer: any,
- isDefault: boolean
- ) => {
+ const handleEditTileServerClick = (event, tileServer, isDefault: boolean) => {
event.preventDefault();
event.stopPropagation();
setTileServerDialog({ ...tileServer, isDefault });
};
- const { classes } = props;
-
const geoTaggingFormatDisabled = AppConfig.geoTaggingFormat !== undefined;
+ const setDesktopMode = desktopMode =>
+ dispatch(SettingsActions.setDesktopMode(desktopMode));
+
+ const setDevMode = devMode => dispatch(SettingsActions.setDevMode(devMode));
+
+ const setEnableWS = enableWS =>
+ dispatch(SettingsActions.setEnableWS(enableWS));
+
+ const setWarningOpeningFilesExternally = warningOpeningFilesExternally =>
+ dispatch(
+ SettingsActions.setWarningOpeningFilesExternally(
+ warningOpeningFilesExternally
+ )
+ );
+
+ const setSaveTagInLocation = saveTagInLocation =>
+ dispatch(SettingsActions.setSaveTagInLocation(saveTagInLocation));
+
+ const setRevisionsEnabled = enabled =>
+ dispatch(SettingsActions.setRevisionsEnabled(enabled));
+
+ const setGeoTaggingFormat = geoTaggingFormat =>
+ dispatch(SettingsActions.setGeoTaggingFormat(geoTaggingFormat));
+
+ const setHistory = (key, value) =>
+ dispatch(SettingsActions.setHistory(key, value));
+
+ const setPrefixTagContainer = prefix =>
+ dispatch(SettingsActions.setPrefixTagContainer(prefix));
+
return (
<div style={{ width: '100%' }}>
<List className={classes.root}>
<ListItem className={classes.listItem}>
<Button
data-tid="resetSettingsTID"
- onClick={() => props.showResetSettings(true)}
+ onClick={() => showResetSettings(true)}
color="secondary"
style={{ marginLeft: -7 }}
>
@@ -134,8 +149,8 @@ function SettingsAdvanced(props: Props) {
<Switch
data-tid="settingsSetDesktopMode"
disabled={!(typeof window.ExtDisplayMode === 'undefined')}
- onClick={() => props.setDesktopMode(!props.settings.desktopMode)}
- checked={!props.settings.desktopMode}
+ onClick={() => setDesktopMode(!settings.desktopMode)}
+ checked={!settings.desktopMode}
/>
</ListItem>
<ListItem className={classes.listItem}>
@@ -143,16 +158,16 @@ function SettingsAdvanced(props: Props) {
<Switch
data-tid="settingsEnableDevMode"
disabled={window.ExtDevMode && window.ExtDevMode === true}
- onClick={() => props.setDevMode(!props.settings.devMode)}
- checked={props.isDevMode}
+ onClick={() => setDevMode(!devMode)}
+ checked={devMode}
/>
</ListItem>
<ListItem className={classes.listItem}>
<ListItemText primary={i18n.t('enableWS')} />
<Switch
data-tid="settingsEnableWS"
- onClick={() => props.setEnableWS(!props.settings.enableWS)}
- checked={props.settings.enableWS}
+ onClick={() => setEnableWS(!settings.enableWS)}
+ checked={settings.enableWS}
/>
</ListItem>
<ListItem className={classes.listItem}>
@@ -160,11 +175,11 @@ function SettingsAdvanced(props: Props) {
<Switch
data-tid="warningOpeningFilesExternally"
onClick={() =>
- props.setWarningOpeningFilesExternally(
- !props.settings.warningOpeningFilesExternally
+ setWarningOpeningFilesExternally(
+ !settings.warningOpeningFilesExternally
)
}
- checked={props.settings.warningOpeningFilesExternally}
+ checked={settings.warningOpeningFilesExternally}
/>
</ListItem>
<ListItem className={classes.listItem}>
@@ -172,8 +187,8 @@ function SettingsAdvanced(props: Props) {
<Input
style={{ maxWidth: '100px' }}
data-tid="prefixTagContainerTID"
- value={props.settings.prefixTagContainer}
- onChange={event => props.setPrefixTagContainer(event.target.value)}
+ value={settings.prefixTagContainer}
+ onChange={event => setPrefixTagContainer(event.target.value)}
/>
</ListItem>
{Pro && (
@@ -195,9 +210,9 @@ function SettingsAdvanced(props: Props) {
<Select
data-tid="fileOpenTID"
title={i18n.t('core:fileOpenHistoryTitle')}
- value={props.settings[historyKeys.fileOpenKey]}
- onChange={(event: any) =>
- props.setHistory(historyKeys.fileOpenKey, event.target.value)
+ value={settings[historyKeys.fileOpenKey]}
+ onChange={event =>
+ setHistory(historyKeys.fileOpenKey, event.target.value)
}
input={<Input id="fileOpenSelector" />}
>
@@ -226,12 +241,9 @@ function SettingsAdvanced(props: Props) {
<Select
data-tid="folderOpenTID"
title={i18n.t('core:folderOpenHistoryTitle')}
- value={props.settings[historyKeys.folderOpenKey]}
+ value={settings[historyKeys.folderOpenKey]}
onChange={(event: any) =>
- props.setHistory(
- historyKeys.folderOpenKey,
- event.target.value
- )
+ setHistory(historyKeys.folderOpenKey, event.target.value)
}
input={<Input id="folderOpenSelector" />}
>
@@ -258,9 +270,9 @@ function SettingsAdvanced(props: Props) {
<Select
data-tid="fileEditTID"
title={i18n.t('core:fileEditHistoryTitle')}
- value={props.settings[historyKeys.fileEditKey]}
+ value={settings[historyKeys.fileEditKey]}
onChange={(event: any) =>
- props.setHistory(historyKeys.fileEditKey, event.target.value)
+ setHistory(historyKeys.fileEditKey, event.target.value)
}
input={<Input id="fileEditSelector" />}
>
@@ -289,12 +301,9 @@ function SettingsAdvanced(props: Props) {
<Select
data-tid="searchHistoryTID"
title={i18n.t('core:searchHistoryTitle')}
- value={props.settings[historyKeys.searchHistoryKey]}
+ value={settings[historyKeys.searchHistoryKey]}
onChange={(event: any) =>
- props.setHistory(
- historyKeys.searchHistoryKey,
- event.target.value
- )
+ setHistory(historyKeys.searchHistoryKey, event.target.value)
}
input={<Input id="searchHistorySelector" />}
>
@@ -337,10 +346,8 @@ function SettingsAdvanced(props: Props) {
<Switch
data-tid="setRevisionsEnabledTID"
disabled={!Pro}
- onClick={() =>
- props.setRevisionsEnabled(!props.settings.isRevisionsEnabled)
- }
- checked={props.settings.isRevisionsEnabled}
+ onClick={() => setRevisionsEnabled(!settings.isRevisionsEnabled)}
+ checked={settings.isRevisionsEnabled}
/>
</ListItem>
<ListItem className={classes.listItem}>
@@ -356,10 +363,8 @@ function SettingsAdvanced(props: Props) {
<Switch
data-tid="saveTagInLocationTID"
disabled={!Pro}
- onClick={() =>
- props.setSaveTagInLocation(!props.settings.saveTagInLocation)
- }
- checked={props.settings.saveTagInLocation}
+ onClick={() => setSaveTagInLocation(!settings.saveTagInLocation)}
+ checked={settings.saveTagInLocation}
/>
</ListItem>
<ListItem className={classes.listItem}>
@@ -375,14 +380,12 @@ function SettingsAdvanced(props: Props) {
value={
geoTaggingFormatDisabled
? AppConfig.geoTaggingFormat
- : props.settings.geoTaggingFormat
- }
- onChange={(event: any) =>
- props.setGeoTaggingFormat(event.target.value)
+ : settings.geoTaggingFormat
}
+ onChange={(event: any) => setGeoTaggingFormat(event.target.value)}
input={<Input id="geoTaggingFormatSelector" />}
>
- {props.settings.supportedGeoTagging.map(geoTagging => (
+ {settings.supportedGeoTagging.map(geoTagging => (
<MenuItem key={geoTagging} value={geoTagging}>
{geoTagging.toUpperCase()}
</MenuItem>
@@ -409,8 +412,8 @@ function SettingsAdvanced(props: Props) {
}}
dense
>
- {props.tileServers.length > 0 ? (
- props.tileServers.map((tileServer, index) => (
+ {tileServers.length > 0 ? (
+ tileServers.map((tileServer, index) => (
<ListItem key={tileServer.uuid} className={classes.listItem}>
<ListItemText
primary={tileServer.name}
@@ -463,34 +466,4 @@ function SettingsAdvanced(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- settings: getSettings(state),
- tileServers: getMapTileServers(state),
- enableWS: getEnableWS(state),
- isDevMode: isDevMode(state)
- };
-}
-
-function mapActionCreatorsToProps(dispatch) {
- return bindActionCreators(
- {
- setWarningOpeningFilesExternally:
- SettingsActions.setWarningOpeningFilesExternally,
- setDesktopMode: SettingsActions.setDesktopMode,
- setDevMode: SettingsActions.setDevMode,
- setEnableWS: SettingsActions.setEnableWS,
- setSaveTagInLocation: SettingsActions.setSaveTagInLocation,
- setGeoTaggingFormat: SettingsActions.setGeoTaggingFormat,
- setHistory: SettingsActions.setHistory,
- setRevisionsEnabled: SettingsActions.setRevisionsEnabled,
- setPrefixTagContainer: SettingsActions.setPrefixTagContainer
- },
- dispatch
- );
-}
-
-export default connect(
- mapStateToProps,
- mapActionCreatorsToProps
-)(withStyles(styles, { withTheme: true })(SettingsAdvanced));
+export default withStyles(styles, { withTheme: true })(SettingsAdvanced);
diff --git a/app/components/dialogs/settings/SettingsDialog.tsx b/app/components/dialogs/settings/SettingsDialog.tsx
index 8f99cfc22..4ea5350ea 100644
--- a/app/components/dialogs/settings/SettingsDialog.tsx
+++ b/app/components/dialogs/settings/SettingsDialog.tsx
@@ -16,8 +16,8 @@
*
*/
-import React, { useState } from 'react';
-import { connect } from 'react-redux';
+import React, { useState, useEffect } from 'react';
+import { useSelector } from 'react-redux';
import Button from '@mui/material/Button';
import withStyles from '@mui/styles/withStyles';
import useMediaQuery from '@mui/material/useMediaQuery';
@@ -29,7 +29,6 @@ import Dialog from '@mui/material/Dialog';
import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';
import DialogTitle from '@mui/material/DialogTitle';
-import AppConfig from '-/AppConfig';
import ConfirmDialog from '../ConfirmDialog';
import SettingsGeneral from '../settings/SettingsGeneral';
import SettingsKeyBindings from '../settings/SettingsKeyBindings';
@@ -41,6 +40,7 @@ import SettingsAdvanced from '-/components/dialogs/settings/SettingsAdvanced';
import DialogCloseButton from '-/components/dialogs/DialogCloseButton';
import Links from '-/content/links';
import SettingsExtensions from '-/components/dialogs/settings/SettingsExtensions';
+import { openURLExternally } from '-/services/utils-io';
const styles: any = () => ({
mainContent: {
@@ -52,10 +52,10 @@ interface Props {
open: boolean;
classes?: any;
onClose: () => void;
- openURLExternally: (url: string, skipConfirmation?: boolean) => void;
}
function SettingsDialog(props: Props) {
+ const language = useSelector(getCurrentLanguage);
const [currentTab, setCurrentTab] = useState<number>(0);
const [
isResetSettingsDialogOpened,
@@ -176,7 +176,7 @@ function SettingsDialog(props: Props) {
</DialogActions>
);
- const { open, onClose, openURLExternally } = props;
+ const { open, onClose } = props;
const theme = useTheme();
const fullScreen = useMediaQuery(theme.breakpoints.down('md'));
return (
@@ -194,8 +194,4 @@ function SettingsDialog(props: Props) {
);
}
-const mapStateToProps = state => ({
- language: getCurrentLanguage(state)
-});
-
-export default connect(mapStateToProps)(withStyles(styles)(SettingsDialog));
+export default withStyles(styles)(SettingsDialog);
diff --git a/app/components/dialogs/settings/SettingsExtensions.tsx b/app/components/dialogs/settings/SettingsExtensions.tsx
index 78cb2ebfe..29357e8d6 100644
--- a/app/components/dialogs/settings/SettingsExtensions.tsx
+++ b/app/components/dialogs/settings/SettingsExtensions.tsx
@@ -17,8 +17,7 @@
*/
import React, { ChangeEvent, useRef, useState } from 'react';
-import { connect } from 'react-redux';
-import { bindActionCreators } from 'redux';
+import { useSelector, useDispatch } from 'react-redux';
import { Accordion, AccordionDetails, AccordionSummary } from '@mui/material';
import Typography from '@mui/material/Typography';
import Tooltip from '-/components/Tooltip';
@@ -30,9 +29,12 @@ import IconButton from '@mui/material/IconButton';
import Switch from '@mui/material/Switch';
import Button from '@mui/material/Button';
import DeleteIcon from '@mui/icons-material/Delete';
-import { Progress } from 'aws-sdk/clients/s3';
import { actions as SettingsActions, isDevMode } from '-/reducers/settings';
-import { actions as AppActions, getExtensions } from '-/reducers/app';
+import {
+ actions as AppActions,
+ AppDispatch,
+ getExtensions
+} from '-/reducers/app';
import IOActions from '-/reducers/io-actions';
import { TS } from '-/tagspaces.namespace';
import i18n from '-/services/i18n';
@@ -40,43 +42,38 @@ import PlatformIO from '-/services/platform-facade';
import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
import InfoIcon from '-/components/InfoIcon';
-interface Props {
- extension: Array<TS.Extension>;
- isDevMode: boolean;
- removeExtension: (extensionId: string) => void;
- updateExtension: (extension: TS.Extension) => void;
- removeSupportedFileTypes: (extensionId: string) => void;
- enableExtension: (extensionId: string, enabled: boolean) => void;
- resetProgress: () => void;
- onUploadProgress: (progress: Progress, response: any) => void;
- toggleUploadDialog: () => void;
- uploadFilesAPI: (
- files: Array<File>,
- destination: string,
- onUploadProgress?: (progress: Progress, response: any) => void,
- uploadMeta?: boolean
- ) => any;
- switchCurrentLocationType: (currentLocationId?) => void;
-}
-
-function SettingsExtensions(props: Props) {
+function SettingsExtensions() {
const fileInputRef = useRef<HTMLInputElement>(null);
const [removeExtDialogOpened, setRemoveExtDialogOpened] = useState<
TS.Extension
>(undefined);
- function handleFileInputChange(selection: any) {
+ const extension = useSelector(getExtensions);
+ const devMode = useSelector(isDevMode);
+ const dispatch: AppDispatch = useDispatch();
+
+ const onUploadProgress = (progress, abort, fileName) => {
+ dispatch(AppActions.onUploadProgress(progress, abort, fileName));
+ };
+
+ const handleFileInputChange = (selection: any) => {
const files: File[] = Array.from(selection.currentTarget.files);
PlatformIO.getUserDataDir().then(dataDir => {
- props.resetProgress();
- props.toggleUploadDialog();
+ dispatch(AppActions.resetProgress());
+ dispatch(AppActions.toggleUploadDialog());
PlatformIO.disableObjectStoreSupport();
PlatformIO.disableWebdavSupport();
const destinationPath =
dataDir + PlatformIO.getDirSeparator() + 'tsplugins';
- props
- .uploadFilesAPI(files, destinationPath, props.onUploadProgress, false)
- .then(fsEntries => {
+ dispatch(
+ IOActions.uploadFilesAPI(
+ files,
+ destinationPath,
+ onUploadProgress,
+ false
+ )
+ )
+ .then((fsEntries: Array<TS.FileSystemEntry>) => {
const targetPath =
destinationPath +
PlatformIO.getDirSeparator() +
@@ -86,19 +83,18 @@ function SettingsExtensions(props: Props) {
const promises = fsEntries.map(fsEntry =>
PlatformIO.unZip(fsEntry.path, targetPath)
);
- // fsEntries.name.substring(0, fsEntries.extension.length + 1);
return Promise.all(promises).then(paths => {
PlatformIO.loadExtensions();
paths.forEach(path => PlatformIO.deleteFilePromise(path));
- return props.switchCurrentLocationType();
+ return dispatch(AppActions.switchCurrentLocationType());
});
})
.catch(error => {
console.log('uploadFiles', error);
- return props.switchCurrentLocationType();
+ return dispatch(AppActions.switchCurrentLocationType());
});
});
- }
+ };
return (
<div style={{ minHeight: 400 }}>
@@ -115,8 +111,8 @@ function SettingsExtensions(props: Props) {
</AccordionSummary>
<AccordionDetails>
<List>
- {props.extension &&
- props.extension
+ {extension &&
+ extension
.filter(ext => !ext.extensionExternal)
.map(ext => (
<ListItem key={ext.extensionId} disablePadding>
@@ -139,8 +135,8 @@ function SettingsExtensions(props: Props) {
</AccordionSummary>
<AccordionDetails>
<List>
- {props.extension &&
- props.extension
+ {extension &&
+ extension
.filter(ext => ext.extensionExternal)
.map(ext => (
<ListItem key={ext.extensionId} disablePadding>
@@ -151,20 +147,37 @@ function SettingsExtensions(props: Props) {
checked={ext.extensionEnabled}
onChange={(event: ChangeEvent<HTMLInputElement>) => {
if (event.target.checked) {
- props.updateExtension({
- ...ext,
- extensionEnabled: true
- });
- props.enableExtension(ext.extensionId, true);
- //reload default file types
+ dispatch(
+ AppActions.updateExtension({
+ ...ext,
+ extensionEnabled: true
+ })
+ );
+ dispatch(
+ SettingsActions.enableExtension(
+ ext.extensionId,
+ true
+ )
+ );
PlatformIO.loadExtensions();
} else {
- props.updateExtension({
- ...ext,
- extensionEnabled: false
- });
- props.enableExtension(ext.extensionId, false);
- props.removeSupportedFileTypes(ext.extensionId);
+ dispatch(
+ AppActions.updateExtension({
+ ...ext,
+ extensionEnabled: false
+ })
+ );
+ dispatch(
+ SettingsActions.enableExtension(
+ ext.extensionId,
+ false
+ )
+ );
+ dispatch(
+ SettingsActions.removeSupportedFileTypes(
+ ext.extensionId
+ )
+ );
}
}}
/>
@@ -194,9 +207,13 @@ function SettingsExtensions(props: Props) {
})}
confirmCallback={result => {
if (result) {
- props.removeExtension(removeExtDialogOpened.extensionId);
- props.removeSupportedFileTypes(
- removeExtDialogOpened.extensionId
+ dispatch(
+ AppActions.removeExtension(removeExtDialogOpened.extensionId)
+ );
+ dispatch(
+ SettingsActions.removeSupportedFileTypes(
+ removeExtDialogOpened.extensionId
+ )
);
PlatformIO.removeExtension(removeExtDialogOpened.extensionId);
}
@@ -205,11 +222,11 @@ function SettingsExtensions(props: Props) {
confirmDialogTID="confirmRemoveExtDialogTID"
confirmDialogContentTID="confirmRemoveExtDialogContentTID"
/>
- {props.extension &&
- props.extension.filter(ext => ext.extensionExternal).length < 1 && (
+ {extension &&
+ extension.filter(ext => ext.extensionExternal).length < 1 && (
<Typography variant="subtitle1">No extensions found</Typography>
)}
- {props.isDevMode && (
+ {devMode && (
<Box style={{ textAlign: 'center' }}>
<Button
data-tid="installExtensionTID"
@@ -233,31 +250,4 @@ function SettingsExtensions(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- extension: getExtensions(state),
- isDevMode: isDevMode(state)
- };
-}
-
-function mapActionCreatorsToProps(dispatch) {
- return bindActionCreators(
- {
- removeExtension: AppActions.removeExtension,
- updateExtension: AppActions.updateExtension,
- removeSupportedFileTypes: SettingsActions.removeSupportedFileTypes,
- enableExtension: SettingsActions.enableExtension,
- onUploadProgress: AppActions.onUploadProgress,
- uploadFilesAPI: IOActions.uploadFilesAPI,
- toggleUploadDialog: AppActions.toggleUploadDialog,
- resetProgress: AppActions.resetProgress,
- switchCurrentLocationType: AppActions.switchCurrentLocationType
- },
- dispatch
- );
-}
-
-export default connect(
- mapStateToProps,
- mapActionCreatorsToProps
-)(SettingsExtensions);
+export default SettingsExtensions;
diff --git a/app/components/dialogs/settings/SettingsFileTypes.tsx b/app/components/dialogs/settings/SettingsFileTypes.tsx
index 354b4dd6c..d93d64f32 100644
--- a/app/components/dialogs/settings/SettingsFileTypes.tsx
+++ b/app/components/dialogs/settings/SettingsFileTypes.tsx
@@ -17,8 +17,7 @@
*/
import React, { useState, useEffect, useRef, useReducer } from 'react';
-import { connect } from 'react-redux';
-import { bindActionCreators } from 'redux';
+import { useSelector, useDispatch } from 'react-redux';
import { getUuid } from '@tagspaces/tagspaces-common/utils-io';
import withStyles from '@mui/styles/withStyles';
import MenuItem from '@mui/material/MenuItem';
@@ -45,7 +44,6 @@ import ColorPickerDialog from '-/components/dialogs/ColorPickerDialog';
import i18n from '-/services/i18n';
import TransparentBackground from '-/components/TransparentBackground';
import { TS } from '-/tagspaces.namespace';
-import AppConfig from '-/AppConfig';
import {
actions as SettingsActions,
getSupportedFileTypes,
@@ -53,8 +51,8 @@ import {
} from '-/reducers/settings';
import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
import PlatformFacade from '-/services/platform-facade';
-import { getExtensions } from '-/reducers/app';
-import { supportedFileTypes } from '-/extension-config';
+import { AppDispatch, getExtensions } from '-/reducers/app';
+import { supportedFileTypes as defaultSupportedFileTypes } from '-/extension-config';
import useFirstRender from '-/utils/useFirstRender';
const styles: any = (theme: any) => ({
@@ -76,15 +74,12 @@ const styles: any = (theme: any) => ({
});
interface Props {
- supportedFileTypes: Array<TS.FileTypes>;
- setSupportedFileTypes?: (fileTypes: Array<any>) => void;
classes: any;
- extensions: Array<TS.Extension>;
- isDevMode: boolean;
}
function SettingsFileTypes(props: Props) {
- const items = useRef<Array<TS.FileTypes>>(props.supportedFileTypes);
+ const supportedFileTypes = useSelector(getSupportedFileTypes);
+ const items = useRef<Array<TS.FileTypes>>(supportedFileTypes);
const selectedItem = useRef<TS.FileTypes>(undefined);
const isValidationInProgress = useRef<boolean>(false);
const [isConfirmDialogOpened, setIsConfirmDialogOpened] = useState<boolean>(
@@ -98,9 +93,13 @@ function SettingsFileTypes(props: Props) {
const [ignored, forceUpdate] = useReducer(x => x + 1, 0);
const firstRender = useFirstRender();
+ const extensions = useSelector(getExtensions);
+ const devMode = useSelector(isDevMode);
+ const dispatch: AppDispatch = useDispatch();
+
useEffect(() => {
if (!firstRender) {
- items.current = props.supportedFileTypes;
+ items.current = supportedFileTypes;
isValidationInProgress.current = false;
if (selectedItem.current !== undefined) {
const timer = scrollToItem(selectedItem.current);
@@ -111,7 +110,7 @@ function SettingsFileTypes(props: Props) {
};
}
}
- }, [props.supportedFileTypes]);
+ }, [supportedFileTypes]);
type ScrollToIndexArgs = {
index: number;
@@ -193,7 +192,7 @@ function SettingsFileTypes(props: Props) {
forceUpdate();
return false;
}
- props.setSupportedFileTypes(newItems);
+ dispatch(SettingsActions.setSupportedFileTypes(newItems));
};
const validateSelectedFileTypes = newItems => {
@@ -366,7 +365,7 @@ function SettingsFileTypes(props: Props) {
sx={{ width: 180 }}
input={<Input id="" />}
onChange={event => {
- const extension: TS.Extension = props.extensions.find(
+ const extension: TS.Extension = extensions.find(
ext => ext.extensionId === event.target.value
);
if (extension.extensionExternal) {
@@ -384,7 +383,7 @@ function SettingsFileTypes(props: Props) {
}}
>
<MenuItem value="" />
- {props.extensions.map(
+ {extensions.map(
extension =>
(extension.extensionTypes.includes('viewer') ||
extension.extensionTypes.includes('editor')) && (
@@ -407,7 +406,7 @@ function SettingsFileTypes(props: Props) {
onChange={event => updateItems(item, 'editor', event.target.value)}
>
<MenuItem value="">{i18n.t('clearEditor')}</MenuItem>
- {props.extensions
+ {extensions
.filter(
extension =>
extension.extensionTypes &&
@@ -477,13 +476,15 @@ function SettingsFileTypes(props: Props) {
>
{i18n.t('core:addNewFileType')}
</Button>
- {props.isDevMode && (
+ {devMode && (
<Button
data-tid="resetFileTypesTID"
onClick={() => {
selectedItem.current = undefined;
- items.current = supportedFileTypes;
- props.setSupportedFileTypes(supportedFileTypes);
+ items.current = defaultSupportedFileTypes;
+ dispatch(
+ SettingsActions.setSupportedFileTypes(supportedFileTypes)
+ );
}}
color="secondary"
style={{ width: '50%' }}
@@ -533,22 +534,4 @@ function SettingsFileTypes(props: Props) {
);
}
-const mapStateToProps = state => ({
- supportedFileTypes: getSupportedFileTypes(state),
- extensions: getExtensions(state),
- isDevMode: isDevMode(state)
-});
-
-function mapDispatchToProps(dispatch) {
- return bindActionCreators(
- {
- setSupportedFileTypes: SettingsActions.setSupportedFileTypes
- },
- dispatch
- );
-}
-
-export default connect(
- mapStateToProps,
- mapDispatchToProps
-)(withStyles(styles)(SettingsFileTypes));
+export default withStyles(styles)(SettingsFileTypes);
diff --git a/app/components/dialogs/settings/SettingsGeneral.tsx b/app/components/dialogs/settings/SettingsGeneral.tsx
index 37571900b..80f4fbba7 100644
--- a/app/components/dialogs/settings/SettingsGeneral.tsx
+++ b/app/components/dialogs/settings/SettingsGeneral.tsx
@@ -17,8 +17,7 @@
*/
import React, { useState } from 'react';
-import { connect } from 'react-redux';
-import { bindActionCreators } from 'redux';
+import { useSelector, useDispatch } from 'react-redux';
import withStyles from '@mui/styles/withStyles';
import List from '@mui/material/List';
import ListItem from '@mui/material/ListItem';
@@ -49,6 +48,7 @@ import TransparentBackground from '-/components/TransparentBackground';
import { BetaLabel } from '-/components/HelperComponents';
import PlatformIO from '-/services/platform-facade';
import { PerspectiveIDs } from '-/perspectives';
+import { AppDispatch } from '-/reducers/app';
const styles: any = {
root: {
@@ -68,26 +68,7 @@ const styles: any = {
};
interface Props {
- setTagColor: (tagColor: string) => void;
- setTagTextColor: (tagTextColor: string) => void;
classes: any;
- settings: any;
- language: string;
- persistTagsInSidecarFile: boolean;
- toggleShowUnixHiddenEntries: () => void;
- setCurrentTheme: (theme: string) => void;
- setCurrentRegularTheme: (theme: string) => void;
- setCurrentDarkTheme: (theme: string) => void;
- setLanguage: (language: string) => void;
- setCheckForUpdates: (check: boolean) => void;
- reorderTags: (check: boolean) => void;
- setUseTrashCan: (useTrashCan: boolean) => void;
- setPersistTagsInSidecarFile: (tagInSidecar: boolean) => void;
- setAddTagsToLibrary: (addTagsToLibrary: boolean) => void;
- setUseGenerateThumbnails: (useGenerateThumbnails: boolean) => void;
- setTagDelimiter: (tagDelimiter: string) => void;
- setDefaultPerspective: (defaultPerspective: string) => void;
- setMaxSearchResult: (maxResult: string) => void;
}
function SettingsGeneral(props: Props) {
@@ -95,6 +76,10 @@ function SettingsGeneral(props: Props) {
const [displayTextColorPicker, setDisplayTextColorPicker] = useState<boolean>(
false
);
+ const dispatch: AppDispatch = useDispatch();
+ const settings = useSelector(getSettings);
+ const language = useSelector(getCurrentLanguage);
+ const persistTagsInSidecarFile = useSelector(getPersistTagsInSidecarFile);
const toggleDefaultTagBackgroundColorPicker = () => {
setDisplayColorPicker(!displayColorPicker);
@@ -113,20 +98,20 @@ function SettingsGeneral(props: Props) {
}; */
const handleMaxSearchResult = event => {
- props.setMaxSearchResult(event.target.value);
+ dispatch(SettingsActions.setMaxSearchResult(event.target.value));
};
const changePerspective = (event: any) => {
const perspective = event.target.value;
- props.setDefaultPerspective(perspective);
+ dispatch(SettingsActions.setDefaultPerspective(perspective));
};
let defaultPerspective = PerspectiveIDs.UNSPECIFIED;
- if (props.settings.defaultPerspective) {
- defaultPerspective = props.settings.defaultPerspective;
+ if (settings.defaultPerspective) {
+ defaultPerspective = settings.defaultPerspective;
}
- const { classes, persistTagsInSidecarFile, language } = props;
+ const { classes } = props;
return (
<List className={classes.root}>
@@ -134,14 +119,14 @@ function SettingsGeneral(props: Props) {
<ListItemText primary={i18n.t('core:interfaceLanguage')} />
<Select
data-tid="settingsSetLanguage"
- value={props.settings.interfaceLanguage}
+ value={settings.interfaceLanguage}
onChange={(event: any) => {
- props.setLanguage(event.target.value);
+ dispatch(SettingsActions.setLanguage(event.target.value));
PlatformIO.setLanguage(event.target.value);
}}
input={<Input id="languageSelector" />}
>
- {props.settings.supportedLanguages.map(language => (
+ {settings.supportedLanguages.map(language => (
<MenuItem key={language.iso} value={language.iso}>
{language.title}
</MenuItem>
@@ -152,11 +137,13 @@ function SettingsGeneral(props: Props) {
<ListItemText primary={i18n.t('core:themeSelector')} />
<Select
data-tid="settingsSetCurrentTheme"
- value={props.settings.currentTheme}
- onChange={(event: any) => props.setCurrentTheme(event.target.value)}
+ value={settings.currentTheme}
+ onChange={(event: any) =>
+ dispatch(SettingsActions.setCurrentTheme(event.target.value))
+ }
input={<Input id="themeSelector" />}
>
- {props.settings.supportedThemes.map(theme => (
+ {settings.supportedThemes.map(theme => (
<MenuItem key={theme} value={theme}>
{theme === 'light' && i18n.t('core:regularScheme')}
{theme === 'dark' && i18n.t('core:darkScheme')}
@@ -169,13 +156,13 @@ function SettingsGeneral(props: Props) {
<ListItemText primary={i18n.t('core:themeRegularSelector')} />
<Select
data-tid="settingsCurrentRegularThemeTID"
- value={props.settings.currentRegularTheme}
+ value={settings.currentRegularTheme}
onChange={(event: any) =>
- props.setCurrentRegularTheme(event.target.value)
+ dispatch(SettingsActions.setCurrentRegularTheme(event.target.value))
}
input={<Input id="themeRegularSelector" />}
>
- {props.settings.supportedRegularThemes.map(theme => (
+ {settings.supportedRegularThemes.map(theme => (
<MenuItem key={theme} value={theme}>
{theme.charAt(0).toUpperCase() + theme.slice(1)}
</MenuItem>
@@ -186,13 +173,13 @@ function SettingsGeneral(props: Props) {
<ListItemText primary={i18n.t('core:themeDarkSelector')} />
<Select
data-tid="settingsCurrentDarkThemeTID"
- value={props.settings.currentDarkTheme}
+ value={settings.currentDarkTheme}
onChange={(event: any) =>
- props.setCurrentDarkTheme(event.target.value)
+ dispatch(SettingsActions.setCurrentDarkTheme(event.target.value))
}
input={<Input id="themeDarkSelector" />}
>
- {props.settings.supportedDarkThemes.map(theme => (
+ {settings.supportedDarkThemes.map(theme => (
<MenuItem key={theme} value={theme}>
{theme.charAt(0).toUpperCase() + theme.slice(1)}
</MenuItem>
@@ -232,7 +219,9 @@ function SettingsGeneral(props: Props) {
<ToggleButton
value={false}
data-tid="settingsSetPersistTagsInFileName"
- onClick={() => props.setPersistTagsInSidecarFile(false)}
+ onClick={() =>
+ dispatch(SettingsActions.setPersistTagsInSidecarFile(false))
+ }
>
<Tooltip
title={
@@ -251,7 +240,9 @@ function SettingsGeneral(props: Props) {
<ToggleButton
value={true}
data-tid="settingsSetPersistTagsInSidecarFile"
- onClick={() => props.setPersistTagsInSidecarFile(true)}
+ onClick={() =>
+ dispatch(SettingsActions.setPersistTagsInSidecarFile(true))
+ }
>
<Tooltip
title={
@@ -275,9 +266,11 @@ function SettingsGeneral(props: Props) {
<Switch
data-tid="settingsSetCheckForUpdates"
onClick={() =>
- props.setCheckForUpdates(!props.settings.checkForUpdates)
+ dispatch(
+ SettingsActions.setCheckForUpdates(!settings.checkForUpdates)
+ )
}
- checked={props.settings.checkForUpdates}
+ checked={settings.checkForUpdates}
/>
</ListItem>
<ListItem className={classes.listItem}>
@@ -291,8 +284,10 @@ function SettingsGeneral(props: Props) {
/>
<Switch
data-tid="reorderTagsTID"
- onClick={() => props.reorderTags(!props.settings.reorderTags)}
- checked={props.settings.reorderTags}
+ onClick={() =>
+ dispatch(SettingsActions.reorderTags(!settings.reorderTags))
+ }
+ checked={settings.reorderTags}
/>
</ListItem>
<ListItem className={classes.listItem}>
@@ -300,9 +295,11 @@ function SettingsGeneral(props: Props) {
<Switch
data-tid="settingsSetAddTagsToLibrary"
onClick={() =>
- props.setAddTagsToLibrary(!props.settings.addTagsToLibrary)
+ dispatch(
+ SettingsActions.setAddTagsToLibrary(!settings.addTagsToLibrary)
+ )
}
- checked={props.settings.addTagsToLibrary}
+ checked={settings.addTagsToLibrary}
/>
</ListItem>
<ListItem className={classes.listItem}>
@@ -311,14 +308,16 @@ function SettingsGeneral(props: Props) {
disabled={AppConfig.useGenerateThumbnails !== undefined}
data-tid="settingsUseGenerateThumbnails"
onClick={() =>
- props.setUseGenerateThumbnails(
- !props.settings.useGenerateThumbnails
+ dispatch(
+ SettingsActions.setUseGenerateThumbnails(
+ !settings.useGenerateThumbnails
+ )
)
}
checked={
AppConfig.useGenerateThumbnails !== undefined
? AppConfig.useGenerateThumbnails
- : props.settings.useGenerateThumbnails
+ : settings.useGenerateThumbnails
}
/>
</ListItem>
@@ -330,7 +329,7 @@ function SettingsGeneral(props: Props) {
className={classes.colorChooserButton}
size="small"
style={{
- backgroundColor: props.settings.tagBackgroundColor
+ backgroundColor: settings.tagBackgroundColor
}}
onClick={toggleDefaultTagBackgroundColorPicker}
>
@@ -341,10 +340,10 @@ function SettingsGeneral(props: Props) {
<ColorPickerDialog
open={displayColorPicker}
setColor={color => {
- props.setTagColor(color);
+ dispatch(SettingsActions.setTagColor(color));
}}
onClose={toggleDefaultTagBackgroundColorPicker}
- color={props.settings.tagBackgroundColor}
+ color={settings.tagBackgroundColor}
/>
)}
</ListItem>
@@ -355,7 +354,7 @@ function SettingsGeneral(props: Props) {
data-tid="settingsToggleDefaultTagForegroundColor"
className={classes.colorChooserButton}
size="small"
- style={{ backgroundColor: props.settings.tagTextColor }}
+ style={{ backgroundColor: settings.tagTextColor }}
onClick={toggleDefaultTagTextColorPicker}
>
&nbsp;
@@ -365,10 +364,10 @@ function SettingsGeneral(props: Props) {
<ColorPickerDialog
open={displayTextColorPicker}
setColor={color => {
- props.setTagTextColor(color);
+ dispatch(SettingsActions.setTagTextColor(color));
}}
onClose={toggleDefaultTagTextColorPicker}
- color={props.settings.tagTextColor}
+ color={settings.tagTextColor}
/>
)}
</ListItem>
@@ -384,8 +383,10 @@ function SettingsGeneral(props: Props) {
/>
<Switch
data-tid="settingsSetUseTrashCan"
- onClick={() => props.setUseTrashCan(!props.settings.useTrashCan)}
- checked={props.settings.useTrashCan}
+ onClick={() =>
+ dispatch(SettingsActions.setUseTrashCan(!settings.useTrashCan))
+ }
+ checked={settings.useTrashCan}
/>
</ListItem>
)}
@@ -393,8 +394,10 @@ function SettingsGeneral(props: Props) {
<ListItemText primary={i18n.t('core:showUnixHiddenFiles')} />
<Switch
data-tid="settingsSetShowUnixHiddenEntries"
- onClick={props.toggleShowUnixHiddenEntries}
- checked={props.settings.showUnixHiddenEntries}
+ onClick={() =>
+ dispatch(SettingsActions.toggleShowUnixHiddenEntries())
+ }
+ checked={settings.showUnixHiddenEntries}
/>
</ListItem>
{/* <ListItem className={classes.listItem}>
@@ -402,7 +405,7 @@ function SettingsGeneral(props: Props) {
<Select
style={{ minWidth: '170px' }}
data-tid="settingsTagDelimiterChoose"
- value={this.props.settings.tagDelimiter}
+ value={this.settings.tagDelimiter}
onChange={this.handleTagDelimiterChange}
inputProps={{
name: 'tagDelimiter',
@@ -420,7 +423,7 @@ function SettingsGeneral(props: Props) {
style={{ maxWidth: '100px' }}
type="number"
data-tid="settingsMaxSearchResult"
- value={props.settings.maxSearchResult}
+ value={settings.maxSearchResult}
onChange={handleMaxSearchResult}
/>
</ListItem>
@@ -428,20 +431,4 @@ function SettingsGeneral(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- settings: getSettings(state),
- language: getCurrentLanguage(state),
- persistTagsInSidecarFile: getPersistTagsInSidecarFile(state)
- };
-}
-
-function mapActionCreatorsToProps(dispatch) {
- return bindActionCreators(SettingsActions, dispatch);
-}
-
-export default connect(
- mapStateToProps,
- mapActionCreatorsToProps
- // @ts-ignore
-)(withStyles(styles, { withTheme: true })(SettingsGeneral));
+export default withStyles(styles, { withTheme: true })(SettingsGeneral);
diff --git a/app/components/dialogs/settings/SettingsKeyBindings.tsx b/app/components/dialogs/settings/SettingsKeyBindings.tsx
index 7d8c1a684..9fa49ab9f 100644
--- a/app/components/dialogs/settings/SettingsKeyBindings.tsx
+++ b/app/components/dialogs/settings/SettingsKeyBindings.tsx
@@ -17,8 +17,7 @@
*/
import React from 'react';
-import { connect } from 'react-redux';
-import { bindActionCreators } from 'redux';
+import { useSelector, useDispatch } from 'react-redux';
import withStyles from '@mui/styles/withStyles';
import TextField from '@mui/material/TextField';
import Switch from '@mui/material/Switch';
@@ -33,6 +32,7 @@ import {
isGlobalKeyBindingEnabled
} from '-/reducers/settings';
import DefaultSettings from '-/reducers/settings-default';
+import { AppDispatch } from '-/reducers/app';
const styles: any = (theme: any) => ({
keyBinding: {
@@ -43,20 +43,22 @@ const styles: any = (theme: any) => ({
interface Props {
classes: any;
- keyBindings: Array<any>;
- setKeyBinding: (kbName: string, kbCommand: string) => void;
- setGlobalKeyBinding: (value: boolean) => void;
- globalKeyBindingEnabled: boolean;
}
-
function SettingsKeyBindings(props: Props) {
- const {
- keyBindings,
- classes,
- setKeyBinding,
- setGlobalKeyBinding,
- globalKeyBindingEnabled
- } = props;
+ const { classes } = props;
+ const keyBindings = useSelector(getKeyBindings);
+ const globalKeyBindingEnabled = useSelector(isGlobalKeyBindingEnabled);
+ const dispatch: AppDispatch = useDispatch();
+
+ const setKeyBinding = (kbName, kbCommand) => {
+ dispatch(SettingsActions.setKeyBinding(kbName, kbCommand));
+ };
+
+ const setGlobalKeyBinding = value => {
+ dispatch(SettingsActions.setGlobalKeyBinding(value));
+ PlatformIO.setGlobalShortcuts(value);
+ };
+
return (
<form className={classes.root} noValidate autoComplete="off">
<ListItem style={{ paddingLeft: 0, paddingRight: 0 }}>
@@ -64,7 +66,6 @@ function SettingsKeyBindings(props: Props) {
<Switch
onClick={() => {
setGlobalKeyBinding(!globalKeyBindingEnabled);
- PlatformIO.setGlobalShortcuts(!globalKeyBindingEnabled);
}}
checked={globalKeyBindingEnabled}
/>
@@ -93,24 +94,4 @@ function SettingsKeyBindings(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- keyBindings: getKeyBindings(state),
- globalKeyBindingEnabled: isGlobalKeyBindingEnabled(state)
- };
-}
-
-function mapActionCreatorsToProps(dispatch) {
- return bindActionCreators(
- {
- setKeyBinding: SettingsActions.setKeyBinding,
- setGlobalKeyBinding: SettingsActions.setGlobalKeyBinding
- },
- dispatch
- );
-}
-
-export default connect(
- mapStateToProps,
- mapActionCreatorsToProps
-)(withStyles(styles)(SettingsKeyBindings));
+export default withStyles(styles)(SettingsKeyBindings);
diff --git a/app/components/menus/DirectoryMenu.tsx b/app/components/menus/DirectoryMenu.tsx
index 3b44d89a1..e72bd39a9 100644
--- a/app/components/menus/DirectoryMenu.tsx
+++ b/app/components/menus/DirectoryMenu.tsx
@@ -16,11 +16,9 @@
*
*/
-import React, { useRef, useState } from 'react';
-import { bindActionCreators } from 'redux';
-import { connect } from 'react-redux';
+import React, { useRef } from 'react';
+import { useSelector, useDispatch } from 'react-redux';
import Menu from '@mui/material/Menu';
-import { Progress } from 'aws-sdk/clients/s3';
import { formatDateTime4Tag } from '@tagspaces/tagspaces-common/misc';
import AppConfig from '-/AppConfig';
import {
@@ -35,6 +33,7 @@ import i18n from '-/services/i18n';
import PlatformIO from '-/services/platform-facade';
import {
actions as AppActions,
+ AppDispatch,
getDirectoryPath,
getLastSelectedEntryPath,
getSelectedEntries,
@@ -51,6 +50,7 @@ import { getRelativeEntryPath } from '-/services/utils-io';
import { PerspectiveIDs } from '-/perspectives';
import PlatformFacade from '-/services/platform-facade';
import { getDirectoryMenuItems } from '-/perspectives/common/DirectoryMenuItems';
+import { getLocations } from '-/reducers/locations';
interface Props {
open: boolean;
@@ -67,58 +67,109 @@ interface Props {
openFsEntry: (fsEntry: TS.FileSystemEntry) => void;
openAddRemoveTagsDialog?: () => void;
reflectCreateEntry?: (path: string, isFile: boolean) => void;
- toggleNewFileDialog?: () => void;
- uploadFilesAPI: (
- files: Array<File>,
- destination: string,
- onUploadProgress?: (progress: Progress, response: any) => void
- ) => any;
- reflectCreateEntries: (fsEntries: Array<TS.FileSystemEntry>) => void;
- onUploadProgress: (progress: Progress, response: any) => void;
switchPerspective?: (perspectiveId: string) => void;
- toggleProTeaser?: (slidePage?: string) => void;
- setCurrentDirectoryPerspective: (perspective: string) => void;
perspectiveMode?: boolean;
- showNotification?: (
- text: string,
- notificationType?: string,
- autohide?: boolean
- ) => void;
- toggleUploadDialog: () => void;
- toggleProgressDialog: () => void;
- resetProgress: () => void;
- addTags: (
- paths: Array<string>,
- tags: Array<TS.Tag>,
- updateIndex: boolean
- ) => void;
- toggleDeleteMultipleEntriesDialog: () => void;
openRenameDirectoryDialog: () => void;
openMoveCopyFilesDialog: () => void;
- selectedEntries: Array<TS.FileSystemEntry>;
- currentDirectoryPath: string;
- lastSelectedEntryPath: string;
- isReadOnlyMode: boolean;
- setSelectedEntries: (selectedEntries: Array<TS.FileSystemEntry>) => void;
mouseX?: number;
mouseY?: number;
- openURLExternally?: (url: string, skipConfirmation: boolean) => void;
currentLocation?: TS.Location;
- locations?: Array<TS.Location>;
- toggleCreateDirectoryDialog: () => void;
}
function DirectoryMenu(props: Props) {
const fileUploadContainerRef = useRef<FileUploadContainerRef>(null);
-
const {
- selectedEntries,
+ open,
+ onClose,
+ anchorEl,
+ mouseX,
+ mouseY,
+ directoryPath,
currentLocation,
- locations,
- toggleProTeaser,
- showNotification
+ openAddRemoveTagsDialog,
+ openMoveCopyFilesDialog,
+ openRenameDirectoryDialog
} = props;
+ const selectedEntries: Array<TS.FileSystemEntry> = useSelector(
+ getSelectedEntries
+ );
+ const locations: Array<TS.Location> = useSelector(getLocations);
+ const currentDirectoryPath = useSelector(getDirectoryPath);
+ const lastSelectedEntryPath = useSelector(getLastSelectedEntryPath);
+ const readOnlyMode = useSelector(isReadOnlyMode);
+ const dispatch: AppDispatch = useDispatch();
+
+ const loadDirectoryContent = (path, generateThumbnails, loadDirMeta) => {
+ dispatch(
+ AppActions.loadDirectoryContent(path, generateThumbnails, loadDirMeta)
+ );
+ };
+
+ const toggleCreateDirectoryDialog = () => {
+ dispatch(AppActions.toggleCreateDirectoryDialog());
+ };
+
+ const openFsEntry = fsEntry => {
+ dispatch(AppActions.openFsEntry(fsEntry));
+ };
+
+ const reflectCreateEntry = (path, isFile) => {
+ dispatch(AppActions.reflectCreateEntry(path, isFile));
+ };
+
+ const toggleNewFileDialog = () => {
+ dispatch(AppActions.toggleNewFileDialog());
+ };
+
+ const uploadFilesAPI = (files, destination, onUploadProgress) => {
+ dispatch(IOActions.uploadFilesAPI(files, destination, onUploadProgress));
+ };
+
+ const reflectCreateEntries = fsEntries => {
+ dispatch(AppActions.reflectCreateEntries(fsEntries));
+ };
+
+ const onUploadProgress = (progress, response) => {
+ dispatch(AppActions.onUploadProgress(progress, response));
+ };
+
+ const toggleUploadDialog = () => {
+ dispatch(AppActions.toggleUploadDialog());
+ };
+
+ const toggleProgressDialog = () => {
+ dispatch(AppActions.toggleProgressDialog());
+ };
+
+ const resetProgress = () => {
+ dispatch(AppActions.resetProgress());
+ };
+
+ const addTags = (paths, tags, updateIndex) => {
+ dispatch(TaggingActions.addTags(paths, tags, updateIndex));
+ };
+
+ const toggleDeleteMultipleEntriesDialog = () => {
+ dispatch(AppActions.toggleDeleteMultipleEntriesDialog());
+ };
+
+ const setSelectedEntries = selectedEntries => {
+ dispatch(AppActions.setSelectedEntries(selectedEntries));
+ };
+
+ const showNotification = (text, notificationType?, autohide?) => {
+ dispatch(AppActions.showNotification(text, notificationType, autohide));
+ };
+
+ const toggleProTeaser = slidePage => {
+ dispatch(AppActions.toggleProTeaser(slidePage));
+ };
+
+ const setCurrentDirectoryPerspective = perspective => {
+ dispatch(AppActions.setCurrentDirectoryPerspective(perspective));
+ };
+
function generateFolderLink() {
const entryFromIndex = selectedEntries[0]['locationID'];
const locationID = entryFromIndex
@@ -151,25 +202,22 @@ function DirectoryMenu(props: Props) {
] = useState(false);*/
function reloadDirectory() {
- props.loadDirectoryContent(props.directoryPath, true, true);
+ loadDirectoryContent(directoryPath, true, true);
}
function openDirectory() {
- props.loadDirectoryContent(props.directoryPath, true, true);
+ loadDirectoryContent(directoryPath, true, true);
}
function showProperties() {
- getAllPropertiesPromise(props.directoryPath)
+ getAllPropertiesPromise(directoryPath)
.then((fsEntry: TS.FileSystemEntry) => {
- props.openFsEntry(fsEntry);
+ openFsEntry(fsEntry);
return true;
})
.catch(error =>
console.warn(
- 'Error getting properties for entry: ' +
- props.directoryPath +
- ' - ' +
- error
+ 'Error getting properties for entry: ' + directoryPath + ' - ' + error
)
);
}
@@ -180,16 +228,16 @@ function DirectoryMenu(props: Props) {
perspectiveId === PerspectiveIDs.GRID ||
perspectiveId === PerspectiveIDs.LIST
) {
- if (props.switchPerspective) {
- props.switchPerspective(perspectiveId);
+ if (switchPerspective) {
+ switchPerspective(perspectiveId);
} else {
- props.setCurrentDirectoryPerspective(perspectiveId);
+ setCurrentDirectoryPerspective(perspectiveId);
}
} else if (perspectiveId === PerspectiveIDs.GALLERY) {
toggleProTeaser(PerspectiveIDs.GALLERY);
// const openPersDocs = window.confirm(i18n.t('perspectiveInPro'));
// if (openPersDocs) {
- // props.openURLExternally(
+ // openURLExternally(
// Links.documentationLinks.galleryPerspective,
// true
// );
@@ -198,7 +246,7 @@ function DirectoryMenu(props: Props) {
toggleProTeaser(PerspectiveIDs.MAPIQUE);
// const openPersDocs = window.confirm(i18n.t('perspectiveInPro'));
// if (openPersDocs) {
- // props.openURLExternally(
+ // openURLExternally(
// Links.documentationLinks.mapiquePerspective,
// true
// );
@@ -207,7 +255,7 @@ function DirectoryMenu(props: Props) {
toggleProTeaser(PerspectiveIDs.KANBAN);
// const openPersDocs = window.confirm(i18n.t('perspectiveInPro'));
// if (openPersDocs) {
- // props.openURLExternally(
+ // openURLExternally(
// Links.documentationLinks.kanbanPerspective,
// true
// );
@@ -216,25 +264,17 @@ function DirectoryMenu(props: Props) {
}
function showDeleteDirectoryDialog() {
- props.setSelectedEntries([
+ setSelectedEntries([
{
isFile: false,
- name: props.directoryPath,
- path: props.directoryPath,
+ name: directoryPath,
+ path: directoryPath,
tags: [],
size: 0,
lmdt: 0
}
]);
- props.toggleDeleteMultipleEntriesDialog();
- }
-
- function showRenameDirectoryDialog() {
- props.openRenameDirectoryDialog();
- }
-
- function openMoveCopyDialog() {
- props.openMoveCopyFilesDialog();
+ toggleDeleteMultipleEntriesDialog();
}
/*function showCreateDirectoryDialog() {
@@ -242,11 +282,11 @@ function DirectoryMenu(props: Props) {
}*/
function createNewFile() {
- props.toggleNewFileDialog();
+ toggleNewFileDialog();
}
function showInFileManager() {
- props.openDirectory(props.directoryPath);
+ dispatch(AppActions.openDirectory(directoryPath));
}
function openInNewWindow() {
@@ -272,13 +312,13 @@ Do you want to continue?`)
) {
return false;
}
- props.toggleProgressDialog();
+ toggleProgressDialog();
const entryCallback = entry => {
PlatformFacade.readMacOSTags(entry.path)
.then(tags => {
if (tags.length > 0) {
- props.addTags([entry.path], tags, true);
+ addTags([entry.path], tags, true);
}
return tags;
})
@@ -286,13 +326,13 @@ Do you want to continue?`)
console.warn('Error creating tags: ' + err);
});
};
- Pro.MacTagsImport.importTags(props.directoryPath, entryCallback)
+ Pro.MacTagsImport.importTags(directoryPath, entryCallback)
.then(() => {
- // props.loadDirectoryContent(props.directoryPath); // TODO after first import tags is not imported without reloadDirContent
- props.toggleProgressDialog();
- console.log('Import tags succeeded ' + props.directoryPath);
- props.showNotification(
- 'Tags from ' + props.directoryPath + ' are imported successfully.',
+ // loadDirectoryContent(directoryPath); // TODO after first import tags is not imported without reloadDirContent
+ toggleProgressDialog();
+ console.log('Import tags succeeded ' + directoryPath);
+ showNotification(
+ 'Tags from ' + directoryPath + ' are imported successfully.',
'default',
true
);
@@ -300,10 +340,10 @@ Do you want to continue?`)
})
.catch(err => {
console.warn('Error importing tags: ' + err);
- props.toggleProgressDialog();
+ toggleProgressDialog();
});
} else {
- props.showNotification(
+ showNotification(
i18n.t('core:thisFunctionalityIsAvailableInPro'),
'default',
true
@@ -336,24 +376,22 @@ Do you want to continue?`)
AppConfig.endTagContainer +
'.jpg';
const newFilePath =
- normalizePath(props.directoryPath) +
- PlatformIO.getDirSeparator() +
- fileName;
+ normalizePath(directoryPath) + PlatformIO.getDirSeparator() + fileName;
PlatformIO.renameFilePromise(filePath, newFilePath)
.then(() => {
- props.showNotification(
+ showNotification(
'File ' + newFilePath + ' successfully imported.',
'default',
true
);
- props.reflectCreateEntry(newFilePath, true);
+ reflectCreateEntry(newFilePath, true);
return true;
})
.catch(error => {
// TODO showAlertDialog("Saving " + filePath + " failed.");
console.error('Save to file ' + newFilePath + ' failed ' + error);
- props.showNotification(
+ showNotification(
'Importing file ' + newFilePath + ' failed.',
'error',
true
@@ -363,7 +401,7 @@ Do you want to continue?`)
}
// function loadImageLocal() {
- // props.onClose();
+ // onClose();
// navigator.camera.getPicture(onCameraSuccess, onFail, {
// destinationType: Camera.DestinationType.FILE_URI,
// sourceType: Camera.PictureSourceType.PHOTOLIBRARY
@@ -384,7 +422,7 @@ Do you want to continue?`)
function setFolderThumbnail() {
const parentDirectoryPath = extractContainingDirectoryPath(
- props.directoryPath,
+ directoryPath,
PlatformIO.getDirSeparator()
);
const parentDirectoryName = extractDirectoryName(
@@ -394,7 +432,7 @@ Do you want to continue?`)
PlatformIO.copyFilePromise(
getThumbFileLocationForDirectory(
- props.directoryPath,
+ directoryPath,
PlatformIO.getDirSeparator()
),
getThumbFileLocationForDirectory(
@@ -404,7 +442,7 @@ Do you want to continue?`)
i18n.t('core:thumbAlreadyExists', { directoryName: parentDirectoryName })
)
.then(() => {
- props.showNotification(
+ showNotification(
'Thumbnail created for: ' + parentDirectoryPath,
'default',
true
@@ -412,29 +450,26 @@ Do you want to continue?`)
return true;
})
.catch(error => {
- props.showNotification('Thumbnail creation failed.', 'default', true);
- console.warn(
- 'Error setting Thumb for entry: ' + props.directoryPath,
- error
- );
+ showNotification('Thumbnail creation failed.', 'default', true);
+ console.warn('Error setting Thumb for entry: ' + directoryPath, error);
return true;
});
}
const menuItems = getDirectoryMenuItems(
currentLocation,
- props.selectedEntries.length,
- props.lastSelectedEntryPath !== props.currentDirectoryPath,
- props.isReadOnlyMode,
- props.onClose,
+ selectedEntries.length,
+ lastSelectedEntryPath !== currentDirectoryPath,
+ readOnlyMode,
+ onClose,
openDirectory,
reloadDirectory,
- showRenameDirectoryDialog,
- openMoveCopyDialog,
+ openRenameDirectoryDialog,
+ openMoveCopyFilesDialog,
showDeleteDirectoryDialog,
showInFileManager,
createNewFile,
- props.toggleCreateDirectoryDialog,
+ toggleCreateDirectoryDialog,
addExistingFile,
setFolderThumbnail,
copySharingLink,
@@ -442,73 +477,35 @@ Do you want to continue?`)
switchPerspective,
showProperties,
cameraTakePicture,
- props.openAddRemoveTagsDialog,
+ openAddRemoveTagsDialog,
openInNewWindow
);
return (
<div style={{ overflowY: 'hidden' }}>
<Menu
- anchorEl={props.anchorEl}
- open={props.open}
- onClose={props.onClose}
- anchorReference={
- props.mouseY && props.mouseX ? 'anchorPosition' : undefined
- }
+ anchorEl={anchorEl}
+ open={open}
+ onClose={onClose}
+ anchorReference={mouseY && mouseX ? 'anchorPosition' : undefined}
anchorPosition={
- props.mouseY && props.mouseX
- ? { top: props.mouseY, left: props.mouseX }
- : undefined
+ mouseY && mouseX ? { top: mouseY, left: mouseX } : undefined
}
>
{menuItems}
</Menu>
<FileUploadContainer
ref={fileUploadContainerRef}
- directoryPath={props.directoryPath}
- onUploadProgress={props.onUploadProgress}
- toggleUploadDialog={props.toggleUploadDialog}
- toggleProgressDialog={props.toggleProgressDialog}
- resetProgress={props.resetProgress}
- reflectCreateEntries={props.reflectCreateEntries}
- uploadFilesAPI={props.uploadFilesAPI}
+ directoryPath={directoryPath}
+ onUploadProgress={onUploadProgress}
+ toggleUploadDialog={toggleUploadDialog}
+ toggleProgressDialog={toggleProgressDialog}
+ resetProgress={resetProgress}
+ reflectCreateEntries={reflectCreateEntries}
+ uploadFilesAPI={uploadFilesAPI}
/>
</div>
);
}
-function mapStateToProps(state) {
- return {
- selectedEntries: getSelectedEntries(state),
- currentDirectoryPath: getDirectoryPath(state),
- lastSelectedEntryPath: getLastSelectedEntryPath(state),
- isReadOnlyMode: isReadOnlyMode(state)
- };
-}
-
-function mapDispatchToProps(dispatch) {
- return bindActionCreators(
- {
- showNotification: AppActions.showNotification,
- onUploadProgress: AppActions.onUploadProgress,
- toggleUploadDialog: AppActions.toggleUploadDialog,
- toggleProgressDialog: AppActions.toggleProgressDialog,
- toggleNewFileDialog: AppActions.toggleNewFileDialog,
- toggleCreateDirectoryDialog: AppActions.toggleCreateDirectoryDialog,
- toggleProTeaser: AppActions.toggleProTeaser,
- resetProgress: AppActions.resetProgress,
- reflectCreateEntries: AppActions.reflectCreateEntries,
- setCurrentDirectoryPerspective: AppActions.setCurrentDirectoryPerspective,
- extractContent: IOActions.extractContent,
- uploadFilesAPI: IOActions.uploadFilesAPI,
- addTags: TaggingActions.addTags,
- toggleDeleteMultipleEntriesDialog:
- AppActions.toggleDeleteMultipleEntriesDialog,
- setSelectedEntries: AppActions.setSelectedEntries,
- openURLExternally: AppActions.openURLExternally
- },
- dispatch
- );
-}
-
-export default connect(mapStateToProps, mapDispatchToProps)(DirectoryMenu);
+export default DirectoryMenu;
diff --git a/app/components/menus/EntryTagMenu.tsx b/app/components/menus/EntryTagMenu.tsx
index 22b568fd8..d292efc1b 100644
--- a/app/components/menus/EntryTagMenu.tsx
+++ b/app/components/menus/EntryTagMenu.tsx
@@ -17,8 +17,7 @@
*/
import React, { useState } from 'react';
-import { bindActionCreators } from 'redux';
-import { connect } from 'react-redux';
+import { useDispatch, useSelector } from 'react-redux';
import EditIcon from '@mui/icons-material/Edit';
import DeleteIcon from '@mui/icons-material/DeleteForever';
import AddIcon from '@mui/icons-material/Add';
@@ -31,7 +30,11 @@ import ConfirmDialog from '../dialogs/ConfirmDialog';
import i18n from '-/services/i18n';
import { actions as LocationIndexActions } from '-/reducers/location-index';
import { getMaxSearchResults } from '-/reducers/settings';
-import { actions as AppActions } from '-/reducers/app';
+import {
+ actions as AppActions,
+ AppDispatch,
+ isReadOnlyMode
+} from '-/reducers/app';
import { TS } from '-/tagspaces.namespace';
interface Props {
@@ -41,43 +44,58 @@ interface Props {
selectedTag: TS.Tag | null;
currentEntryPath: string;
removeTags: (paths: Array<string>, tags: Array<TS.Tag>) => void;
- setSearchQuery: (searchQuery: TS.SearchQuery) => void;
- maxSearchResults?: number;
setIsAddTagDialogOpened?: (tag: TS.Tag) => void;
- toggleEditTagDialog?: (tag: TS.Tag) => void;
- isReadOnlyMode?: boolean;
}
function EntryTagMenu(props: Props) {
+ const {
+ open,
+ onClose,
+ anchorEl,
+ selectedTag,
+ currentEntryPath,
+ removeTags,
+ setIsAddTagDialogOpened
+ } = props;
const [isDeleteTagDialogOpened, setIsDeleteTagDialogOpened] = useState(false);
+ const dispatch: AppDispatch = useDispatch();
+ const maxSearchResults: number = useSelector(getMaxSearchResults);
+ const readOnlyMode = useSelector(isReadOnlyMode);
+
+ const setSearchQuery = searchQuery => {
+ dispatch(LocationIndexActions.setSearchQuery(searchQuery));
+ };
+
+ const toggleEditTagDialog = tag => {
+ dispatch(AppActions.toggleEditTagDialog(tag));
+ };
function showEditTagDialog() {
- props.onClose();
- // setIsEditTagDialogOpened(true);
- const tag = props.selectedTag;
- tag.path = props.currentEntryPath;
- props.toggleEditTagDialog(tag);
+ onClose();
+ const tag = selectedTag;
+ tag.path = currentEntryPath;
+ toggleEditTagDialog(tag);
}
function showDeleteTagDialog() {
- props.onClose();
+ onClose();
setIsDeleteTagDialogOpened(true);
}
function showAddTagDialog() {
- props.onClose();
- props.setIsAddTagDialogOpened(props.selectedTag);
+ onClose();
+ setIsAddTagDialogOpened(selectedTag);
}
function showFilesWithThisTag() {
- if (props.selectedTag) {
- props.setSearchQuery({
- tagsAND: [props.selectedTag],
- maxSearchResults: props.maxSearchResults,
+ if (selectedTag) {
+ setSearchQuery({
+ tagsAND: [selectedTag],
+ maxSearchResults: maxSearchResults,
executeSearch: true
});
}
- props.onClose();
+ onClose();
}
function handleCloseDialogs() {
@@ -85,7 +103,7 @@ function EntryTagMenu(props: Props) {
}
function confirmRemoveTag() {
- props.removeTags([props.currentEntryPath], [props.selectedTag]);
+ removeTags([currentEntryPath], [selectedTag]);
handleCloseDialogs();
}
@@ -101,8 +119,8 @@ function EntryTagMenu(props: Props) {
<ListItemText primary={i18n.t('core:showFilesWithThisTag')} />
</MenuItem>
];
- if (!props.isReadOnlyMode) {
- if (props.setIsAddTagDialogOpened) {
+ if (!readOnlyMode) {
+ if (setIsAddTagDialogOpened) {
menuItems.push(
<MenuItem
key="addTagMenu"
@@ -144,7 +162,7 @@ function EntryTagMenu(props: Props) {
return (
<div style={{ overflowY: 'hidden' }}>
- <Menu anchorEl={props.anchorEl} open={props.open} onClose={props.onClose}>
+ <Menu anchorEl={anchorEl} open={open} onClose={onClose}>
{menuItems}
</Menu>
<ConfirmDialog
@@ -165,20 +183,4 @@ function EntryTagMenu(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- maxSearchResults: getMaxSearchResults(state)
- };
-}
-
-function mapDispatchToProps(dispatch) {
- return bindActionCreators(
- {
- setSearchQuery: LocationIndexActions.setSearchQuery,
- toggleEditTagDialog: AppActions.toggleEditTagDialog
- },
- dispatch
- );
-}
-
-export default connect(mapStateToProps, mapDispatchToProps)(EntryTagMenu);
+export default EntryTagMenu;
diff --git a/app/components/menus/FileMenu.tsx b/app/components/menus/FileMenu.tsx
index 5e26efcf3..520313187 100644
--- a/app/components/menus/FileMenu.tsx
+++ b/app/components/menus/FileMenu.tsx
@@ -54,22 +54,20 @@ import {
} from '-/services/utils-io';
import { Pro } from '-/pro';
import { TS } from '-/tagspaces.namespace';
-import { bindActionCreators } from 'redux';
-import { actions as AppActions } from '-/reducers/app';
-import { connect } from 'react-redux';
-import { supportedImgs } from '-/services/thumbsgenerator';
import {
- getEnableWS,
- getMapTileServers,
- getPrefixTagContainer,
- getSettings,
- isDevMode
-} from '-/reducers/settings';
+ actions as AppActions,
+ AppDispatch,
+ isReadOnlyMode
+} from '-/reducers/app';
+import { useSelector, useDispatch } from 'react-redux';
+import { supportedImgs } from '-/services/thumbsgenerator';
+import { getPrefixTagContainer } from '-/reducers/settings';
import {
OpenNewWindowIcon,
DeleteIcon,
LinkIcon
} from '-/components/CommonIcons';
+import { getLocations } from '-/reducers/locations';
interface Props {
anchorEl: Element;
@@ -82,7 +80,6 @@ interface Props {
openMoveCopyFilesDialog: () => void;
openShareFilesDialog?: () => void;
openAddRemoveTagsDialog: () => void;
- openFsEntry: (fsEntry: TS.FileSystemEntry) => void;
loadDirectoryContent: (
path: string,
generateThumbnails: boolean,
@@ -90,34 +87,40 @@ interface Props {
) => void;
openFileNatively: (path: string) => void;
showInFileManager: (path: string) => void;
- showNotification: (
- text: string,
- notificationType?: string,
- autohide?: boolean
- ) => void;
selectedFilePath?: string;
- isReadOnlyMode: boolean;
selectedEntries: Array<any>;
currentLocation: TS.Location;
- locations: Array<TS.Location>;
- setLastBackgroundImageChange: (path: string, dt: number) => void;
reorderTop?: () => void;
reorderBottom?: () => void;
onDuplicateFile?: (fileDirPath: string) => void;
- exitSearchMode: () => void;
- prefixTagContainer: string;
}
function FileMenu(props: Props) {
const {
+ openDeleteFileDialog,
+ openRenameFileDialog,
+ openMoveCopyFilesDialog,
+ openShareFilesDialog,
+ openAddRemoveTagsDialog,
+ showInFileManager,
+ onDuplicateFile,
+ loadDirectoryContent,
selectedEntries,
- isReadOnlyMode,
+ openFileNatively,
currentLocation,
+ reorderTop,
+ reorderBottom,
+ anchorEl,
+ mouseX,
+ mouseY,
+ open,
onClose,
- selectedFilePath,
- showNotification,
- locations
+ selectedFilePath
} = props;
+ const dispatch: AppDispatch = useDispatch();
+ const locations: Array<TS.Location> = useSelector(getLocations);
+ const readOnlyMode = useSelector(isReadOnlyMode);
+ const prefixTagContainer = useSelector(getPrefixTagContainer);
function generateFileLink() {
const entryFromIndex = selectedEntries[0].locationID;
@@ -137,46 +140,52 @@ function FileMenu(props: Props) {
navigator.clipboard
.writeText(sharingLink)
.then(() => {
- showNotification(i18n.t('core:sharingLinkCopied'));
+ dispatch(
+ AppActions.showNotification(i18n.t('core:sharingLinkCopied'))
+ );
return true;
})
.catch(() => {
- showNotification(i18n.t('core:sharingLinkFailed'));
+ dispatch(
+ AppActions.showNotification(i18n.t('core:sharingLinkFailed'))
+ );
});
}
}
function showDeleteFileDialog() {
onClose();
- props.openDeleteFileDialog();
+ openDeleteFileDialog();
}
function showRenameFileDialog() {
onClose();
- props.openRenameFileDialog();
+ openRenameFileDialog();
}
function showMoveCopyFilesDialog() {
onClose();
- props.openMoveCopyFilesDialog();
+ openMoveCopyFilesDialog();
}
function showShareFilesDialog() {
onClose();
- props.openShareFilesDialog();
+ openShareFilesDialog();
}
function setFolderThumbnail() {
onClose();
- setFolderThumbnailPromise(props.selectedFilePath)
+ setFolderThumbnailPromise(selectedFilePath)
.then((directoryPath: string) => {
- showNotification('Thumbnail created for: ' + directoryPath);
+ dispatch(
+ AppActions.showNotification('Thumbnail created for: ' + directoryPath)
+ );
return true;
})
.catch(error => {
- showNotification('Thumbnail creation failed.');
+ dispatch(AppActions.showNotification('Thumbnail creation failed.'));
console.warn(
- 'Error setting Thumb for entry: ' + props.selectedFilePath,
+ 'Error setting Thumb for entry: ' + selectedFilePath,
error
);
return true;
@@ -187,24 +196,30 @@ function FileMenu(props: Props) {
onClose();
let path =
PlatformIO.haveObjectStoreSupport() || PlatformIO.haveWebDavSupport()
- ? PlatformIO.getURLforPath(props.selectedFilePath)
- : props.selectedFilePath;
+ ? PlatformIO.getURLforPath(selectedFilePath)
+ : selectedFilePath;
const directoryPath = extractContainingDirectoryPath(
- props.selectedFilePath,
+ selectedFilePath,
PlatformIO.getDirSeparator()
);
setFolderBackgroundPromise(path, directoryPath)
.then((directoryPath: string) => {
- props.setLastBackgroundImageChange(path, new Date().getTime());
- showNotification('Background created for: ' + directoryPath);
+ dispatch(
+ AppActions.setLastBackgroundImageChange(path, new Date().getTime())
+ );
+ dispatch(
+ AppActions.showNotification(
+ 'Background created for: ' + directoryPath
+ )
+ );
return true;
})
.catch(error => {
- showNotification('Background creation failed.');
+ dispatch(AppActions.showNotification('Background creation failed.'));
console.warn(
- 'Error setting Background for entry: ' + props.selectedFilePath,
+ 'Error setting Background for entry: ' + selectedFilePath,
error
);
return true;
@@ -213,14 +228,7 @@ function FileMenu(props: Props) {
function showAddRemoveTagsDialog() {
onClose();
- props.openAddRemoveTagsDialog();
- }
-
- function showInFileManager() {
- onClose();
- if (props.selectedFilePath) {
- props.showInFileManager(props.selectedFilePath);
- }
+ openAddRemoveTagsDialog();
}
function duplicateFile() {
@@ -250,31 +258,26 @@ function FileMenu(props: Props) {
fileName,
extractedTags,
AppConfig.tagDelimiter,
- props.prefixTagContainer
+ prefixTagContainer
);
PlatformIO.copyFilePromise(selectedFilePath, newFilePath)
.then(() => {
- if (props.onDuplicateFile) {
- props.onDuplicateFile(dirPath);
+ if (onDuplicateFile) {
+ onDuplicateFile(dirPath);
} else {
- props.loadDirectoryContent(dirPath, true, true);
+ loadDirectoryContent(dirPath, true, true);
}
return true;
})
.catch(error => {
- showNotification('Error creating duplicate: ', error);
+ dispatch(
+ AppActions.showNotification('Error creating duplicate: ', error)
+ );
});
}
}
- function openFileNatively() {
- onClose();
- if (props.selectedFilePath) {
- props.openFileNatively(props.selectedFilePath);
- }
- }
-
function openParentFolderInternally() {
onClose();
if (selectedFilePath) {
@@ -282,8 +285,8 @@ function FileMenu(props: Props) {
selectedFilePath,
PlatformIO.getDirSeparator()
);
- props.exitSearchMode();
- props.loadDirectoryContent(parentFolder, false, true);
+ dispatch(AppActions.exitSearchMode());
+ loadDirectoryContent(parentFolder, false, true);
}
}
@@ -292,13 +295,13 @@ function FileMenu(props: Props) {
if (selectedFilePath) {
getAllPropertiesPromise(selectedFilePath)
.then((fsEntry: TS.FileSystemEntry) => {
- props.openFsEntry(fsEntry);
+ dispatch(AppActions.openFsEntry(fsEntry));
return true;
})
.catch(error =>
console.warn(
'Error getting properties for entry: ' +
- props.selectedFilePath +
+ selectedFilePath +
' - ' +
error
)
@@ -373,7 +376,12 @@ function FileMenu(props: Props) {
<MenuItem
key="fileMenuOpenFileNatively"
data-tid="fileMenuOpenFileNatively"
- onClick={openFileNatively}
+ onClick={() => {
+ onClose();
+ if (selectedFilePath) {
+ openFileNatively(selectedFilePath);
+ }
+ }}
>
<ListItemIcon>
<OpenFileNatively />
@@ -385,7 +393,12 @@ function FileMenu(props: Props) {
<MenuItem
key="fileMenuOpenContainingFolder"
data-tid="fileMenuOpenContainingFolder"
- onClick={showInFileManager}
+ onClick={() => {
+ onClose();
+ if (selectedFilePath) {
+ showInFileManager(selectedFilePath);
+ }
+ }}
>
<ListItemIcon>
<OpenFolderInternally />
@@ -395,7 +408,7 @@ function FileMenu(props: Props) {
);
menuItems.push(<Divider key="fmDivider" />);
}
- if (!isReadOnlyMode) {
+ if (!readOnlyMode) {
menuItems.push(
<MenuItem
key="fileMenuAddRemoveTags"
@@ -408,14 +421,14 @@ function FileMenu(props: Props) {
<ListItemText primary={i18n.t('core:addRemoveTags')} />
</MenuItem>
);
- if (props.reorderTop) {
+ if (reorderTop) {
menuItems.push(
<MenuItem
key="reorderTop"
data-tid="reorderTopTID"
onClick={() => {
onClose();
- props.reorderTop();
+ reorderTop();
}}
>
<ListItemIcon>
@@ -425,14 +438,14 @@ function FileMenu(props: Props) {
</MenuItem>
);
}
- if (props.reorderBottom) {
+ if (reorderBottom) {
menuItems.push(
<MenuItem
key="reorderBottom"
data-tid="reorderBottomTID"
onClick={() => {
onClose();
- props.reorderBottom();
+ reorderBottom();
}}
>
<ListItemIcon>
@@ -470,7 +483,7 @@ function FileMenu(props: Props) {
);
}
- if (Pro && props.openShareFilesDialog) {
+ if (Pro && openShareFilesDialog) {
menuItems.push(
<MenuItem
key="fileMenuShareFile"
@@ -557,17 +570,13 @@ function FileMenu(props: Props) {
return (
<div style={{ overflowY: 'hidden' }}>
<Menu
- anchorEl={props.anchorEl}
- anchorReference={
- props.mouseY && props.mouseX ? 'anchorPosition' : undefined
- }
+ anchorEl={anchorEl}
+ anchorReference={mouseY && mouseX ? 'anchorPosition' : undefined}
anchorPosition={
- props.mouseY && props.mouseX
- ? { top: props.mouseY, left: props.mouseX }
- : undefined
+ mouseY && mouseX ? { top: mouseY, left: mouseX } : undefined
}
- open={props.open}
- onClose={props.onClose}
+ open={open}
+ onClose={onClose}
>
{menuItems}
</Menu>
@@ -575,20 +584,4 @@ function FileMenu(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- prefixTagContainer: getPrefixTagContainer(state)
- };
-}
-
-function mapDispatchToProps(dispatch) {
- return bindActionCreators(
- {
- setLastBackgroundImageChange: AppActions.setLastBackgroundImageChange,
- exitSearchMode: AppActions.exitSearchMode
- },
- dispatch
- );
-}
-
-export default connect(mapStateToProps, mapDispatchToProps)(FileMenu);
+export default FileMenu;
diff --git a/app/components/menus/LocationContextMenu.tsx b/app/components/menus/LocationContextMenu.tsx
index fabbfd50f..f4e4c2719 100644
--- a/app/components/menus/LocationContextMenu.tsx
+++ b/app/components/menus/LocationContextMenu.tsx
@@ -17,6 +17,7 @@
*/
import React from 'react';
+import { useSelector, useDispatch } from 'react-redux';
import { getUuid } from '@tagspaces/tagspaces-common/utils-io';
import { generateSharingLink } from '@tagspaces/tagspaces-common/paths';
import ListItemText from '@mui/material/ListItemText';
@@ -32,8 +33,6 @@ import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward';
import DeleteIcon from '@mui/icons-material/DeleteForever';
import OpenFolderNativelyIcon from '@mui/icons-material/Launch';
import { OpenNewWindowIcon, CloseIcon } from '-/components/CommonIcons';
-import { bindActionCreators } from 'redux';
-import { connect } from 'react-redux';
import { locationType } from '@tagspaces/tagspaces-common/misc';
import AppConfig from '-/AppConfig';
import {
@@ -42,47 +41,60 @@ import {
} from '-/reducers/locations';
import { actions as LocationIndexActions } from '-/reducers/location-index';
import i18n from '-/services/i18n';
-import { actions as AppActions } from '-/reducers/app';
+import { actions as AppActions, AppDispatch } from '-/reducers/app';
import { TS } from '-/tagspaces.namespace';
import PlatformIO from '-/services/platform-facade';
interface Props {
setEditLocationDialogOpened: (open: boolean) => void;
setDeleteLocationDialogOpened: (open: boolean) => void;
- createLocationIndex: (location: TS.Location) => void;
selectedLocation: TS.Location;
- moveLocationUp: (locationId: string) => void;
- moveLocationDown: (locationId: string) => void;
- showInFileManager: (path: string) => void;
- closeLocation: (locationId: string) => void;
closeLocationTree: () => void;
locationDirectoryContextMenuAnchorEl: HTMLElement;
setLocationDirectoryContextMenuAnchorEl: (el: HTMLElement) => void;
- addLocation: (
- location: TS.Location,
- openAfterCreate?: boolean,
- locationPosition?: number
- ) => void;
- locationPosition: number;
}
function LocationContextMenu(props: Props) {
const {
- addLocation,
selectedLocation,
setEditLocationDialogOpened,
- setLocationDirectoryContextMenuAnchorEl,
- createLocationIndex,
- locationPosition,
- moveLocationUp,
- moveLocationDown,
setDeleteLocationDialogOpened,
+ setLocationDirectoryContextMenuAnchorEl,
closeLocationTree,
- closeLocation,
- showInFileManager,
locationDirectoryContextMenuAnchorEl
} = props;
+ const dispatch: AppDispatch = useDispatch();
+ const locationPosition = useSelector(state =>
+ getLocationPosition(state, selectedLocation.uuid)
+ );
+
+ const createLocationIndex = location => {
+ dispatch(LocationIndexActions.createLocationIndex(location));
+ };
+
+ const moveLocationUp = locationId => {
+ dispatch(LocationActions.moveLocationUp(locationId));
+ };
+
+ const moveLocationDown = locationId => {
+ dispatch(LocationActions.moveLocationDown(locationId));
+ };
+
+ const showInFileManager = path => {
+ dispatch(AppActions.showInFileManager(path));
+ };
+
+ const closeLocation = locationId => {
+ dispatch(AppActions.closeLocation(locationId));
+ };
+
+ const addLocation = (location, openAfterCreate, locationPosition) => {
+ dispatch(
+ LocationActions.addLocation(location, openAfterCreate, locationPosition)
+ );
+ };
+
const indexLocation = () => {
setLocationDirectoryContextMenuAnchorEl(null);
createLocationIndex(selectedLocation);
@@ -277,27 +289,4 @@ function LocationContextMenu(props: Props) {
);
}
-function mapDispatchToProps(dispatch) {
- return bindActionCreators(
- {
- createLocationIndex: LocationIndexActions.createLocationIndex,
- moveLocationUp: LocationActions.moveLocationUp,
- moveLocationDown: LocationActions.moveLocationDown,
- showInFileManager: AppActions.showInFileManager,
- closeLocation: AppActions.closeLocation,
- addLocation: LocationActions.addLocation
- },
- dispatch
- );
-}
-
-function mapStateToProps(state, ownProps) {
- return {
- locationPosition: getLocationPosition(state, ownProps.selectedLocation.uuid)
- };
-}
-
-export default connect(
- mapStateToProps,
- mapDispatchToProps
-)(LocationContextMenu);
+export default LocationContextMenu;
diff --git a/app/components/menus/LocationManagerMenu.tsx b/app/components/menus/LocationManagerMenu.tsx
index 65b5c81d6..97e63913a 100644
--- a/app/components/menus/LocationManagerMenu.tsx
+++ b/app/components/menus/LocationManagerMenu.tsx
@@ -30,15 +30,16 @@ import Typography from '@mui/material/Typography';
import IconButton from '@mui/material/IconButton';
import MoreVertIcon from '@mui/icons-material/MoreVert';
import { bindActionCreators } from 'redux';
-import { connect } from 'react-redux';
+import { useDispatch } from 'react-redux';
import AppConfig from '-/AppConfig';
import i18n from '-/services/i18n';
import { Pro } from '../../pro';
-import { actions as AppActions } from '-/reducers/app';
+import { actions as AppActions, AppDispatch } from '-/reducers/app';
import Links from '-/content/links';
import { ProLabel } from '-/components/HelperComponents';
import { actions as LocationIndexActions } from '-/reducers/location-index';
import { OpenLinkIcon, HelpIcon } from '-/components/CommonIcons';
+import { openURLExternally } from '-/services/utils-io';
interface Props {
classes: any;
@@ -46,17 +47,21 @@ interface Props {
importLocations: () => void;
showCreateLocationDialog: () => void;
toggleOpenLinkDialog: () => void;
- closeAllLocations: () => void;
- openURLExternally: (url: string, skipConfirmation?: boolean) => void;
- createLocationsIndexes: () => void;
}
function LocationManagerMenu(props: Props) {
+ const {
+ classes,
+ exportLocations,
+ importLocations,
+ showCreateLocationDialog,
+ toggleOpenLinkDialog
+ } = props;
const [
locationManagerMenuAnchorEl,
setLocationManagerMenuAnchorEl
] = useState<null | HTMLElement>(null);
-
+ const dispatch: AppDispatch = useDispatch();
const menuItems = [];
if (!AppConfig.locationsReadOnly) {
menuItems.push(
@@ -65,7 +70,7 @@ function LocationManagerMenu(props: Props) {
data-tid="locationManagerMenuCreateLocation"
onClick={() => {
setLocationManagerMenuAnchorEl(null);
- props.showCreateLocationDialog();
+ showCreateLocationDialog();
}}
>
<ListItemIcon>
@@ -82,7 +87,7 @@ function LocationManagerMenu(props: Props) {
data-tid="locationManagerMenuOpenLink"
onClick={() => {
setLocationManagerMenuAnchorEl(null);
- props.toggleOpenLinkDialog();
+ toggleOpenLinkDialog();
}}
>
<ListItemIcon>
@@ -101,7 +106,7 @@ function LocationManagerMenu(props: Props) {
data-tid="locationManagerMenuExportLocationsTID"
onClick={() => {
setLocationManagerMenuAnchorEl(null);
- props.exportLocations();
+ exportLocations();
}}
>
<ListItemIcon>
@@ -124,7 +129,7 @@ function LocationManagerMenu(props: Props) {
data-tid="locationManagerMenuImportLocationsTID"
onClick={() => {
setLocationManagerMenuAnchorEl(null);
- props.importLocations();
+ importLocations();
}}
>
<ListItemIcon>
@@ -148,7 +153,7 @@ function LocationManagerMenu(props: Props) {
data-tid="locationManagerMenuCloseAll"
onClick={() => {
setLocationManagerMenuAnchorEl(null);
- props.closeAllLocations();
+ dispatch(AppActions.closeAllLocations());
}}
>
<ListItemIcon>
@@ -164,7 +169,7 @@ function LocationManagerMenu(props: Props) {
data-tid="updateAllLocationIndexes"
onClick={() => {
setLocationManagerMenuAnchorEl(null);
- props.createLocationsIndexes();
+ dispatch(LocationIndexActions.createLocationsIndexes());
}}
>
<ListItemIcon>
@@ -180,7 +185,7 @@ function LocationManagerMenu(props: Props) {
data-tid="locationManagerMenuHelp"
onClick={() => {
setLocationManagerMenuAnchorEl(null);
- props.openURLExternally(Links.documentationLinks.locations, true);
+ openURLExternally(Links.documentationLinks.locations, true);
}}
>
<ListItemIcon>
@@ -192,9 +197,9 @@ function LocationManagerMenu(props: Props) {
return (
<>
- <div className={props.classes.toolbar}>
+ <div className={classes.toolbar}>
<Typography
- className={classNames(props.classes.panelTitle, props.classes.header)}
+ className={classNames(classes.panelTitle, classes.header)}
variant="subtitle1"
>
{i18n.t('core:locationManager')}
@@ -219,14 +224,4 @@ function LocationManagerMenu(props: Props) {
</>
);
}
-
-function mapDispatchToProps(dispatch) {
- return bindActionCreators(
- {
- closeAllLocations: AppActions.closeAllLocations,
- createLocationsIndexes: LocationIndexActions.createLocationsIndexes
- },
- dispatch
- );
-}
-export default connect(undefined, mapDispatchToProps)(LocationManagerMenu);
+export default LocationManagerMenu;
diff --git a/app/components/menus/LocationMenu.tsx b/app/components/menus/LocationMenu.tsx
index c2f1fcd46..f55710f30 100644
--- a/app/components/menus/LocationMenu.tsx
+++ b/app/components/menus/LocationMenu.tsx
@@ -17,8 +17,7 @@
*/
import React, { useState } from 'react';
-import { connect } from 'react-redux';
-import { bindActionCreators } from 'redux';
+import { useSelector, useDispatch } from 'react-redux';
import Menu from '@mui/material/Menu';
import MenuItem from '@mui/material/MenuItem';
import { LocalLocationIcon, CloudLocationIcon } from '-/components/CommonIcons';
@@ -32,32 +31,31 @@ import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
import { locationType } from '@tagspaces/tagspaces-common/misc';
import i18n from '-/services/i18n';
import { getLocations } from '-/reducers/locations';
-import { actions as AppActions, getCurrentLocationId } from '-/reducers/app';
+import {
+ actions as AppActions,
+ AppDispatch,
+ getCurrentLocationId
+} from '-/reducers/app';
import { TS } from '-/tagspaces.namespace';
interface Props {
- currentLocationId: string | null;
theme: any;
- locations: Array<TS.Location>;
menuAnchorEl?: Element;
- openLocation: (location: TS.Location) => void;
}
function LocationMenu(props: Props) {
+ const dispatch: AppDispatch = useDispatch();
+ const locations: Array<TS.Location> = useSelector(getLocations);
+ const currentLocationId: string | null = useSelector(getCurrentLocationId);
const [
locationChooserMenuAnchorEl,
setLocationChooserMenuAnchorEl
] = useState<null | HTMLElement>(null);
- const openLocation = location => {
- props.openLocation(location);
- setLocationChooserMenuAnchorEl(null);
- };
-
let currentLocation;
- if (props.currentLocationId && props.locations) {
- currentLocation = props.locations.find(
- (location: TS.Location) => location.uuid === props.currentLocationId
+ if (currentLocationId && locations) {
+ currentLocation = locations.find(
+ (location: TS.Location) => location.uuid === currentLocationId
);
}
@@ -117,11 +115,14 @@ function LocationMenu(props: Props) {
>
{i18n.t('core:chooseLocation')}
</ListSubHeader>
- {props.locations.map((location: TS.Location) => (
+ {locations.map((location: TS.Location) => (
<MenuItem
data-tid="folderContainerMenuOpenLocation"
key={location.uuid}
- onClick={() => openLocation(location)}
+ onClick={() => {
+ dispatch(AppActions.openLocation(location));
+ setLocationChooserMenuAnchorEl(null);
+ }}
style={
currentLocation && currentLocation.uuid === location.uuid
? { backgroundColor: theme.palette.primary.light }
@@ -144,23 +145,4 @@ function LocationMenu(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- locations: getLocations(state),
- currentLocationId: getCurrentLocationId(state)
- };
-}
-
-function mapActionCreatorsToProps(dispatch) {
- return bindActionCreators(
- {
- openLocation: AppActions.openLocation
- },
- dispatch
- );
-}
-
-export default connect(
- mapStateToProps,
- mapActionCreatorsToProps
-)(withTheme(LocationMenu));
+export default withTheme(LocationMenu);
diff --git a/app/components/menus/SavedSearchesMenu.tsx b/app/components/menus/SavedSearchesMenu.tsx
index e7b04e9fc..62109949c 100644
--- a/app/components/menus/SavedSearchesMenu.tsx
+++ b/app/components/menus/SavedSearchesMenu.tsx
@@ -17,46 +17,50 @@
*/
import React from 'react';
+import { useSelector, useDispatch } from 'react-redux';
import Menu from '@mui/material/Menu';
import MenuItem from '@mui/material/MenuItem';
-import { TS } from '-/tagspaces.namespace';
import { getSearches } from '-/reducers/searches';
-import { connect } from 'react-redux';
-import { bindActionCreators } from 'redux';
import { actions as LocationIndexActions } from '-/reducers/location-index';
import i18n from '-/services/i18n';
import { getShowUnixHiddenEntries } from '-/reducers/settings';
+import { AppDispatch } from '-/reducers/app';
interface Props {
- classes?: any;
open: boolean;
anchorEl: Element;
onClose: () => void;
- searches: Array<TS.SearchQuery>;
- setSearchQuery: (searchQuery: TS.SearchQuery) => void;
- showUnixHiddenEntries: boolean;
}
function SavedSearchesMenu(props: Props) {
+ const { open, onClose, anchorEl } = props;
+ const dispatch: AppDispatch = useDispatch();
+ const searches = useSelector(state => getSearches(state));
+ const showUnixHiddenEntries = useSelector(state =>
+ getShowUnixHiddenEntries(state)
+ );
+
const handleSavedSearchClick = (uuid: string) => {
- const savedSearch = props.searches.find(search => search.uuid === uuid);
+ const savedSearch = searches.find(search => search.uuid === uuid);
if (!savedSearch) {
return true;
}
- props.setSearchQuery({
- ...savedSearch,
- showUnixHiddenEntries: props.showUnixHiddenEntries
- });
+ dispatch(
+ LocationIndexActions.setSearchQuery({
+ ...savedSearch,
+ showUnixHiddenEntries: showUnixHiddenEntries
+ })
+ );
};
- const menuItems = props.searches.length ? (
- props.searches.map(search => (
+ const menuItems = searches.length ? (
+ searches.map(search => (
<MenuItem
key={search.uuid}
onClick={() => {
handleSavedSearchClick(search.uuid);
- props.onClose();
+ onClose();
}}
>
{search.title}
@@ -69,9 +73,9 @@ function SavedSearchesMenu(props: Props) {
return (
<div style={{ overflowY: 'hidden' }}>
<Menu
- anchorEl={props.anchorEl}
- open={props.open}
- onClose={props.onClose}
+ anchorEl={anchorEl}
+ open={open}
+ onClose={onClose}
id="search-menu"
MenuListProps={{
'aria-labelledby': 'basic-button'
@@ -111,19 +115,4 @@ function SavedSearchesMenu(props: Props) {
</div>
);
}
-
-function mapStateToProps(state) {
- return {
- searches: getSearches(state),
- showUnixHiddenEntries: getShowUnixHiddenEntries(state)
- };
-}
-function mapDispatchToProps(dispatch) {
- return bindActionCreators(
- {
- setSearchQuery: LocationIndexActions.setSearchQuery
- },
- dispatch
- );
-}
-export default connect(mapStateToProps, mapDispatchToProps)(SavedSearchesMenu);
+export default SavedSearchesMenu;
diff --git a/app/components/menus/SearchMenu.tsx b/app/components/menus/SearchMenu.tsx
index b5bede233..309723f2e 100644
--- a/app/components/menus/SearchMenu.tsx
+++ b/app/components/menus/SearchMenu.tsx
@@ -27,13 +27,13 @@ import i18n from '-/services/i18n';
import { Pro } from '../../pro';
import Links from '-/content/links';
import { ProLabel } from '-/components/HelperComponents';
+import { openURLExternally } from '-/services/utils-io';
interface Props {
classes?: any;
open: boolean;
anchorEl: Element;
onClose: () => void;
- openURLExternally: (url: string, skipConfirmation?: boolean) => void;
importSearches: () => void;
exportSearches: () => void;
}
@@ -92,7 +92,7 @@ function SearchMenu(props: Props) {
data-tid="searchMenuHelp"
onClick={() => {
props.onClose();
- props.openURLExternally(Links.documentationLinks.search, true);
+ openURLExternally(Links.documentationLinks.search, true);
}}
>
<ListItemIcon>
diff --git a/app/components/menus/TagGroupMenu.tsx b/app/components/menus/TagGroupMenu.tsx
index ed12fe090..7603103b9 100644
--- a/app/components/menus/TagGroupMenu.tsx
+++ b/app/components/menus/TagGroupMenu.tsx
@@ -17,6 +17,7 @@
*/
import React from 'react';
+import { useSelector, useDispatch } from 'react-redux';
import Edit from '@mui/icons-material/Edit';
import ArrowDownward from '@mui/icons-material/ArrowDownward';
import ArrowUpward from '@mui/icons-material/ArrowUpward';
@@ -30,15 +31,13 @@ import ListItemSecondaryAction from '@mui/material/ListItemSecondaryAction';
import CollectTagsIcon from '@mui/icons-material/Voicemail';
import Menu from '@mui/material/Menu';
import MenuItem from '@mui/material/MenuItem';
-import { bindActionCreators } from 'redux';
-import { connect } from 'react-redux';
import i18n from '-/services/i18n';
import { getMaxSearchResults } from '-/reducers/settings';
import { actions as LocationIndexActions } from '-/reducers/location-index';
-import { actions as AppActions } from '-/reducers/app';
+import { actions as AppActions, AppDispatch } from '-/reducers/app';
import { TS } from '-/tagspaces.namespace';
import InfoIcon from '-/components/InfoIcon';
-import { ProLabel } from '-/components/HelperComponents';
+import TaggingActions from '-/reducers/tagging-actions';
interface Props {
classes?: any;
@@ -52,92 +51,99 @@ interface Props {
moveTagGroupUp: (tagGroupId: string) => void;
moveTagGroupDown: (tagGroupId: string) => void;
sortTagGroup: (tagGroupId: string) => void;
- collectTagsFromLocation: (tagGroup: TS.TagGroup) => void;
handleCloseTagGroupMenu: () => void;
- setSearchQuery: (searchQuery: TS.SearchQuery) => void;
- tagLibraryChanged: () => void;
- maxSearchResults: number;
}
function TagGroupMenu(props: Props) {
+ const {
+ open,
+ onClose,
+ selectedTagGroupEntry,
+ handleCloseTagGroupMenu,
+ moveTagGroupUp,
+ moveTagGroupDown,
+ sortTagGroup,
+ anchorEl,
+ showCreateTagsDialog,
+ showEditTagGroupDialog,
+ showDeleteTagGroupDialog
+ } = props;
+ const dispatch: AppDispatch = useDispatch();
+ const maxSearchResults = useSelector(getMaxSearchResults);
+
function handleCollectTags() {
- props.onClose();
+ onClose();
- if (props.selectedTagGroupEntry) {
- props.collectTagsFromLocation(props.selectedTagGroupEntry);
+ if (selectedTagGroupEntry) {
+ dispatch(TaggingActions.collectTagsFromLocation(selectedTagGroupEntry));
}
- props.handleCloseTagGroupMenu();
- props.tagLibraryChanged();
+ handleCloseTagGroupMenu();
+ dispatch(AppActions.tagLibraryChanged());
}
- function moveTagGroupUp() {
- if (props.selectedTagGroupEntry) {
- props.moveTagGroupUp(props.selectedTagGroupEntry.uuid);
+ function moveTagGroupUpInt() {
+ if (selectedTagGroupEntry) {
+ moveTagGroupUp(selectedTagGroupEntry.uuid);
}
- props.handleCloseTagGroupMenu();
+ handleCloseTagGroupMenu();
}
- function moveTagGroupDown() {
- if (props.selectedTagGroupEntry) {
- props.moveTagGroupDown(props.selectedTagGroupEntry.uuid);
+ function moveTagGroupDownInt() {
+ if (selectedTagGroupEntry) {
+ moveTagGroupDown(selectedTagGroupEntry.uuid);
}
- props.handleCloseTagGroupMenu();
+ handleCloseTagGroupMenu();
}
- function sortTagGroup() {
- if (props.selectedTagGroupEntry) {
- props.sortTagGroup(props.selectedTagGroupEntry.uuid);
+ function sortTagGroupInt() {
+ if (selectedTagGroupEntry) {
+ sortTagGroup(selectedTagGroupEntry.uuid);
}
- props.handleCloseTagGroupMenu();
+ handleCloseTagGroupMenu();
}
function showFilesWithTags() {
- if (props.selectedTagGroupEntry) {
- // props.openSearchPanel();
- props.setSearchQuery({
- tagsOR: props.selectedTagGroupEntry.children,
- maxSearchResults: props.maxSearchResults,
- executeSearch: true
- });
+ if (selectedTagGroupEntry) {
+ // openSearchPanel();
+ dispatch(
+ LocationIndexActions.setSearchQuery({
+ tagsOR: selectedTagGroupEntry.children,
+ maxSearchResults: maxSearchResults,
+ executeSearch: true
+ })
+ );
}
- props.handleCloseTagGroupMenu();
+ handleCloseTagGroupMenu();
}
return (
<div style={{ overflowY: 'hidden' }}>
- <Menu
- anchorEl={props.anchorEl}
- open={props.open}
- onClose={props.handleCloseTagGroupMenu}
- >
- <MenuItem data-tid="createTags" onClick={props.showCreateTagsDialog}>
+ <Menu anchorEl={anchorEl} open={open} onClose={handleCloseTagGroupMenu}>
+ <MenuItem data-tid="createTags" onClick={showCreateTagsDialog}>
<ListItemIcon>
<TagIcon />
</ListItemIcon>
<ListItemText primary={i18n.t('core:addTags')} />
</MenuItem>
- <MenuItem
- data-tid="editTagGroup"
- onClick={props.showEditTagGroupDialog}
- >
+ <MenuItem data-tid="editTagGroup" onClick={showEditTagGroupDialog}>
<ListItemIcon>
<Edit />
</ListItemIcon>
<ListItemText primary={i18n.t('core:editTagGroup')} />
</MenuItem>
- <MenuItem data-tid="moveTagGroupUp" onClick={moveTagGroupUp}>
+ <MenuItem data-tid="moveTagGroupUp" onClick={moveTagGroupUpInt}>
<ListItemIcon>
<ArrowUpward />
</ListItemIcon>
<ListItemText primary={i18n.t('core:moveTagGroupUp')} />
</MenuItem>
- <MenuItem data-tid="moveTagGroupDown" onClick={moveTagGroupDown}>
+ <MenuItem data-tid="moveTagGroupDown" onClick={moveTagGroupDownInt}>
<ListItemIcon>
<ArrowDownward />
</ListItemIcon>
<ListItemText primary={i18n.t('core:moveTagGroupDown')} />
</MenuItem>
- <MenuItem data-tid="sortTagGroup" onClick={sortTagGroup}>
+ <MenuItem data-tid="sortTagGroup" onClick={sortTagGroupInt}>
<ListItemIcon>
<SortTagGroupIcon />
</ListItemIcon>
@@ -152,10 +158,7 @@ function TagGroupMenu(props: Props) {
<InfoIcon tooltip={i18n.t('core:showFilesWithTagsTooltip')} />
</ListItemSecondaryAction>
</MenuItem>
- <MenuItem
- data-tid="deleteTagGroup"
- onClick={props.showDeleteTagGroupDialog}
- >
+ <MenuItem data-tid="deleteTagGroup" onClick={showDeleteTagGroupDialog}>
<ListItemIcon>
<DeleteTagGroupIcon />
</ListItemIcon>
@@ -178,20 +181,4 @@ function TagGroupMenu(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- maxSearchResults: getMaxSearchResults(state)
- };
-}
-
-function mapDispatchToProps(dispatch) {
- return bindActionCreators(
- {
- setSearchQuery: LocationIndexActions.setSearchQuery,
- tagLibraryChanged: AppActions.tagLibraryChanged
- },
- dispatch
- );
-}
-
-export default connect(mapStateToProps, mapDispatchToProps)(TagGroupMenu);
+export default TagGroupMenu;
diff --git a/app/components/menus/TagLibraryMenu.tsx b/app/components/menus/TagLibraryMenu.tsx
index 23c9cdcd8..bbc8d6446 100644
--- a/app/components/menus/TagLibraryMenu.tsx
+++ b/app/components/menus/TagLibraryMenu.tsx
@@ -17,6 +17,7 @@
*/
import React, { useRef, useState } from 'react';
+import { useDispatch } from 'react-redux';
import ListItemText from '@mui/material/ListItemText';
import ListItemIcon from '@mui/material/ListItemIcon';
import Menu from '@mui/material/Menu';
@@ -32,27 +33,23 @@ import { TS } from '-/tagspaces.namespace';
import Links from '-/content/links';
import { ProLabel, ProTooltip } from '-/components/HelperComponents';
import { Pro } from '-/pro';
+import { openURLExternally } from '-/services/utils-io';
+import { actions as AppActions, AppDispatch } from '-/reducers/app';
interface Props {
classes?: any;
anchorEl: Element;
tagGroups: Array<Object>;
- openURLExternally: (path: string, skipConfirmation?: boolean) => void;
open: boolean;
onClose: () => void;
importTagGroups: (entries: Array<TS.TagGroup>, replace?: boolean) => void;
- exportTagGroups: (entries: Array<TS.TagGroup>) => void;
showCreateTagGroupDialog: () => void;
- showNotification: (
- text: string,
- notificationType?: string, // NotificationTypes
- autohide?: boolean
- ) => void;
saveTagInLocation: boolean;
refreshTagsFromLocation: () => void;
}
function TagLibraryMenu(props: Props) {
+ const dispatch: AppDispatch = useDispatch();
const fileInput = useRef<HTMLInputElement>(null);
const tagGroupsImported = useRef([]);
// const [tagGroups, setTagGroups] = useState(null);
@@ -91,17 +88,21 @@ function TagLibraryMenu(props: Props) {
tagGroupsImported.current = jsonObj.tagGroups;
setIsImportExportTagGroupDialogOpened(true);
} else {
- props.showNotification(
- i18n.t('core:invalidImportFile'),
- 'warning',
- true
+ dispatch(
+ AppActions.showNotification(
+ i18n.t('core:invalidImportFile'),
+ 'warning',
+ true
+ )
);
}
} catch (e) {
- props.showNotification(
- i18n.t('core:invalidImportFile'),
- 'warning',
- true
+ dispatch(
+ AppActions.showNotification(
+ i18n.t('core:invalidImportFile'),
+ 'warning',
+ true
+ )
);
}
};
@@ -119,7 +120,6 @@ function TagLibraryMenu(props: Props) {
dialogModeImport ? tagGroupsImported.current : props.tagGroups
}
dialogModeImport={dialogModeImport}
- exportTagGroups={props.exportTagGroups}
importTagGroups={props.importTagGroups}
/>
)}
@@ -179,7 +179,7 @@ function TagLibraryMenu(props: Props) {
data-tid="taglibraryHelp"
onClick={() => {
props.onClose();
- props.openURLExternally(Links.documentationLinks.taglibrary, true);
+ openURLExternally(Links.documentationLinks.taglibrary, true);
}}
>
<ListItemIcon>
diff --git a/app/components/menus/TagMenu.tsx b/app/components/menus/TagMenu.tsx
index 47720792e..cd5214b13 100644
--- a/app/components/menus/TagMenu.tsx
+++ b/app/components/menus/TagMenu.tsx
@@ -17,8 +17,7 @@
*/
import React from 'react';
-import { bindActionCreators } from 'redux';
-import { connect } from 'react-redux';
+import { useSelector, useDispatch } from 'react-redux';
import ShowEntriesWithTagIcon from '@mui/icons-material/SearchOutlined';
import ApplyTagIcon from '@mui/icons-material/LocalOfferOutlined';
import Edit from '@mui/icons-material/Edit';
@@ -30,7 +29,11 @@ import MenuItem from '@mui/material/MenuItem';
import { actions as LocationIndexActions } from '-/reducers/location-index';
import i18n from '-/services/i18n';
import { getMaxSearchResults } from '-/reducers/settings';
-import { getSelectedEntries } from '-/reducers/app';
+import {
+ AppDispatch,
+ getSelectedEntries,
+ isReadOnlyMode
+} from '-/reducers/app';
import { TS } from '-/tagspaces.namespace';
import TaggingActions from '-/reducers/tagging-actions';
@@ -42,41 +45,33 @@ interface Props {
open?: boolean;
onClose: () => void;
selectedTag?: TS.Tag;
- setSearchQuery: (searchQuery: TS.SearchQuery) => void;
showEditTagDialog: () => void;
showDeleteTagDialog: () => void;
- maxSearchResults: number;
- selectedEntries: Array<any>;
- isReadOnlyMode: boolean;
- addTags: (
- paths: Array<string>,
- tags: Array<TS.Tag>,
- updateIndex?: boolean
- ) => void;
}
function TagMenu(props: Props) {
const {
- isReadOnlyMode,
selectedTag,
- setSearchQuery,
onClose,
showEditTagDialog,
showDeleteTagDialog,
- maxSearchResults,
- selectedEntries,
- addTags,
anchorEl,
open
} = props;
+ const dispatch: AppDispatch = useDispatch();
+ const readOnlyMode = useSelector(isReadOnlyMode);
+ const maxSearchResults: number = useSelector(getMaxSearchResults);
+ const selectedEntries = useSelector(getSelectedEntries);
function showFilesWithThisTag() {
if (selectedTag) {
- setSearchQuery({
- tagsAND: [selectedTag],
- maxSearchResults,
- executeSearch: true
- });
+ dispatch(
+ LocationIndexActions.setSearchQuery({
+ tagsAND: [selectedTag],
+ maxSearchResults: maxSearchResults,
+ executeSearch: true
+ })
+ );
}
onClose();
}
@@ -93,7 +88,7 @@ function TagMenu(props: Props) {
function applyTag() {
const selectedEntryPaths = selectedEntries.map(entry => entry.path);
- addTags(selectedEntryPaths, [selectedTag]);
+ dispatch(TaggingActions.addTags(selectedEntryPaths, [selectedTag]));
onClose();
}
@@ -115,7 +110,7 @@ function TagMenu(props: Props) {
</MenuItem>
)}
- {selectedEntries && selectedEntries.length > 0 && !isReadOnlyMode && (
+ {selectedEntries && selectedEntries.length > 0 && !readOnlyMode && (
<MenuItem data-tid="applyTagTID" onClick={applyTag}>
<ListItemIcon>
<ApplyTagIcon />
@@ -144,21 +139,4 @@ function TagMenu(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- maxSearchResults: getMaxSearchResults(state),
- selectedEntries: getSelectedEntries(state)
- };
-}
-
-function mapDispatchToProps(dispatch) {
- return bindActionCreators(
- {
- setSearchQuery: LocationIndexActions.setSearchQuery,
- addTags: TaggingActions.addTags
- },
- dispatch
- );
-}
-
-export default connect(mapStateToProps, mapDispatchToProps)(TagMenu);
+export default TagMenu;
diff --git a/app/containers/MainPage.tsx b/app/containers/MainPage.tsx
index 03cab9023..306f51ed5 100644
--- a/app/containers/MainPage.tsx
+++ b/app/containers/MainPage.tsx
@@ -179,7 +179,6 @@ interface Props {
// setLastSelectedEntry: (path: string) => void; // needed by electron-menus
setSelectedEntries: (selectedEntries: Array<Object>) => void; // needed by electron-menus
openFsEntry: (fsEntry: TS.FileSystemEntry) => void; // needed by electron-menus
- openURLExternally: (url: string, skipConfirm: boolean) => void;
openNextFile: (path?: string) => void; // needed by electron-menus
openPrevFile: (path?: string) => void; // needed by electron-menus
openLocationManagerPanel: () => void;
@@ -594,7 +593,6 @@ function MainPage(props: Props) {
toggleOpenLinkDialog,
toggleProTeaser,
setFirstRun,
- openURLExternally,
loadDirectoryContent,
directoryPath,
mainSplitSize,
@@ -705,7 +703,6 @@ function MainPage(props: Props) {
{props.isAboutDialogOpened && (
<AboutDialogAsync
open={props.isAboutDialogOpened}
- openURLExternally={openURLExternally}
toggleLicenseDialog={toggleLicenseDialog}
toggleThirdPartyLibsDialog={toggleThirdPartyLibsDialog}
onClose={toggleAboutDialog}
@@ -758,7 +755,6 @@ function MainPage(props: Props) {
<ProTeaserDialogAsync
open={props.isProTeaserVisible}
onClose={toggleProTeaser}
- openURLExternally={openURLExternally}
/>
)}
{props.isUploadProgressDialogOpened !== undefined && (
@@ -802,7 +798,6 @@ function MainPage(props: Props) {
)}
<SettingsDialog
open={props.isSettingsDialogOpened}
- openURLExternally={openURLExternally}
onClose={toggleSettingsDialog}
/>
{KanBanImportDialog && props.selectedEntries[0] && (
@@ -992,7 +987,6 @@ function mapDispatchToProps(dispatch) {
setSelectedEntries: AppActions.setSelectedEntries,
// setGeneratingThumbnails: AppActions.setGeneratingThumbnails,
openFsEntry: AppActions.openFsEntry,
- openURLExternally: AppActions.openURLExternally,
setEntryFullWidth: AppActions.setEntryFullWidth,
openNextFile: AppActions.openNextFile,
openPrevFile: AppActions.openPrevFile,
diff --git a/app/containers/PageNotification.tsx b/app/containers/PageNotification.tsx
index 0a5a1eb25..e3af527f4 100644
--- a/app/containers/PageNotification.tsx
+++ b/app/containers/PageNotification.tsx
@@ -40,6 +40,7 @@ import {
import i18n from '../services/i18n';
import { Pro } from '../pro';
import Links from '-/content/links';
+import { openURLExternally } from '-/services/utils-io';
interface Props {
notificationStatus: any;
@@ -56,7 +57,6 @@ interface Props {
lastPublishedVersion: string;
setUpdateAvailable: (isUpdateAvailable: boolean) => void;
setGeneratingThumbnails: (isGenerating: boolean) => void;
- openURLExternally: (url: string, skipConfirm: boolean) => void;
}
const TSNotification = withStyles((theme: Theme) =>
@@ -75,7 +75,7 @@ function PageNotification(props: Props) {
};
const openChangelogPage = () => {
- props.openURLExternally(Links.links.changelogURL, true);
+ openURLExternally(Links.links.changelogURL, true);
};
const getLatestVersion = () => {
@@ -86,7 +86,7 @@ function PageNotification(props: Props) {
false
);
} else {
- props.openURLExternally(Links.links.downloadURL, true);
+ openURLExternally(Links.links.downloadURL, true);
}
props.setUpdateAvailable(false);
};
@@ -202,8 +202,7 @@ function mapDispatchToProps(dispatch) {
hideNotifications: AppActions.hideNotifications,
cancelDirectoryIndexing: LocationIndexActions.cancelDirectoryIndexing,
setUpdateAvailable: AppActions.setUpdateAvailable,
- setGeneratingThumbnails: AppActions.setGeneratingThumbnails,
- openURLExternally: AppActions.openURLExternally
+ setGeneratingThumbnails: AppActions.setGeneratingThumbnails
},
dispatch
);
diff --git a/app/containers/RendererListener.ts b/app/containers/RendererListener.ts
index eca0db76e..83a64ce35 100644
--- a/app/containers/RendererListener.ts
+++ b/app/containers/RendererListener.ts
@@ -99,10 +99,10 @@ export default function listen(props) {
props.toggleOnboardingDialog();
break;
}
- case 'open-url-externally': {
+ /*case 'open-url-externally': {
props.openURLExternally();
break;
- }
+ }*/
case 'toggle-license-dialog': {
props.toggleLicenseDialog();
break;
@@ -120,10 +120,10 @@ export default function listen(props) {
}
});
- ipcRenderer.on('open-url-externally', (event, arg) => {
+ /*ipcRenderer.on('open-url-externally', (event, arg) => {
const { url, skipConfirm } = arg;
props.openURLExternally(url, skipConfirm);
- });
+ });*/
ipcRenderer.on('play-pause', (event, arg) => {
// Create the event.
diff --git a/app/perspectives/grid-perspective/components/CellContent.tsx b/app/perspectives/grid-perspective/components/CellContent.tsx
index 6d50fba16..9b8e6f331 100644
--- a/app/perspectives/grid-perspective/components/CellContent.tsx
+++ b/app/perspectives/grid-perspective/components/CellContent.tsx
@@ -17,6 +17,7 @@
*/
import React, { useMemo } from 'react';
+import { useSelector, useDispatch } from 'react-redux';
import classNames from 'classnames';
import Grid from '@mui/material/Grid';
import Typography from '@mui/material/Typography';
@@ -25,8 +26,6 @@ import Tooltip from '-/components/Tooltip';
import FolderOpenIcon from '@mui/icons-material/FolderOpen';
import IconButton from '@mui/material/IconButton';
import { SelectedIcon, UnSelectedIcon } from '-/components/CommonIcons';
-import { bindActionCreators } from 'redux';
-import { connect } from 'react-redux';
import {
formatFileSize,
formatDateTime
@@ -51,43 +50,39 @@ import { TS } from '-/tagspaces.namespace';
import TaggingActions from '-/reducers/tagging-actions';
import {
actions as AppActions,
- getLastThumbnailImageChange
+ AppDispatch,
+ getLastThumbnailImageChange,
+ isReadOnlyMode
} from '-/reducers/app';
import { FolderIcon } from '-/components/CommonIcons';
import { dataTidFormat } from '-/services/test';
-import { isDesktopMode } from '-/reducers/settings';
-// import { getTagColor } from '-/reducers/settings';
+import {
+ getSupportedFileTypes,
+ isDesktopMode,
+ isReorderTags
+} from '-/reducers/settings';
const maxDescriptionPreviewLength = 100;
interface Props {
selected: boolean;
isLast?: boolean;
- isDesktopMode: boolean;
fsEntry: TS.FileSystemEntry;
entrySize: string;
classes: any;
style?: any;
theme: any;
- supportedFileTypes: Array<Object>;
thumbnailMode: any;
- addTags: () => void;
- addTag: (tag: TS.Tag, parentTagGroupUuid: TS.Uuid) => void;
openFsEntry: (fsEntry: TS.FileSystemEntry) => void;
selectedEntries: Array<TS.FileSystemEntry>;
selectEntry: (fsEntry: TS.FileSystemEntry) => void;
deselectEntry: (fsEntry: TS.FileSystemEntry) => void;
- isReadOnlyMode: boolean;
showTags: boolean;
handleTagMenu: (event: Object, tag: TS.Tag, entryPath: string) => void;
layoutType: string;
handleGridContextMenu: (event: Object, fsEntry: TS.FileSystemEntry) => void;
handleGridCellDblClick: (event: Object, fsEntry: TS.FileSystemEntry) => void;
handleGridCellClick: (event: Object, fsEntry: TS.FileSystemEntry) => void;
- editTagForEntry?: (path: string, tag: TS.Tag) => void;
- reorderTags: boolean;
- lastThumbnailImageChange: any;
- exitSearchMode: () => void;
showEntriesDescription?: boolean;
}
@@ -98,28 +93,43 @@ function CellContent(props: Props) {
entrySize,
classes,
theme,
- supportedFileTypes,
thumbnailMode,
- addTags,
- addTag,
- editTagForEntry,
selectedEntries,
- isReadOnlyMode,
handleTagMenu,
layoutType,
handleGridContextMenu,
handleGridCellDblClick,
handleGridCellClick,
- lastThumbnailImageChange,
showEntriesDescription,
showTags,
// openFsEntry,
selectEntry,
deselectEntry,
- reorderTags,
- isDesktopMode,
isLast
} = props;
+ const readOnlyMode = useSelector(isReadOnlyMode);
+ const supportedFileTypes = useSelector(getSupportedFileTypes);
+ const reorderTags: boolean = useSelector(isReorderTags);
+ const lastThumbnailImageChange = useSelector(getLastThumbnailImageChange);
+ const desktopMode = useSelector(isDesktopMode);
+
+ const dispatch: AppDispatch = useDispatch();
+
+ // You can use the dispatch function to dispatch actions
+ const handleEditTag = (path: string, tag: TS.Tag, newTagTitle?: string) => {
+ dispatch(TaggingActions.editTagForEntry(path, tag, newTagTitle));
+ };
+ const handleAddTags = (
+ paths: Array<string>,
+ tags: Array<TS.Tag>,
+ updateIndex?
+ ) => {
+ dispatch(TaggingActions.addTags(paths, tags, updateIndex));
+ };
+
+ const handleAddTag = (tag: TS.Tag, parentTagGroupUuid: TS.Uuid) => {
+ dispatch(AppActions.addTag(tag, parentTagGroupUuid));
+ };
// remove isNewFile on Cell click it will open file in editMode
const fSystemEntry: TS.FileSystemEntry = (({ isNewFile, ...o }) => o)(
@@ -251,7 +261,7 @@ function CellContent(props: Props) {
<IconButton
style={{
opacity: selected ? 1 : 0.5,
- padding: isDesktopMode ? 5 : 8
+ padding: desktopMode ? 5 : 8
}}
onMouseLeave={e => {
//@ts-ignore
@@ -509,12 +519,12 @@ function CellContent(props: Props) {
const renderTags = useMemo(() => {
let sideCarLength = 0;
return entryTags.map((tag: TS.Tag, index) => {
- const tagContainer = isReadOnlyMode ? (
+ const tagContainer = readOnlyMode ? (
<TagContainer
tag={tag}
key={entryPath + tag.title}
entryPath={entryPath}
- addTags={addTags}
+ addTags={handleAddTags}
handleTagMenu={handleTagMenu}
selectedEntries={selectedEntries}
/>
@@ -524,11 +534,11 @@ function CellContent(props: Props) {
index={tag.type === 'sidecar' ? index : index - sideCarLength}
key={entryPath + tag.title}
entryPath={entryPath}
- addTags={addTags}
- addTag={addTag}
+ addTags={handleAddTags}
+ addTag={handleAddTag}
handleTagMenu={handleTagMenu}
selectedEntries={selectedEntries}
- editTagForEntry={editTagForEntry}
+ editTagForEntry={handleEditTag}
reorderTags={reorderTags}
/>
);
@@ -538,7 +548,7 @@ function CellContent(props: Props) {
}
return tagContainer;
});
- }, [entryTags, isReadOnlyMode, reorderTags, entryPath, selectedEntries]);
+ }, [entryTags, readOnlyMode, reorderTags, entryPath, selectedEntries]);
let entryHeight = 130;
if (entrySize === 'small') {
@@ -584,22 +594,4 @@ function CellContent(props: Props) {
);
}
-function mapStateToProps(state) {
- return {
- reorderTags: state.settings.reorderTags,
- lastThumbnailImageChange: getLastThumbnailImageChange(state),
- isDesktopMode: isDesktopMode(state)
- };
-}
-
-function mapActionCreatorsToProps(dispatch) {
- return bindActionCreators(
- {
- editTagForEntry: TaggingActions.editTagForEntry,
- exitSearchMode: AppActions.exitSearchMode
- },
- dispatch
- );
-}
-
-export default connect(mapStateToProps, mapActionCreatorsToProps)(CellContent);
+export default CellContent;
diff --git a/app/perspectives/grid-perspective/components/GridPagination.tsx b/app/perspectives/grid-perspective/components/GridPagination.tsx
index 897166b84..26c68f190 100644
--- a/app/perspectives/grid-perspective/components/GridPagination.tsx
+++ b/app/perspectives/grid-perspective/components/GridPagination.tsx
@@ -112,7 +112,6 @@ interface Props {
currentLocation: TS.Location;
lastSelectedEntryPath: string;
directoryContent: Array<TS.FileSystemEntry>;
- supportedFileTypes: Array<any>;
openFsEntry: (fsEntry?: TS.FileSystemEntry) => void;
openFileNatively: (path?: string) => void;
loadDirectoryContent: (
diff --git a/app/perspectives/grid-perspective/components/MainContainer.tsx b/app/perspectives/grid-perspective/components/MainContainer.tsx
index 4298df2de..b8c167314 100644
--- a/app/perspectives/grid-perspective/components/MainContainer.tsx
+++ b/app/perspectives/grid-perspective/components/MainContainer.tsx
@@ -16,54 +16,37 @@
*
*/
-import React, { useEffect, useMemo, useReducer, useRef, useState } from 'react';
-import { connect } from 'react-redux';
-import { bindActionCreators } from 'redux';
+import React, { useEffect, useReducer, useRef, useState } from 'react';
+import { useSelector, useDispatch } from 'react-redux';
import { GlobalHotKeys } from 'react-hotkeys';
import withStyles from '@mui/styles/withStyles';
-import {
- isObj,
- locationType,
- sortByCriteria
-} from '@tagspaces/tagspaces-common/misc';
-import AppConfig from '-/AppConfig';
+import { isObj, sortByCriteria } from '@tagspaces/tagspaces-common/misc';
import { isVisibleOnScreen } from '-/utils/dom';
-// import { actions as TagLibraryActions } from '-/reducers/taglibrary';
-import {
- getSupportedFileTypes,
- getDesktopMode,
- getKeyBindingObject
- // isDesktopMode
-} from '-/reducers/settings';
+import { getDesktopMode, getKeyBindingObject } from '-/reducers/settings';
import styles from './styles.css';
import FileMenu from '-/components/menus/FileMenu';
import DirectoryMenu from '-/components/menus/DirectoryMenu';
import EntryTagMenu from '-/components/menus/EntryTagMenu';
-import i18n from '-/services/i18n';
+//import i18n from '-/services/i18n';
import AddRemoveTagsDialog from '-/components/dialogs/AddRemoveTagsDialog';
import MoveCopyFilesDialog from '-/components/dialogs/MoveCopyFilesDialog';
-import TargetMoveFileBox from '-/components/TargetMoveFileBox';
-import FileSourceDnd from '-/components/FileSourceDnd';
-import DragItemTypes from '-/components/DragItemTypes';
import TagDropContainer from '-/components/TagDropContainer';
import IOActions from '-/reducers/io-actions';
import {
actions as AppActions,
+ AppDispatch,
getDirectoryMeta,
getEditedEntryPaths,
- getLastSelectedEntry,
getLastSelectedEntryPath,
getSearchFilter,
getSelectedEntries,
- isDeleteMultipleEntriesDialogOpened,
isReadOnlyMode
} from '-/reducers/app';
-import TaggingActions from '-/reducers/tagging-actions';
import CellContent from './CellContent';
import MainToolbar from './MainToolbar';
import SortingMenu from './SortingMenu';
import GridOptionsMenu from './GridOptionsMenu';
-import { getLocation, getLocations } from '-/reducers/locations';
+import { getCurrentLocation } from '-/reducers/locations';
import PlatformIO from '-/services/platform-facade';
import GridPagination from '-/perspectives/grid-perspective/components/GridPagination';
import GridSettingsDialog from '-/perspectives/grid-perspective/components/GridSettingsDialog';
@@ -76,20 +59,13 @@ import { PerspectiveIDs } from '-/perspectives';
import { fileOperationsEnabled } from '-/perspectives/common/main-container';
import GlobalSearch from '-/services/search-index';
import useFirstRender from '-/utils/useFirstRender';
+import { openURLExternally } from '-/services/utils-io';
interface Props {
classes: any;
theme: any;
- desktopMode: boolean;
currentDirectoryPath: string;
- lastSelectedEntry: any;
- selectedEntries: Array<TS.FileSystemEntry>;
- lastSelectedEntryPath: string;
- supportedFileTypes: Array<any>;
- isReadOnlyMode: boolean;
openFsEntry: (fsEntry?: TS.FileSystemEntry) => void;
- openNextFile: () => any;
- openPrevFile: () => any;
openRenameEntryDialog: () => void;
loadDirectoryContent: (
path: string,
@@ -98,30 +74,11 @@ interface Props {
) => void;
openDirectory: (path: string) => void;
showInFileManager: (path: string) => void;
- openFileNatively: (path?: string) => void;
- openURLExternally: (path: string) => void;
loadParentDirectoryContent: () => void;
- setSelectedEntries: (selectedEntries: Array<TS.FileSystemEntry>) => void;
- addTags: () => void;
- addTag: (tag: TS.Tag, parentTagGroupUuid: TS.Uuid) => void;
removeTags: (paths: Array<string>, tags: Array<TS.Tag>) => void;
removeAllTags: () => void;
directoryContent: Array<TS.FileSystemEntry>;
- moveFiles: (files: Array<string>, destination: string) => Promise<boolean>;
- keyBindings: any;
- showNotification: (
- text: string,
- notificationType: string,
- autohide: boolean
- ) => void;
- currentLocation: TS.Location;
- locations: Array<TS.Location>;
- toggleDeleteMultipleEntriesDialog: () => void;
- directoryMeta: TS.FileSystemEntryMeta;
- setDirectoryMeta: (fsEntryMeta: TS.FileSystemEntryMeta) => void;
lastSearchTimestamp: number;
- searchFilter: string;
- editedEntryPaths: Array<TS.EditedEntryPath>;
}
function getSettings(directoryMeta: TS.FileSystemEntryMeta): TS.FolderSettings {
@@ -139,12 +96,64 @@ function getSettings(directoryMeta: TS.FileSystemEntryMeta): TS.FolderSettings {
}
function GridPerspective(props: Props) {
+ const {
+ classes,
+ loadParentDirectoryContent,
+ theme,
+ currentDirectoryPath,
+ openRenameEntryDialog,
+ directoryContent,
+ lastSearchTimestamp,
+ openFsEntry,
+ loadDirectoryContent,
+ removeTags,
+ removeAllTags,
+ showInFileManager,
+ openDirectory
+ } = props;
+
+ const directoryMeta: TS.FileSystemEntryMeta = useSelector(getDirectoryMeta);
+ const readOnlyMode = useSelector(isReadOnlyMode);
+ const desktopMode = useSelector(getDesktopMode);
+ const selectedEntries: Array<TS.FileSystemEntry> = useSelector(
+ getSelectedEntries
+ );
+ const lastSelectedEntryPath = useSelector(getLastSelectedEntryPath);
+ const keyBindings = useSelector(getKeyBindingObject);
+ const currentLocation: TS.Location = useSelector(getCurrentLocation);
+ const searchFilter: string = useSelector(getSearchFilter);
+ const editedEntryPaths: Array<TS.EditedEntryPath> = useSelector(
+ getEditedEntryPaths
+ );
+
+ const dispatch: AppDispatch = useDispatch();
+
+ // Create functions that dispatch actions
+ const handleMoveFiles = (files: Array<string>, destination: string) =>
+ dispatch(IOActions.moveFiles(files, destination));
+
+ const handleSetSelectedEntries = (entries: Array<TS.FileSystemEntry>) => {
+ dispatch(AppActions.setSelectedEntries(entries));
+ };
+
+ const handleShowNotification = (
+ text: string,
+ notificationType: string,
+ autohide: boolean
+ ) => {
+ dispatch(AppActions.showNotification(text, notificationType, autohide));
+ };
+
+ const handleOpenFileNatively = (path?: string) => {
+ dispatch(AppActions.openFileNatively(path));
+ };
+
const isLocal =
Pro &&
- props.directoryMeta &&
- props.directoryMeta.perspectiveSettings &&
- props.directoryMeta.perspectiveSettings[PerspectiveIDs.GRID];
- const settings = getSettings(props.directoryMeta);
+ directoryMeta &&
+ directoryMeta.perspectiveSettings &&
+ directoryMeta.perspectiveSettings[PerspectiveIDs.GRID];
+ const settings = getSettings(directoryMeta);
const ShareFilesDialog = Pro && Pro.UI ? Pro.UI.ShareFilesDialog : false;
@@ -185,8 +194,8 @@ function GridPerspective(props: Props) {
: defaultSettings.orderBy
);
const sortedDirContent = useRef<Array<TS.FileSystemEntry>>(
- !props.lastSearchTimestamp
- ? props.directoryContent
+ !lastSearchTimestamp
+ ? directoryContent
: GlobalSearch.getInstance().getResults()
);
const layoutType = useRef<string>(
@@ -258,51 +267,40 @@ function GridPerspective(props: Props) {
const [ignored, forceUpdate] = useReducer(x => x + 1, 0);
const firstRender = useFirstRender();
- const {
- classes,
- selectedEntries,
- loadParentDirectoryContent,
- theme,
- currentDirectoryPath
- } = props;
-
useEffect(() => {
- if (props.selectedEntries.length === 1) {
+ if (selectedEntries.length === 1) {
makeFirstSelectedEntryVisible();
}
- }, [props.selectedEntries]);
+ }, [selectedEntries]);
useEffect(() => {
if (!firstRender) {
sortedDirContent.current = sortByCriteria(
- props.searchFilter
- ? props.directoryContent.filter(entry =>
- entry.name
- .toLowerCase()
- .includes(props.searchFilter.toLowerCase())
+ searchFilter
+ ? directoryContent.filter(entry =>
+ entry.name.toLowerCase().includes(searchFilter.toLowerCase())
)
- : props.directoryContent,
+ : directoryContent,
sortBy.current,
orderBy.current
);
forceUpdate();
}
- }, [props.searchFilter]);
+ }, [searchFilter]);
useEffect(() => {
if (!firstRender) {
setSortedDirContent();
}
}, [
- // props.currentDirectoryPath, // open subdirs
- props.directoryContent, // open subdirs todo rethink this (replace with useEffect for currDirPath changes only)
+ directoryContent, // open subdirs todo rethink this (replace with useEffect for currDirPath changes only)
sortBy.current,
orderBy.current
]);
useEffect(() => {
if (!firstRender) {
- if (props.lastSearchTimestamp) {
+ if (lastSearchTimestamp) {
sortBy.current = 'byRelevance';
// orderBy.current = false;
} else {
@@ -317,13 +315,13 @@ function GridPerspective(props: Props) {
}
setSortedDirContent();
}
- }, [props.lastSearchTimestamp]);
+ }, [lastSearchTimestamp]);
function setSortedDirContent() {
- if (!props.lastSearchTimestamp) {
+ if (!lastSearchTimestamp) {
// not in search mode
sortedDirContent.current = sortByCriteria(
- props.directoryContent,
+ directoryContent,
sortBy.current,
orderBy.current
);
@@ -339,13 +337,11 @@ function GridPerspective(props: Props) {
}
} else {
sortedDirContent.current = sortByCriteria(
- props.searchFilter
+ searchFilter
? GlobalSearch.getInstance()
.getResults()
.filter(entry =>
- entry.name
- .toLowerCase()
- .includes(props.searchFilter.toLowerCase())
+ entry.name.toLowerCase().includes(searchFilter.toLowerCase())
)
: GlobalSearch.getInstance().getResults(),
sortBy.current,
@@ -358,15 +354,15 @@ function GridPerspective(props: Props) {
useEffect(() => {
// HANDLE (ADD/REMOVE sidecar TAGS) IN SEARCH RESULTS
- if (!firstRender && props.lastSearchTimestamp) {
+ if (!firstRender && lastSearchTimestamp) {
sortedDirContent.current = GlobalSearch.getInstance().getResults();
forceUpdate();
}
- }, [props.editedEntryPaths]);
+ }, [editedEntryPaths]);
useEffect(() => {
if (!firstRender) {
- const perspectiveSettings = getSettings(props.directoryMeta);
+ const perspectiveSettings = getSettings(directoryMeta);
showDirectories.current =
perspectiveSettings && perspectiveSettings.showDirectories !== undefined
? perspectiveSettings.showDirectories
@@ -416,7 +412,7 @@ function GridPerspective(props: Props) {
: defaultSettings.gridPageLimit;
forceUpdate();
}
- }, [props.directoryMeta]);
+ }, [directoryMeta]);
useEffect(() => {
if (!firstRender && isDefaultSetting.current !== undefined) {
@@ -440,7 +436,7 @@ function GridPerspective(props: Props) {
PerspectiveIDs.GRID,
perspectiveSettings
).then((fsEntryMeta: TS.FileSystemEntryMeta) => {
- props.setDirectoryMeta(fsEntryMeta);
+ dispatch(AppActions.setDirectoryMeta(fsEntryMeta));
});
} else {
localStorage.setItem(
@@ -512,8 +508,8 @@ function GridPerspective(props: Props) {
const handleExportCsvMenu = () => {
if (Pro) {
- if (props.selectedEntries && props.selectedEntries.length > 0) {
- Pro.exportAsCsv.ExportAsCsv(props.selectedEntries);
+ if (selectedEntries && selectedEntries.length > 0) {
+ Pro.exportAsCsv.ExportAsCsv(selectedEntries);
} else {
Pro.exportAsCsv.ExportAsCsv(sortedDirContent.current);
}
@@ -521,7 +517,7 @@ function GridPerspective(props: Props) {
};
const clearSelection = () => {
- props.setSelectedEntries([]);
+ handleSetSelectedEntries([]);
selectedEntryPath.current = undefined;
};
@@ -531,10 +527,10 @@ function GridPerspective(props: Props) {
if (someFileSelected) {
clearSelection();
} else {
- if (!props.lastSearchTimestamp) {
- props.setSelectedEntries(props.directoryContent);
+ if (!lastSearchTimestamp) {
+ handleSetSelectedEntries(directoryContent);
} else {
- props.setSelectedEntries(GlobalSearch.getInstance().getResults());
+ handleSetSelectedEntries(GlobalSearch.getInstance().getResults());
}
}
};
@@ -588,7 +584,7 @@ function GridPerspective(props: Props) {
const openHelpWebPage = () => {
closeOptionsMenu();
- props.openURLExternally(Links.documentationLinks.defaultPerspective);
+ openURLExternally(Links.documentationLinks.defaultPerspective);
};
const openSettings = () => {
@@ -622,7 +618,7 @@ function GridPerspective(props: Props) {
};
const openDeleteFileDialog = () => {
- props.toggleDeleteMultipleEntriesDialog();
+ dispatch(AppActions.toggleDeleteMultipleEntriesDialog());
};
const openAddRemoveTagsDialog = () => {
@@ -630,70 +626,65 @@ function GridPerspective(props: Props) {
};
const keyMap = {
- nextDocument: props.keyBindings.nextDocument,
- prevDocument: props.keyBindings.prevDocument,
- selectAll: props.keyBindings.selectAll,
- deleteDocument: props.keyBindings.deleteDocument,
- addRemoveTags: props.keyBindings.addRemoveTags,
- renameFile: props.keyBindings.renameFile,
- openEntry: props.keyBindings.openEntry,
- openFileExternally: props.keyBindings.openFileExternally
+ nextDocument: keyBindings.nextDocument,
+ prevDocument: keyBindings.prevDocument,
+ selectAll: keyBindings.selectAll,
+ deleteDocument: keyBindings.deleteDocument,
+ addRemoveTags: keyBindings.addRemoveTags,
+ renameFile: keyBindings.renameFile,
+ openEntry: keyBindings.openEntry,
+ openFileExternally: keyBindings.openFileExternally
};
const onContextMenu = (event: React.MouseEvent<HTMLDivElement>) => {
event.preventDefault();
setMouseX(event.clientX);
setMouseY(event.clientY);
- if (props.selectedEntries.length > 0) {
- props.setSelectedEntries([]);
+ if (selectedEntries.length > 0) {
+ handleSetSelectedEntries([]);
}
setDirContextMenuAnchorEl(event.currentTarget);
};
const onClick = (event: React.MouseEvent<HTMLDivElement>) => {
event.preventDefault();
- if (props.selectedEntries.length > 0) {
- props.setSelectedEntries([]);
+ if (selectedEntries.length > 0) {
+ handleSetSelectedEntries([]);
}
};
const keyBindingHandlers = {
- nextDocument: () => props.openNextFile(),
- prevDocument: () => props.openPrevFile(),
+ nextDocument: () => dispatch(AppActions.openNextFile()),
+ prevDocument: () => dispatch(AppActions.openPrevFile()),
selectAll: () => toggleSelectAllFiles(),
deleteDocument: () => {
- if (fileOperationsEnabled(props.selectedEntries)) {
+ if (fileOperationsEnabled(selectedEntries)) {
openDeleteFileDialog();
}
},
addRemoveTags: () => {
- if (props.lastSelectedEntryPath) {
+ if (lastSelectedEntryPath) {
openAddRemoveTagsDialog();
}
},
renameFile: () => {
- props.openRenameEntryDialog();
+ openRenameEntryDialog();
},
openEntry: e => {
e.preventDefault();
- props.openFsEntry();
+ openFsEntry();
},
openFileExternally: () => {
- props.openFileNatively();
+ handleOpenFileNatively();
}
};
- /*const selectedFilePaths = selectedEntries
- ? selectedEntries
- .filter(fsEntry => fsEntry.isFile)
- .map(fsentry => fsentry.path)
- : [];*/
const sortedDirectories = sortedDirContent.current.filter(
entry => !entry.isFile
);
const sortedFiles = sortedDirContent.current.filter(entry => entry.isFile);
- const locationPath = props.currentLocation
- ? PlatformIO.getLocationPath(props.currentLocation)
+ const locationPath = currentLocation
+ ? PlatformIO.getLocationPath(currentLocation)
: '';
let entryWidth = 200;
if (entrySize.current === 'small') {
@@ -724,14 +715,14 @@ function GridPerspective(props: Props) {
selected = true;
}
const selectEntry = (fsEntry: TS.FileSystemEntry) => {
- props.setSelectedEntries([...selectedEntries, fsEntry]);
+ handleSetSelectedEntries([...selectedEntries, fsEntry]);
};
const deselectEntry = (fsEntry: TS.FileSystemEntry) => {
const newSelection = selectedEntries.filter(
data => data.path !== fsEntry.path
);
- props.setSelectedEntries(newSelection);
+ handleSetSelectedEntries(newSelection);
};
return (
<TagDropContainer
@@ -748,18 +739,14 @@ function GridPerspective(props: Props) {
classes={classes}
isLast={isLast}
theme={theme}
- supportedFileTypes={props.supportedFileTypes}
thumbnailMode={thumbnailMode.current}
- addTags={props.addTags}
- addTag={props.addTag}
selectedEntries={selectedEntries}
selectEntry={selectEntry}
deselectEntry={deselectEntry}
- isReadOnlyMode={props.isReadOnlyMode}
handleTagMenu={handleTagMenu}
layoutType={layoutType.current}
showTags={showTags.current}
- openFsEntry={props.openFsEntry}
+ openFsEntry={openFsEntry}
handleGridContextMenu={(
event: React.MouseEvent<HTMLDivElement>,
fsEntry: TS.FileSystemEntry
@@ -786,17 +773,16 @@ function GridPerspective(props: Props) {
classes={classes}
prefixDataTID={'grid'}
layoutType={layoutType.current}
- isReadOnlyMode={props.isReadOnlyMode}
selectedEntries={selectedEntries}
loadParentDirectoryContent={loadParentDirectoryContent}
toggleSelectAllFiles={toggleSelectAllFiles}
someFileSelected={someFileSelected}
handleLayoutSwitch={handleLayoutSwitch}
openAddRemoveTagsDialog={openAddRemoveTagsDialog}
- fileOperationsEnabled={fileOperationsEnabled(props.selectedEntries)}
+ fileOperationsEnabled={fileOperationsEnabled(selectedEntries)}
openMoveCopyFilesDialog={openMoveCopyFilesDialog}
openDeleteFileDialog={openDeleteFileDialog}
- openFsEntry={props.openFsEntry}
+ openFsEntry={openFsEntry}
handleSortingMenu={handleSortingMenu}
handleExportCsvMenu={handleExportCsvMenu}
openSettings={openSettings}
@@ -827,10 +813,10 @@ function GridPerspective(props: Props) {
showDetails={showDetails.current}
showDescription={showDescription.current}
showDirectories={showDirectories.current}
- isReadOnlyMode={props.isReadOnlyMode}
+ isReadOnlyMode={readOnlyMode}
layoutType={layoutType.current}
- desktopMode={props.desktopMode}
- openRenameEntryDialog={props.openRenameEntryDialog}
+ desktopMode={desktopMode}
+ openRenameEntryDialog={openRenameEntryDialog}
showTags={showTags.current}
thumbnailMode={thumbnailMode.current}
entrySize={entrySize.current}
@@ -838,27 +824,26 @@ function GridPerspective(props: Props) {
getCellContent={getCellContent}
currentPage={1}
currentLocationPath={locationPath}
- currentDirectoryPath={props.currentDirectoryPath}
+ currentDirectoryPath={currentDirectoryPath}
onClick={onClick}
onContextMenu={onContextMenu}
settings={settings}
- selectedEntries={props.selectedEntries}
- setSelectedEntries={props.setSelectedEntries}
+ selectedEntries={selectedEntries}
+ setSelectedEntries={handleSetSelectedEntries}
singleClickAction={singleClickAction.current}
- currentLocation={props.currentLocation}
+ currentLocation={currentLocation}
directoryContent={
- props.lastSearchTimestamp
+ lastSearchTimestamp
? GlobalSearch.getInstance().getResults()
- : props.directoryContent
+ : directoryContent
}
- supportedFileTypes={props.supportedFileTypes}
- openFsEntry={props.openFsEntry}
- openFileNatively={props.openFileNatively}
- loadDirectoryContent={props.loadDirectoryContent}
+ openFsEntry={openFsEntry}
+ openFileNatively={handleOpenFileNatively}
+ loadDirectoryContent={loadDirectoryContent}
setFileContextMenuAnchorEl={setFileContextMenuAnchorEl}
setDirContextMenuAnchorEl={setDirContextMenuAnchorEl}
- showNotification={props.showNotification}
- moveFiles={props.moveFiles}
+ showNotification={handleShowNotification}
+ moveFiles={handleMoveFiles}
clearSelection={clearSelection}
/>
</GlobalHotKeys>
@@ -866,17 +851,15 @@ function GridPerspective(props: Props) {
<AddRemoveTagsDialog
open={isAddRemoveTagsDialogOpened}
onClose={() => setIsAddRemoveTagsDialogOpened(false)}
- addTags={props.addTags}
- removeTags={props.removeTags}
- removeAllTags={props.removeAllTags}
- selectedEntries={props.selectedEntries}
+ removeTags={removeTags}
+ removeAllTags={removeAllTags}
+ selectedEntries={selectedEntries}
/>
)}
{isAddTagDialogOpened !== undefined && (
<AddTagToTagGroupDialog
open={true}
onClose={() => setIsAddTagDialogOpened(undefined)}
- addTag={props.addTag}
selectedTag={isAddTagDialogOpened}
/>
)}
@@ -915,7 +898,7 @@ function GridPerspective(props: Props) {
currentDirectoryPath,
PerspectiveIDs.GRID
).then((fsEntryMeta: TS.FileSystemEntryMeta) => {
- props.setDirectoryMeta(fsEntryMeta);
+ dispatch(AppActions.setDirectoryMeta(fsEntryMeta));
setIsGridSettingsDialogOpened(false);
});
}}
@@ -941,7 +924,7 @@ function GridPerspective(props: Props) {
open={Boolean(fileContextMenuAnchorEl)}
onClose={() => setFileContextMenuAnchorEl(null)}
openDeleteFileDialog={openDeleteFileDialog}
- openRenameFileDialog={props.openRenameEntryDialog}
+ openRenameFileDialog={openRenameEntryDialog}
openMoveCopyFilesDialog={openMoveCopyFilesDialog}
openShareFilesDialog={
PlatformIO.haveObjectStoreSupport()
@@ -949,16 +932,12 @@ function GridPerspective(props: Props) {
: undefined
}
openAddRemoveTagsDialog={openAddRemoveTagsDialog}
- openFsEntry={props.openFsEntry}
- openFileNatively={props.openFileNatively}
- loadDirectoryContent={props.loadDirectoryContent}
- showInFileManager={props.showInFileManager}
- showNotification={props.showNotification}
- isReadOnlyMode={props.isReadOnlyMode}
- selectedFilePath={props.lastSelectedEntryPath}
- selectedEntries={props.selectedEntries}
- currentLocation={props.currentLocation}
- locations={props.locations}
+ openFileNatively={handleOpenFileNatively}
+ loadDirectoryContent={loadDirectoryContent}
+ showInFileManager={showInFileManager}
+ selectedFilePath={lastSelectedEntryPath}
+ selectedEntries={selectedEntries}
+ currentLocation={currentLocation}
/>
)}
{/* {Boolean(dirContextMenuAnchorEl) && ( // todo move dialogs from DirectoryMenu */}
@@ -968,17 +947,14 @@ function GridPerspective(props: Props) {
anchorEl={dirContextMenuAnchorEl}
mouseX={mouseX}
mouseY={mouseY}
- directoryPath={props.lastSelectedEntryPath}
- loadDirectoryContent={props.loadDirectoryContent}
- openRenameDirectoryDialog={props.openRenameEntryDialog}
+ directoryPath={lastSelectedEntryPath}
+ loadDirectoryContent={loadDirectoryContent}
+ openRenameDirectoryDialog={openRenameEntryDialog}
openMoveCopyFilesDialog={openMoveCopyFilesDialog}
- openDirectory={props.openDirectory}
- openFsEntry={props.openFsEntry}
- perspectiveMode={
- props.lastSelectedEntryPath !== props.currentDirectoryPath
- }
- currentLocation={props.currentLocation}
- locations={props.locations}
+ openDirectory={openDirectory}
+ openFsEntry={openFsEntry}
+ perspectiveMode={lastSelectedEntryPath !== currentDirectoryPath}
+ currentLocation={currentLocation}
openAddRemoveTagsDialog={openAddRemoveTagsDialog}
/>
{/* {Boolean(tagContextMenuAnchorEl) && ( // TODO EntryTagMenu is used in TagSelect we cannot move confirm dialog from menu */}
@@ -989,8 +965,7 @@ function GridPerspective(props: Props) {
setIsAddTagDialogOpened={setIsAddTagDialogOpened}
selectedTag={selectedTag.current}
currentEntryPath={selectedEntryPath.current} // getSelEntryPath()}
- removeTags={props.removeTags}
- isReadOnlyMode={props.isReadOnlyMode}
+ removeTags={removeTags}
/>
{Boolean(sortingContextMenuAnchorEl) && (
<SortingMenu
@@ -1000,7 +975,7 @@ function GridPerspective(props: Props) {
sortBy={sortBy.current}
orderBy={orderBy.current}
handleSortBy={handleSortBy}
- searchModeEnabled={props.lastSearchTimestamp !== undefined}
+ searchModeEnabled={lastSearchTimestamp !== undefined}
/>
)}
{Boolean(optionsContextMenuAnchorEl) && (
@@ -1026,48 +1001,4 @@ function GridPerspective(props: Props) {
);
}
-function mapActionCreatorsToProps(dispatch) {
- return bindActionCreators(
- {
- moveFiles: IOActions.moveFiles,
- setSelectedEntries: AppActions.setSelectedEntries,
- showNotification: AppActions.showNotification,
- openFileNatively: AppActions.openFileNatively,
- openURLExternally: AppActions.openURLExternally,
- openNextFile: AppActions.openNextFile,
- openPrevFile: AppActions.openPrevFile,
- setDirectoryMeta: AppActions.setDirectoryMeta,
- toggleDeleteMultipleEntriesDialog:
- AppActions.toggleDeleteMultipleEntriesDialog,
- addTags: TaggingActions.addTags,
- addTag: AppActions.addTag
- },
- dispatch
- );
-}
-
-function mapStateToProps(state) {
- return {
- directoryMeta: getDirectoryMeta(state),
- supportedFileTypes: getSupportedFileTypes(state),
- isReadOnlyMode: isReadOnlyMode(state),
- lastSelectedEntry: getLastSelectedEntry(state),
- desktopMode: getDesktopMode(state),
- selectedEntries: getSelectedEntries(state),
- lastSelectedEntryPath: getLastSelectedEntryPath(state),
- keyBindings: getKeyBindingObject(state),
- currentLocation: getLocation(state, state.app.currentLocationId),
- locations: getLocations(state),
- isDeleteMultipleEntriesDialogOpened: isDeleteMultipleEntriesDialogOpened(
- state
- ),
- searchFilter: getSearchFilter(state),
- editedEntryPaths: getEditedEntryPaths(state)
- };
-}
-
-export default connect(
- mapStateToProps,
- mapActionCreatorsToProps
- // @ts-ignore
-)(withStyles(styles, { withTheme: true })(GridPerspective));
+export default withStyles(styles, { withTheme: true })(GridPerspective);
diff --git a/app/perspectives/grid-perspective/components/MainToolbar.tsx b/app/perspectives/grid-perspective/components/MainToolbar.tsx
index 584f26cdb..591e356c3 100644
--- a/app/perspectives/grid-perspective/components/MainToolbar.tsx
+++ b/app/perspectives/grid-perspective/components/MainToolbar.tsx
@@ -17,6 +17,7 @@
*/
import React from 'react';
+import { useSelector } from 'react-redux';
import Toolbar from '@mui/material/Toolbar';
import Tooltip from '-/components/Tooltip';
import IconButton from '@mui/material/IconButton';
@@ -45,12 +46,11 @@ import {
import { getKeyBindingObject } from '-/reducers/settings';
import { getAllPropertiesPromise } from '-/services/utils-io';
import { TS } from '-/tagspaces.namespace';
-import { actions as AppActions } from '-/reducers/app';
+import { actions as AppActions, isReadOnlyMode } from '-/reducers/app';
interface Props {
classes: any;
prefixDataTID?: string;
- isReadOnlyMode: boolean;
selectedEntries: Array<TS.FileSystemEntry>;
loadParentDirectoryContent: () => void;
toggleSelectAllFiles: (event: any) => void;
@@ -83,7 +83,6 @@ function MainToolbar(props: Props) {
loadParentDirectoryContent,
layoutType,
handleLayoutSwitch,
- isReadOnlyMode,
openAddRemoveTagsDialog,
openMoveCopyFilesDialog,
openDeleteFileDialog,
@@ -93,6 +92,7 @@ function MainToolbar(props: Props) {
keyBindings,
openShareFilesDialog
} = props;
+ const readOnlyMode = useSelector(isReadOnlyMode);
function showProperties() {
getAllPropertiesPromise(props.directoryPath)
@@ -168,7 +168,7 @@ function MainToolbar(props: Props) {
<FolderPropertiesIcon />
</IconButton>
</Tooltip>
- {!isReadOnlyMode && (
+ {!readOnlyMode && (
<Tooltip
title={
i18n.t('core:tagSelectedEntries') +
@@ -190,7 +190,7 @@ function MainToolbar(props: Props) {
</span>
</Tooltip>
)}
- {!isReadOnlyMode && (
+ {!readOnlyMode && (
<Tooltip title={i18n.t('core:copyMoveSelectedEntries')}>
<span>
<IconButton
@@ -205,7 +205,7 @@ function MainToolbar(props: Props) {
</span>
</Tooltip>
)}
- {!isReadOnlyMode && (
+ {!readOnlyMode && (
<Tooltip
title={
i18n.t('core:deleteSelectedEntries') +
diff --git a/app/perspectives/grid-perspective/components/styles.css.tsx b/app/perspectives/grid-perspective/components/styles.css.tsx
index f022ba85e..85df0f077 100644
--- a/app/perspectives/grid-perspective/components/styles.css.tsx
+++ b/app/perspectives/grid-perspective/components/styles.css.tsx
@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
-import AppConfig from '-/AppConfig';
+// import AppConfig from '-/AppConfig';
import { alpha } from '@mui/material/styles';
export default (theme: any): any => ({
diff --git a/app/perspectives/list/components/MainContainer.tsx b/app/perspectives/list/components/MainContainer.tsx
index 36d3caf90..8ecb56754 100644
--- a/app/perspectives/list/components/MainContainer.tsx
+++ b/app/perspectives/list/components/MainContainer.tsx
@@ -16,54 +16,37 @@
*
*/
-import React, { useEffect, useMemo, useReducer, useRef, useState } from 'react';
-import { connect } from 'react-redux';
-import { bindActionCreators } from 'redux';
+import React, { useEffect, useReducer, useRef, useState } from 'react';
+import { useSelector, useDispatch } from 'react-redux';
import { GlobalHotKeys } from 'react-hotkeys';
import withStyles from '@mui/styles/withStyles';
-import {
- isObj,
- locationType,
- sortByCriteria
-} from '@tagspaces/tagspaces-common/misc';
-import AppConfig from '-/AppConfig';
+import { isObj, sortByCriteria } from '@tagspaces/tagspaces-common/misc';
import { isVisibleOnScreen } from '-/utils/dom';
-// import { actions as TagLibraryActions } from '-/reducers/taglibrary';
-import {
- getSupportedFileTypes,
- getDesktopMode,
- getKeyBindingObject
- // isDesktopMode
-} from '-/reducers/settings';
+import { getDesktopMode, getKeyBindingObject } from '-/reducers/settings';
import styles from '-/perspectives/grid-perspective/components/styles.css';
import FileMenu from '-/components/menus/FileMenu';
import DirectoryMenu from '-/components/menus/DirectoryMenu';
import EntryTagMenu from '-/components/menus/EntryTagMenu';
-import i18n from '-/services/i18n';
+//import i18n from '-/services/i18n';
import AddRemoveTagsDialog from '-/components/dialogs/AddRemoveTagsDialog';
import MoveCopyFilesDialog from '-/components/dialogs/MoveCopyFilesDialog';
-import TargetMoveFileBox from '-/components/TargetMoveFileBox';
-import FileSourceDnd from '-/components/FileSourceDnd';
-import DragItemTypes from '-/components/DragItemTypes';
import TagDropContainer from '-/components/TagDropContainer';
import IOActions from '-/reducers/io-actions';
import {
actions as AppActions,
+ AppDispatch,
getDirectoryMeta,
getEditedEntryPaths,
- getLastSelectedEntry,
getLastSelectedEntryPath,
getSearchFilter,
getSelectedEntries,
- isDeleteMultipleEntriesDialogOpened,
isReadOnlyMode
} from '-/reducers/app';
-import TaggingActions from '-/reducers/tagging-actions';
import CellContent from '-/perspectives/grid-perspective/components/CellContent';
import MainToolbar from '-/perspectives/grid-perspective/components/MainToolbar';
import SortingMenu from '-/perspectives/grid-perspective/components/SortingMenu';
import GridOptionsMenu from '-/perspectives/grid-perspective/components/GridOptionsMenu';
-import { getLocation, getLocations } from '-/reducers/locations';
+import { getCurrentLocation } from '-/reducers/locations';
import PlatformIO from '-/services/platform-facade';
import GridPagination from '-/perspectives/grid-perspective/components/GridPagination';
import GridSettingsDialog from '-/perspectives/grid-perspective/components/GridSettingsDialog';
@@ -76,20 +59,13 @@ import { PerspectiveIDs } from '-/perspectives';
import { fileOperationsEnabled } from '-/perspectives/common/main-container';
import GlobalSearch from '-/services/search-index';
import useFirstRender from '-/utils/useFirstRender';
+import { openURLExternally } from '-/services/utils-io';
interface Props {
classes: any;
theme: any;
- desktopMode: boolean;
currentDirectoryPath: string;
- lastSelectedEntry: any;
- selectedEntries: Array<TS.FileSystemEntry>;
- lastSelectedEntryPath: string;
- supportedFileTypes: Array<any>;
- isReadOnlyMode: boolean;
openFsEntry: (fsEntry?: TS.FileSystemEntry) => void;
- openNextFile: () => any;
- openPrevFile: () => any;
openRenameEntryDialog: () => void;
loadDirectoryContent: (
path: string,
@@ -98,30 +74,11 @@ interface Props {
) => void;
openDirectory: (path: string) => void;
showInFileManager: (path: string) => void;
- openFileNatively: (path?: string) => void;
- openURLExternally: (path: string) => void;
loadParentDirectoryContent: () => void;
- setSelectedEntries: (selectedEntries: Array<TS.FileSystemEntry>) => void;
- addTags: () => void;
- addTag: (tag: TS.Tag, parentTagGroupUuid: TS.Uuid) => void;
removeTags: (paths: Array<string>, tags: Array<TS.Tag>) => void;
removeAllTags: () => void;
directoryContent: Array<TS.FileSystemEntry>;
- moveFiles: (files: Array<string>, destination: string) => Promise<boolean>;
- keyBindings: any;
- showNotification: (
- text: string,
- notificationType: string,
- autohide: boolean
- ) => void;
- currentLocation: TS.Location;
- locations: Array<TS.Location>;
- toggleDeleteMultipleEntriesDialog: () => void;
- directoryMeta: TS.FileSystemEntryMeta;
- setDirectoryMeta: (fsEntryMeta: TS.FileSystemEntryMeta) => void;
lastSearchTimestamp: number;
- searchFilter: string;
- editedEntryPaths: Array<TS.EditedEntryPath>;
}
function getSettings(directoryMeta: TS.FileSystemEntryMeta): TS.FolderSettings {
@@ -139,12 +96,64 @@ function getSettings(directoryMeta: TS.FileSystemEntryMeta): TS.FolderSettings {
}
function GridPerspective(props: Props) {
+ const {
+ classes,
+ loadParentDirectoryContent,
+ theme,
+ currentDirectoryPath,
+ openRenameEntryDialog,
+ directoryContent,
+ lastSearchTimestamp,
+ openFsEntry,
+ loadDirectoryContent,
+ removeTags,
+ removeAllTags,
+ showInFileManager,
+ openDirectory
+ } = props;
+
+ const directoryMeta: TS.FileSystemEntryMeta = useSelector(getDirectoryMeta);
+ const readOnlyMode = useSelector(isReadOnlyMode);
+ const desktopMode = useSelector(getDesktopMode);
+ const selectedEntries: Array<TS.FileSystemEntry> = useSelector(
+ getSelectedEntries
+ );
+ const lastSelectedEntryPath = useSelector(getLastSelectedEntryPath);
+ const keyBindings = useSelector(getKeyBindingObject);
+ const currentLocation: TS.Location = useSelector(getCurrentLocation);
+ const searchFilter: string = useSelector(getSearchFilter);
+ const editedEntryPaths: Array<TS.EditedEntryPath> = useSelector(
+ getEditedEntryPaths
+ );
+
+ const dispatch: AppDispatch = useDispatch();
+
+ // Create functions that dispatch actions
+ const handleMoveFiles = (files: Array<string>, destination: string) =>
+ dispatch(IOActions.moveFiles(files, destination));
+
+ const handleSetSelectedEntries = (entries: Array<TS.FileSystemEntry>) => {
+ dispatch(AppActions.setSelectedEntries(entries));
+ };
+
+ const handleShowNotification = (
+ text: string,
+ notificationType: string,
+ autohide: boolean
+ ) => {
+ dispatch(AppActions.showNotification(text, notificationType, autohide));
+ };
+
+ const handleOpenFileNatively = (path?: string) => {
+ dispatch(AppActions.openFileNatively(path));
+ };
+
const isLocal =
Pro &&
- props.directoryMeta &&
- props.directoryMeta.perspectiveSettings &&
- props.directoryMeta.perspectiveSettings[PerspectiveIDs.LIST];
- const settings = getSettings(props.directoryMeta);
+ directoryMeta &&
+ directoryMeta.perspectiveSettings &&
+ directoryMeta.perspectiveSettings[PerspectiveIDs.LIST];
+ const settings = getSettings(directoryMeta);
const ShareFilesDialog = Pro && Pro.UI ? Pro.UI.ShareFilesDialog : false;
@@ -185,8 +194,8 @@ function GridPerspective(props: Props) {
: defaultSettings.orderBy
);
const sortedDirContent = useRef<Array<TS.FileSystemEntry>>(
- !props.lastSearchTimestamp
- ? props.directoryContent
+ !lastSearchTimestamp
+ ? directoryContent
: GlobalSearch.getInstance().getResults()
);
const layoutType = useRef<string>(
@@ -258,51 +267,40 @@ function GridPerspective(props: Props) {
const [ignored, forceUpdate] = useReducer(x => x + 1, 0);
const firstRender = useFirstRender();
- const {
- classes,
- selectedEntries,
- loadParentDirectoryContent,
- theme,
- currentDirectoryPath
- } = props;
-
useEffect(() => {
- if (props.selectedEntries.length === 1) {
+ if (selectedEntries.length === 1) {
makeFirstSelectedEntryVisible();
}
- }, [props.selectedEntries]);
+ }, [selectedEntries]);
useEffect(() => {
if (!firstRender) {
sortedDirContent.current = sortByCriteria(
- props.searchFilter
- ? props.directoryContent.filter(entry =>
- entry.name
- .toLowerCase()
- .includes(props.searchFilter.toLowerCase())
+ searchFilter
+ ? directoryContent.filter(entry =>
+ entry.name.toLowerCase().includes(searchFilter.toLowerCase())
)
- : props.directoryContent,
+ : directoryContent,
sortBy.current,
orderBy.current
);
forceUpdate();
}
- }, [props.searchFilter]);
+ }, [searchFilter]);
useEffect(() => {
if (!firstRender) {
setSortedDirContent();
}
}, [
- // props.currentDirectoryPath, // open subdirs
- props.directoryContent, // open subdirs todo rethink this (replace with useEffect for currDirPath changes only)
+ directoryContent, // open subdirs todo rethink this (replace with useEffect for currDirPath changes only)
sortBy.current,
orderBy.current
]);
useEffect(() => {
if (!firstRender) {
- if (props.lastSearchTimestamp) {
+ if (lastSearchTimestamp) {
sortBy.current = 'byRelevance';
// orderBy.current = false;
} else {
@@ -317,13 +315,13 @@ function GridPerspective(props: Props) {
}
setSortedDirContent();
}
- }, [props.lastSearchTimestamp]);
+ }, [lastSearchTimestamp]);
function setSortedDirContent() {
- if (!props.lastSearchTimestamp) {
+ if (!lastSearchTimestamp) {
// not in search mode
sortedDirContent.current = sortByCriteria(
- props.directoryContent,
+ directoryContent,
sortBy.current,
orderBy.current
);
@@ -339,13 +337,11 @@ function GridPerspective(props: Props) {
}
} else {
sortedDirContent.current = sortByCriteria(
- props.searchFilter
+ searchFilter
? GlobalSearch.getInstance()
.getResults()
.filter(entry =>
- entry.name
- .toLowerCase()
- .includes(props.searchFilter.toLowerCase())
+ entry.name.toLowerCase().includes(searchFilter.toLowerCase())
)
: GlobalSearch.getInstance().getResults(),
sortBy.current,
@@ -358,15 +354,15 @@ function GridPerspective(props: Props) {
useEffect(() => {
// HANDLE (ADD/REMOVE sidecar TAGS) IN SEARCH RESULTS
- if (!firstRender && props.lastSearchTimestamp) {
+ if (!firstRender && lastSearchTimestamp) {
sortedDirContent.current = GlobalSearch.getInstance().getResults();
forceUpdate();
}
- }, [props.editedEntryPaths]);
+ }, [editedEntryPaths]);
useEffect(() => {
if (!firstRender) {
- const perspectiveSettings = getSettings(props.directoryMeta);
+ const perspectiveSettings = getSettings(directoryMeta);
showDirectories.current =
perspectiveSettings && perspectiveSettings.showDirectories !== undefined
? perspectiveSettings.showDirectories
@@ -416,7 +412,7 @@ function GridPerspective(props: Props) {
: defaultSettings.gridPageLimit;
forceUpdate();
}
- }, [props.directoryMeta]);
+ }, [directoryMeta]);
useEffect(() => {
if (!firstRender && isDefaultSetting.current !== undefined) {
@@ -440,7 +436,7 @@ function GridPerspective(props: Props) {
PerspectiveIDs.LIST,
perspectiveSettings
).then((fsEntryMeta: TS.FileSystemEntryMeta) => {
- props.setDirectoryMeta(fsEntryMeta);
+ dispatch(AppActions.setDirectoryMeta(fsEntryMeta));
});
} else {
localStorage.setItem(
@@ -512,8 +508,8 @@ function GridPerspective(props: Props) {
const handleExportCsvMenu = () => {
if (Pro) {
- if (props.selectedEntries && props.selectedEntries.length > 0) {
- Pro.exportAsCsv.ExportAsCsv(props.selectedEntries);
+ if (selectedEntries && selectedEntries.length > 0) {
+ Pro.exportAsCsv.ExportAsCsv(selectedEntries);
} else {
Pro.exportAsCsv.ExportAsCsv(sortedDirContent.current);
}
@@ -521,7 +517,7 @@ function GridPerspective(props: Props) {
};
const clearSelection = () => {
- props.setSelectedEntries([]);
+ handleSetSelectedEntries([]);
selectedEntryPath.current = undefined;
};
@@ -531,10 +527,10 @@ function GridPerspective(props: Props) {
if (someFileSelected) {
clearSelection();
} else {
- if (!props.lastSearchTimestamp) {
- props.setSelectedEntries(props.directoryContent);
+ if (!lastSearchTimestamp) {
+ handleSetSelectedEntries(directoryContent);
} else {
- props.setSelectedEntries(GlobalSearch.getInstance().getResults());
+ handleSetSelectedEntries(GlobalSearch.getInstance().getResults());
}
}
};
@@ -588,7 +584,7 @@ function GridPerspective(props: Props) {
const openHelpWebPage = () => {
closeOptionsMenu();
- props.openURLExternally(Links.documentationLinks.defaultPerspective);
+ openURLExternally(Links.documentationLinks.defaultPerspective);
};
const openSettings = () => {
@@ -622,7 +618,7 @@ function GridPerspective(props: Props) {
};
const openDeleteFileDialog = () => {
- props.toggleDeleteMultipleEntriesDialog();
+ dispatch(AppActions.toggleDeleteMultipleEntriesDialog());
};
const openAddRemoveTagsDialog = () => {
@@ -630,70 +626,65 @@ function GridPerspective(props: Props) {
};
const keyMap = {
- nextDocument: props.keyBindings.nextDocument,
- prevDocument: props.keyBindings.prevDocument,
- selectAll: props.keyBindings.selectAll,
- deleteDocument: props.keyBindings.deleteDocument,
- addRemoveTags: props.keyBindings.addRemoveTags,
- renameFile: props.keyBindings.renameFile,
- openEntry: props.keyBindings.openEntry,
- openFileExternally: props.keyBindings.openFileExternally
+ nextDocument: keyBindings.nextDocument,
+ prevDocument: keyBindings.prevDocument,
+ selectAll: keyBindings.selectAll,
+ deleteDocument: keyBindings.deleteDocument,
+ addRemoveTags: keyBindings.addRemoveTags,
+ renameFile: keyBindings.renameFile,
+ openEntry: keyBindings.openEntry,
+ openFileExternally: keyBindings.openFileExternally
};
const onContextMenu = (event: React.MouseEvent<HTMLDivElement>) => {
event.preventDefault();
setMouseX(event.clientX);
setMouseY(event.clientY);
- if (props.selectedEntries.length > 0) {
- props.setSelectedEntries([]);
+ if (selectedEntries.length > 0) {
+ handleSetSelectedEntries([]);
}
setDirContextMenuAnchorEl(event.currentTarget);
};
const onClick = (event: React.MouseEvent<HTMLDivElement>) => {
event.preventDefault();
- if (props.selectedEntries.length > 0) {
- props.setSelectedEntries([]);
+ if (selectedEntries.length > 0) {
+ handleSetSelectedEntries([]);
}
};
const keyBindingHandlers = {
- nextDocument: () => props.openNextFile(),
- prevDocument: () => props.openPrevFile(),
+ nextDocument: () => dispatch(AppActions.openNextFile()),
+ prevDocument: () => dispatch(AppActions.openPrevFile()),
selectAll: () => toggleSelectAllFiles(),
deleteDocument: () => {
- if (fileOperationsEnabled(props.selectedEntries)) {
+ if (fileOperationsEnabled(selectedEntries)) {
openDeleteFileDialog();
}
},
addRemoveTags: () => {
- if (props.lastSelectedEntryPath) {
+ if (lastSelectedEntryPath) {
openAddRemoveTagsDialog();
}
},
renameFile: () => {
- props.openRenameEntryDialog();
+ openRenameEntryDialog();
},
openEntry: e => {
e.preventDefault();
- props.openFsEntry();
+ openFsEntry();
},
openFileExternally: () => {
- props.openFileNatively();
+ handleOpenFileNatively();
}
};
- /*const selectedFilePaths = selectedEntries
- ? selectedEntries
- .filter(fsEntry => fsEntry.isFile)
- .map(fsentry => fsentry.path)
- : [];*/
const sortedDirectories = sortedDirContent.current.filter(
entry => !entry.isFile
);
const sortedFiles = sortedDirContent.current.filter(entry => entry.isFile);
- const locationPath = props.currentLocation
- ? PlatformIO.getLocationPath(props.currentLocation)
+ const locationPath = currentLocation
+ ? PlatformIO.getLocationPath(currentLocation)
: '';
let entryWidth = 200;
if (entrySize.current === 'small') {
@@ -724,14 +715,14 @@ function GridPerspective(props: Props) {
selected = true;
}
const selectEntry = (fsEntry: TS.FileSystemEntry) => {
- props.setSelectedEntries([...selectedEntries, fsEntry]);
+ handleSetSelectedEntries([...selectedEntries, fsEntry]);
};
const deselectEntry = (fsEntry: TS.FileSystemEntry) => {
const newSelection = selectedEntries.filter(
data => data.path !== fsEntry.path
);
- props.setSelectedEntries(newSelection);
+ handleSetSelectedEntries(newSelection);
};
return (
<TagDropContainer
@@ -748,18 +739,14 @@ function GridPerspective(props: Props) {
classes={classes}
isLast={isLast}
theme={theme}
- supportedFileTypes={props.supportedFileTypes}
thumbnailMode={thumbnailMode.current}
- addTags={props.addTags}
- addTag={props.addTag}
selectedEntries={selectedEntries}
selectEntry={selectEntry}
deselectEntry={deselectEntry}
- isReadOnlyMode={props.isReadOnlyMode}
handleTagMenu={handleTagMenu}
layoutType={layoutType.current}
showTags={showTags.current}
- openFsEntry={props.openFsEntry}
+ openFsEntry={openFsEntry}
handleGridContextMenu={(
event: React.MouseEvent<HTMLDivElement>,
fsEntry: TS.FileSystemEntry
@@ -786,17 +773,16 @@ function GridPerspective(props: Props) {
classes={classes}
prefixDataTID={'list'}
layoutType={layoutType.current}
- isReadOnlyMode={props.isReadOnlyMode}
selectedEntries={selectedEntries}
loadParentDirectoryContent={loadParentDirectoryContent}
toggleSelectAllFiles={toggleSelectAllFiles}
someFileSelected={someFileSelected}
handleLayoutSwitch={handleLayoutSwitch}
openAddRemoveTagsDialog={openAddRemoveTagsDialog}
- fileOperationsEnabled={fileOperationsEnabled(props.selectedEntries)}
+ fileOperationsEnabled={fileOperationsEnabled(selectedEntries)}
openMoveCopyFilesDialog={openMoveCopyFilesDialog}
openDeleteFileDialog={openDeleteFileDialog}
- openFsEntry={props.openFsEntry}
+ openFsEntry={openFsEntry}
handleSortingMenu={handleSortingMenu}
handleExportCsvMenu={handleExportCsvMenu}
openSettings={openSettings}
@@ -824,10 +810,10 @@ function GridPerspective(props: Props) {
showDetails={showDetails.current}
showDescription={showDescription.current}
showDirectories={showDirectories.current}
- isReadOnlyMode={props.isReadOnlyMode}
+ isReadOnlyMode={readOnlyMode}
layoutType={layoutType.current}
- desktopMode={props.desktopMode}
- openRenameEntryDialog={props.openRenameEntryDialog}
+ desktopMode={desktopMode}
+ openRenameEntryDialog={openRenameEntryDialog}
showTags={showTags.current}
thumbnailMode={thumbnailMode.current}
entrySize={entrySize.current}
@@ -835,27 +821,26 @@ function GridPerspective(props: Props) {
getCellContent={getCellContent}
currentPage={1}
currentLocationPath={locationPath}
- currentDirectoryPath={props.currentDirectoryPath}
+ currentDirectoryPath={currentDirectoryPath}
onClick={onClick}
onContextMenu={onContextMenu}
settings={settings}
- selectedEntries={props.selectedEntries}
- setSelectedEntries={props.setSelectedEntries}
+ selectedEntries={selectedEntries}
+ setSelectedEntries={handleSetSelectedEntries}
singleClickAction={singleClickAction.current}
- currentLocation={props.currentLocation}
+ currentLocation={currentLocation}
directoryContent={
- props.lastSearchTimestamp
+ lastSearchTimestamp
? GlobalSearch.getInstance().getResults()
- : props.directoryContent
+ : directoryContent
}
- supportedFileTypes={props.supportedFileTypes}
- openFsEntry={props.openFsEntry}
- openFileNatively={props.openFileNatively}
- loadDirectoryContent={props.loadDirectoryContent}
+ openFsEntry={openFsEntry}
+ openFileNatively={handleOpenFileNatively}
+ loadDirectoryContent={loadDirectoryContent}
setFileContextMenuAnchorEl={setFileContextMenuAnchorEl}
setDirContextMenuAnchorEl={setDirContextMenuAnchorEl}
- showNotification={props.showNotification}
- moveFiles={props.moveFiles}
+ showNotification={handleShowNotification}
+ moveFiles={handleMoveFiles}
clearSelection={clearSelection}
/>
</GlobalHotKeys>
@@ -863,17 +848,15 @@ function GridPerspective(props: Props) {
<AddRemoveTagsDialog
open={isAddRemoveTagsDialogOpened}
onClose={() => setIsAddRemoveTagsDialogOpened(false)}
- addTags={props.addTags}
- removeTags={props.removeTags}
- removeAllTags={props.removeAllTags}
- selectedEntries={props.selectedEntries}
+ removeTags={removeTags}
+ removeAllTags={removeAllTags}
+ selectedEntries={selectedEntries}
/>
)}
{isAddTagDialogOpened !== undefined && (
<AddTagToTagGroupDialog
open={true}
onClose={() => setIsAddTagDialogOpened(undefined)}
- addTag={props.addTag}
selectedTag={isAddTagDialogOpened}
/>
)}
@@ -912,7 +895,7 @@ function GridPerspective(props: Props) {
currentDirectoryPath,
PerspectiveIDs.LIST
).then((fsEntryMeta: TS.FileSystemEntryMeta) => {
- props.setDirectoryMeta(fsEntryMeta);
+ dispatch(AppActions.setDirectoryMeta(fsEntryMeta));
setIsGridSettingsDialogOpened(false);
});
}}
@@ -938,7 +921,7 @@ function GridPerspective(props: Props) {
open={Boolean(fileContextMenuAnchorEl)}
onClose={() => setFileContextMenuAnchorEl(null)}
openDeleteFileDialog={openDeleteFileDialog}
- openRenameFileDialog={props.openRenameEntryDialog}
+ openRenameFileDialog={openRenameEntryDialog}
openMoveCopyFilesDialog={openMoveCopyFilesDialog}
openShareFilesDialog={
PlatformIO.haveObjectStoreSupport()
@@ -946,16 +929,12 @@ function GridPerspective(props: Props) {
: undefined
}
openAddRemoveTagsDialog={openAddRemoveTagsDialog}
- openFsEntry={props.openFsEntry}
- openFileNatively={props.openFileNatively}
- loadDirectoryContent={props.loadDirectoryContent}
- showInFileManager={props.showInFileManager}
- showNotification={props.showNotification}
- isReadOnlyMode={props.isReadOnlyMode}
- selectedFilePath={props.lastSelectedEntryPath}
- selectedEntries={props.selectedEntries}
- currentLocation={props.currentLocation}
- locations={props.locations}
+ openFileNatively={handleOpenFileNatively}
+ loadDirectoryContent={loadDirectoryContent}
+ showInFileManager={showInFileManager}
+ selectedFilePath={lastSelectedEntryPath}
+ selectedEntries={selectedEntries}
+ currentLocation={currentLocation}
/>
)}
{/* {Boolean(dirContextMenuAnchorEl) && ( // todo move dialogs from DirectoryMenu */}
@@ -965,17 +944,14 @@ function GridPerspective(props: Props) {
anchorEl={dirContextMenuAnchorEl}
mouseX={mouseX}
mouseY={mouseY}
- directoryPath={props.lastSelectedEntryPath}
- loadDirectoryContent={props.loadDirectoryContent}
- openRenameDirectoryDialog={props.openRenameEntryDialog}
+ directoryPath={lastSelectedEntryPath}
+ loadDirectoryContent={loadDirectoryContent}
+ openRenameDirectoryDialog={openRenameEntryDialog}
openMoveCopyFilesDialog={openMoveCopyFilesDialog}
- openDirectory={props.openDirectory}
- openFsEntry={props.openFsEntry}
- perspectiveMode={
- props.lastSelectedEntryPath !== props.currentDirectoryPath
- }
- currentLocation={props.currentLocation}
- locations={props.locations}
+ openDirectory={openDirectory}
+ openFsEntry={openFsEntry}
+ perspectiveMode={lastSelectedEntryPath !== currentDirectoryPath}
+ currentLocation={currentLocation}
openAddRemoveTagsDialog={openAddRemoveTagsDialog}
/>
{/* {Boolean(tagContextMenuAnchorEl) && ( // TODO EntryTagMenu is used in TagSelect we cannot move confirm dialog from menu */}
@@ -986,8 +962,7 @@ function GridPerspective(props: Props) {
setIsAddTagDialogOpened={setIsAddTagDialogOpened}
selectedTag={selectedTag.current}
currentEntryPath={selectedEntryPath.current} // getSelEntryPath()}
- removeTags={props.removeTags}
- isReadOnlyMode={props.isReadOnlyMode}
+ removeTags={removeTags}
/>
{Boolean(sortingContextMenuAnchorEl) && (
<SortingMenu
@@ -997,7 +972,7 @@ function GridPerspective(props: Props) {
sortBy={sortBy.current}
orderBy={orderBy.current}
handleSortBy={handleSortBy}
- searchModeEnabled={props.lastSearchTimestamp !== undefined}
+ searchModeEnabled={lastSearchTimestamp !== undefined}
/>
)}
{Boolean(optionsContextMenuAnchorEl) && (
@@ -1023,48 +998,4 @@ function GridPerspective(props: Props) {
);
}
-function mapActionCreatorsToProps(dispatch) {
- return bindActionCreators(
- {
- moveFiles: IOActions.moveFiles,
- setSelectedEntries: AppActions.setSelectedEntries,
- showNotification: AppActions.showNotification,
- openFileNatively: AppActions.openFileNatively,
- openURLExternally: AppActions.openURLExternally,
- openNextFile: AppActions.openNextFile,
- openPrevFile: AppActions.openPrevFile,
- setDirectoryMeta: AppActions.setDirectoryMeta,
- toggleDeleteMultipleEntriesDialog:
- AppActions.toggleDeleteMultipleEntriesDialog,
- addTags: TaggingActions.addTags,
- addTag: AppActions.addTag
- },
- dispatch
- );
-}
-
-function mapStateToProps(state) {
- return {
- directoryMeta: getDirectoryMeta(state),
- supportedFileTypes: getSupportedFileTypes(state),
- isReadOnlyMode: isReadOnlyMode(state),
- lastSelectedEntry: getLastSelectedEntry(state),
- desktopMode: getDesktopMode(state),
- selectedEntries: getSelectedEntries(state),
- lastSelectedEntryPath: getLastSelectedEntryPath(state),
- keyBindings: getKeyBindingObject(state),
- currentLocation: getLocation(state, state.app.currentLocationId),
- locations: getLocations(state),
- isDeleteMultipleEntriesDialogOpened: isDeleteMultipleEntriesDialogOpened(
- state
- ),
- searchFilter: getSearchFilter(state),
- editedEntryPaths: getEditedEntryPaths(state)
- };
-}
-
-export default connect(
- mapStateToProps,
- mapActionCreatorsToProps
- // @ts-ignore
-)(withStyles(styles, { withTheme: true })(GridPerspective));
+export default withStyles(styles, { withTheme: true })(GridPerspective);
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index 2b2228076..7657f3efa 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -59,7 +59,8 @@ import {
updateFsEntries,
loadMetaDataPromise,
mergeByProp,
- toFsEntry
+ toFsEntry,
+ openURLExternally
} from '-/services/utils-io';
import { getUuid } from '@tagspaces/tagspaces-common/utils-io';
import i18n from '../services/i18n';
@@ -84,6 +85,12 @@ import { getProTeaserSlideIndex } from '-/content/ProTeaserSlides';
import GlobalSearch from '-/services/search-index';
import { extensionsFound } from '-/extension-config';
+import { ThunkDispatch } from 'redux-thunk';
+import { AnyAction } from 'redux';
+
+type State = {};
+export type AppDispatch = ThunkDispatch<State, any, AnyAction>;
+
export const types = {
DEVICE_ONLINE: 'APP/DEVICE_ONLINE',
DEVICE_OFFLINE: 'APP/DEVICE_OFFLINE',
@@ -1188,7 +1195,7 @@ export const actions = {
type: types.SET_NEW_VERSION_AVAILABLE,
isUpdateAvailable
}),
- setProgress: (path, progress, abort, filePath = undefined) => ({
+ setProgress: (path, progress, abort?, filePath = undefined) => ({
type: types.PROGRESS,
path,
filePath,
@@ -2005,7 +2012,7 @@ export const actions = {
* return Promise<currentLocationId> if location is changed or null if location and type is changed
*/
switchLocationType: (location: TS.Location) => (
- dispatch: (action) => void,
+ dispatch: (action) => string | null,
getState: () => any
): Promise<string | null> => {
const { currentLocationId } = getState().app;
@@ -2028,7 +2035,7 @@ export const actions = {
return Promise.resolve(null);
},
switchCurrentLocationType: (currentLocationId?: string) => (
- dispatch: (action) => void,
+ dispatch: (action) => boolean,
getState: () => any
): Promise<boolean> => {
// dispatch(actions.setCurrentLocationId(location.uuid));
@@ -2941,20 +2948,11 @@ export const actions = {
decodedURI.startsWith('https://') ||
decodedURI.startsWith('file://')
) {
- dispatch(actions.openURLExternally(decodedURI));
+ openURLExternally(decodedURI);
} else {
console.log('Not supported URL format: ' + decodedURI);
}
},
- openURLExternally: (url: string, skipConfirmation = false) => () => {
- if (skipConfirmation) {
- PlatformIO.openUrl(url);
- } else if (
- window.confirm('Do you really want to open this url: ' + url + ' ?')
- ) {
- PlatformIO.openUrl(url);
- }
- },
saveFile: () => (dispatch: (action) => void) => {
dispatch(
actions.showNotification(
diff --git a/app/reducers/io-actions.ts b/app/reducers/io-actions.ts
index 80d7a5827..b74b0f4c1 100644
--- a/app/reducers/io-actions.ts
+++ b/app/reducers/io-actions.ts
@@ -191,6 +191,7 @@ const actions = {
dispatch(
AppActions.showNotification(i18n.t('core:copyingFilesFailed'))
);
+ return false;
});
},
copyDirs: (
@@ -279,8 +280,8 @@ const actions = {
downloadFile: (
url: string,
targetPath: string,
- onDownloadProgress?: (progress: Progress, response: any) => void
- ) => (dispatch: (actions: Object) => void) => {
+ onDownloadProgress?: (progress: Progress, abort, fileName?) => void
+ ) => (dispatch: (actions: Object) => TS.FileSystemEntry) => {
function saveFile(response: Response): Promise<TS.FileSystemEntry> {
if (AppConfig.isElectron && !PlatformIO.haveObjectStoreSupport()) {
return PlatformIO.saveBinaryFilePromise(
@@ -343,9 +344,9 @@ const actions = {
uploadFilesAPI: (
files: Array<File>,
targetPath: string,
- onUploadProgress?: (progress: Progress, response: any) => void,
+ onUploadProgress?: (progress: Progress, abort, fileName?) => void,
uploadMeta = true
- ) => (dispatch: (actions: Object) => void) => {
+ ) => (dispatch: (actions: Object) => Promise<Array<TS.FileSystemEntry>>) => {
if (AppConfig.isElectron || AppConfig.isCordovaiOS) {
const arrFiles = [];
for (let i = 0; i < files.length; i += 1) {
diff --git a/app/reducers/locations.ts b/app/reducers/locations.ts
index f1107d051..79935248b 100644
--- a/app/reducers/locations.ts
+++ b/app/reducers/locations.ts
@@ -26,6 +26,12 @@ import PlatformIO from '-/services/platform-facade';
import { TS } from '-/tagspaces.namespace';
import { getUuid } from '@tagspaces/tagspaces-common/utils-io';
+/* import { ThunkDispatch } from 'redux-thunk';
+import { AnyAction } from 'redux';
+
+type State = Array<TS.Location>;
+export type LocationsDispatch = ThunkDispatch<State, any, AnyAction>;
+ */
export const types = {
ADD_LOCATION: 'APP/ADD_LOCATION',
MOVE_LOCATION: 'APP/MOVE_LOCATION',
@@ -253,9 +259,9 @@ export const actions = {
}
},
switchLocationType: (locationId: string) => (
- dispatch: (actions) => Promise<boolean>,
+ dispatch: (actions) => Promise<string | null>,
getState: () => any
- ): Promise<boolean> => {
+ ): Promise<string | null> => {
const { locations } = getState();
const location: TS.Location = locations.find(
location => location.uuid === locationId
diff --git a/app/reducers/settings-default.ts b/app/reducers/settings-default.ts
index a672ce88c..e3a35711e 100644
--- a/app/reducers/settings-default.ts
+++ b/app/reducers/settings-default.ts
@@ -34,7 +34,6 @@ if (window.ExtCheckForUpdatesOnStartup !== undefined) {
}
export default {
- settingsVersion: 3,
isLoading: false,
error: null,
userId: null,
diff --git a/app/reducers/settings.ts b/app/reducers/settings.ts
index 9906da0cb..41964ffa7 100644
--- a/app/reducers/settings.ts
+++ b/app/reducers/settings.ts
@@ -838,6 +838,7 @@ export const isDevMode = (state: any) =>
window.ExtDevMode ? window.ExtDevMode : state.settings.devMode;
export const isRevisionsEnabled = (state: any) =>
state.settings.isRevisionsEnabled;
+export const isReorderTags = (state: any) => state.settings.reorderTags;
export const getPrefixTagContainer = (state: any) =>
state.settings.prefixTagContainer;
export const getWarningOpeningFilesExternally = (state: any) =>
@@ -894,6 +895,8 @@ export const isGlobalKeyBindingEnabled = (state: any) =>
state.settings.enableGlobalKeyboardShortcuts;
export const getMainVerticalSplitSize = (state: any) =>
state.settings.mainVSplitSize;
+export const getTagGroupCollapsed = (state: any) =>
+ state.settings.tagGroupCollapsed;
export const getTagDelimiter = (state: any) => state.settings.tagDelimiter;
export const getMaxSearchResults = (state: any) =>
state.settings.maxSearchResult;
@@ -917,7 +920,7 @@ export const isFirstRun = (state: any) => {
};
function generateKeyBindingObject(keyBindings: Array<Object>) {
- const kbObject = {};
+ const kbObject: any = {};
keyBindings.map((kb: any) => {
kbObject[kb.name] = kb.command;
return true;
diff --git a/app/reducers/taglibrary.ts b/app/reducers/taglibrary.ts
index 0cc5d9a64..c64d313fc 100644
--- a/app/reducers/taglibrary.ts
+++ b/app/reducers/taglibrary.ts
@@ -722,7 +722,7 @@ export const actions = {
type: types.IMPORT_TAGGROUP,
entries,
replace
- }),
+ })
/**
* GraphQL API return TagGroup Tags array like String
* This migrate tagGroups model to children []
@@ -739,38 +739,6 @@ export const actions = {
dispatch(actions.importTagGroups(tagGroups, true));
}
}, */
- exportTagGroups: (entry: Array<TS.TagGroup>) => (
- dispatch: (actions: Object) => void,
- getState: () => any
- ) => {
- const { settings } = getState();
- const tagLibrary = entry;
- const jsonFormat =
- '{ "appName": "' +
- versionMeta.name +
- '", "appVersion": "' +
- versionMeta.version +
- '", "settingsVersion": ' +
- settings.settingsVersion +
- ', "tagGroups": ';
- const allTagGroups = [];
- tagLibrary.forEach(value => {
- const preparedTagGroup = prepareTagGroupForExport(value);
- if (preparedTagGroup.title && preparedTagGroup.uuid) {
- allTagGroups.push(preparedTagGroup);
- }
- });
-
- const blob = new Blob(
- [jsonFormat + JSON.stringify(allTagGroups, null, 2) + '}'],
- {
- type: 'application/json'
- }
- );
- const dateTimeTag = formatDateTime4Tag(new Date(), true);
- saveAsTextFile(blob, 'tag-library [tagspaces ' + dateTimeTag + '].json');
- console.log('Tag library exported...');
- }
};
// Selectors
diff --git a/app/services/electron-menus.ts b/app/services/electron-menus.ts
index c24a0fa17..309158f68 100644
--- a/app/services/electron-menus.ts
+++ b/app/services/electron-menus.ts
@@ -16,7 +16,7 @@
*
*/
-import { app, Menu } from 'electron';
+import { app, Menu, shell } from 'electron';
import Links from '-/content/links';
export default function buildDesktopMenu(props: any, i18n) {
@@ -216,18 +216,13 @@ export default function buildDesktopMenu(props: any, i18n) {
{
label: '&' + i18n.t('whatsNew'),
click: () => {
- props.openURLExternally({
- url: Links.links.changelogURL,
- skipConfirm: true
- });
+ shell.openExternal(Links.links.changelogURL);
}
},
{
label: '&' + i18n.t('followOnTwitter'),
click: () => {
- props.openURLExternally({
- url: Links.links.twitter
- });
+ shell.openExternal(Links.links.twitter);
}
},
{
@@ -236,17 +231,13 @@ export default function buildDesktopMenu(props: any, i18n) {
{
label: '&' + i18n.t('suggestNewFeatures'),
click: () => {
- props.openURLExternally({
- url: Links.links.suggestFeature
- });
+ shell.openExternal(Links.links.suggestFeature);
}
},
{
label: '&' + i18n.t('reportIssues'),
click: () => {
- props.openURLExternally({
- url: Links.links.reportIssue
- });
+ shell.openExternal(Links.links.reportIssue);
}
},
{
@@ -255,19 +246,13 @@ export default function buildDesktopMenu(props: any, i18n) {
{
label: i18n.t('webClipperChrome'),
click: () => {
- props.openURLExternally({
- url: Links.links.webClipperChrome,
- skipConfirm: true
- });
+ shell.openExternal(Links.links.webClipperChrome);
}
},
{
label: i18n.t('webClipperFirefox'),
click: () => {
- props.openURLExternally({
- url: Links.links.webClipperFirefox,
- skipConfirm: true
- });
+ shell.openExternal(Links.links.webClipperFirefox);
}
},
{
@@ -280,10 +265,7 @@ export default function buildDesktopMenu(props: any, i18n) {
{
label: i18n.t('cancelSubscription'),
click: () => {
- props.openURLExternally({
- url: Links.links.cancelSubscription,
- skipConfirm: true
- });
+ shell.openExternal(Links.links.cancelSubscription);
}
},
{
diff --git a/app/services/platform-facade.ts b/app/services/platform-facade.ts
index e316ffb76..bdd441cbe 100644
--- a/app/services/platform-facade.ts
+++ b/app/services/platform-facade.ts
@@ -569,7 +569,7 @@ export default class PlatformFacade {
return platformGetUserDataDir();
}
- static unZip(filePath, targetPath): Promise<boolean> {
+ static unZip(filePath, targetPath): Promise<string> {
return platformUnZip(filePath, targetPath);
}
diff --git a/app/services/taglibrary-utils.ts b/app/services/taglibrary-utils.ts
index 8375f5b4e..cdf85a159 100644
--- a/app/services/taglibrary-utils.ts
+++ b/app/services/taglibrary-utils.ts
@@ -201,7 +201,10 @@ export function importTagGroups(
return setTagLibrary(arr);
}
-export function exportTagGroups(entry: Array<TS.TagGroup>, settingsVersion) {
+export function exportTagGroups(
+ entry: Array<TS.TagGroup>,
+ settingsVersion = 3
+) {
const tagLibrary = entry;
const jsonFormat =
'{ "appName": "' +
diff --git a/app/services/utils-io.ts b/app/services/utils-io.ts
index 817e5dfcd..dccfeae21 100644
--- a/app/services/utils-io.ts
+++ b/app/services/utils-io.ts
@@ -1748,3 +1748,12 @@ export function getDefaultEditor(fileType) {
}
return undefined;
}
+export function openURLExternally(url: string, skipConfirmation = false) {
+ if (skipConfirmation) {
+ PlatformIO.openUrl(url);
+ } else if (
+ window.confirm('Do you really want to open this url: ' + url + ' ?')
+ ) {
+ PlatformIO.openUrl(url);
+ }
+}