Skip to content

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

back button fix (#1527)

Stanimir4b4042e85556
diff --git a/app/components/SearchPopover.tsx b/app/components/SearchPopover.tsx
index 4556b101b..c1c14c9b0 100644
--- a/app/components/SearchPopover.tsx
+++ b/app/components/SearchPopover.tsx
@@ -74,6 +74,8 @@ import AppConfig from '-/config';
import { actions as SearchActions, getSearches } from '-/reducers/searches';
import { TS } from '-/tagspaces.namespace';
import { ProLabel, BetaLabel, ProTooltip } from '-/components/HelperComponents';
+import HelpIcon from '@material-ui/icons/Help';
+import Links from '-/links';
const SaveSearchDialog = Pro && Pro.UI ? Pro.UI.SaveSearchDialog : false;
@@ -83,10 +85,10 @@ interface Props {
style?: any;
theme?: any;
searchLocationIndex: (searchQuery: TS.SearchQuery) => void;
- createLocationsIndexes: () => void;
+ // createLocationsIndexes: () => void;
searchAllLocations: (searchQuery: TS.SearchQuery) => void;
loadDirectoryContent: (path: string, generateThumbnails: boolean) => void;
- openURLExternally: (url: string) => void;
+ openURLExternally: (url: string, skipConfirmation?: boolean) => void;
hideDrawer?: () => void;
searchQuery: TS.SearchQuery; // () => any;
setSearchResults: (entries: Array<any>) => void;
@@ -96,7 +98,6 @@ interface Props {
maxSearchResults: number;
indexing: boolean;
searches: Array<TS.SearchQuery>;
- addSearches: (searches: Array<TS.SearchQuery>) => void;
showUnixHiddenEntries: boolean;
// openSearchPanel: () => void;
onClose: () => void;
@@ -148,24 +149,6 @@ const SearchPopover = (props: Props) => {
const fileSize = useRef<string>(
props.searchQuery.fileSize ? props.searchQuery.fileSize : ''
);
- const [
- searchMenuAnchorEl,
- setSearchMenuAnchorEl
- ] = useState<null | HTMLElement>(null);
-
- const [
- isExportSearchesDialogOpened,
- setExportSearchesDialogOpened
- ] = useState<boolean>(false);
-
- const ExportSearchesDialog =
- Pro && Pro.UI ? Pro.UI.ExportSearchesDialog : false;
-
- const fileInputRef = useRef<HTMLInputElement>(null);
- const [importFile, setImportFile] = useState<File>(undefined);
-
- const ImportSearchesDialog =
- Pro && Pro.UI ? Pro.UI.ImportSearchesDialog : false;
useEffect(() => {
textQuery.current = props.searchQuery.textQuery;
@@ -195,13 +178,6 @@ const SearchPopover = (props: Props) => {
}*/
}, [props.searchQuery]);
- function handleFileInputChange(selection: any) {
- const target = selection.currentTarget;
- const file = target.files[0];
- setImportFile(file);
- target.value = null;
- }
-
const handleFileTypeChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const { target } = event;
const { value, name } = target;
@@ -620,14 +596,6 @@ const SearchPopover = (props: Props) => {
props.onClose();
};
- const handleSearchMenu = (event: any) => {
- setSearchMenuAnchorEl(event.currentTarget);
- };
-
- const handleCloseSearchMenu = () => {
- setSearchMenuAnchorEl(null);
- };
-
const { indexing, indexedEntriesCount } = props;
const indexStatus = indexedEntriesCount
@@ -638,11 +606,13 @@ const SearchPopover = (props: Props) => {
<div className={classes.toolbar}>
<Button
size="medium"
- data-tid="searchMenu"
- startIcon={<MoreVertIcon />}
- onClick={handleSearchMenu}
+ data-tid="helpSearchTID"
+ startIcon={<HelpIcon />}
+ onClick={() =>
+ props.openURLExternally(Links.documentationLinks.search, true)
+ }
>
- {i18n.t('searchTitle')}
+ {i18n.t('core:help')}
</Button>
<Typography
variant="caption"
@@ -659,19 +629,6 @@ const SearchPopover = (props: Props) => {
<CloseIcon />
</IconButton>
</div>
- <SearchMenu
- anchorEl={searchMenuAnchorEl}
- open={Boolean(searchMenuAnchorEl)}
- onClose={handleCloseSearchMenu}
- createLocationsIndexes={props.createLocationsIndexes}
- openURLExternally={props.openURLExternally}
- exportSearches={() => {
- setExportSearchesDialogOpened(true);
- }}
- importSearches={() => {
- fileInputRef.current.click();
- }}
- />
<div className={classes.searchArea}>
<FormControl className={classes.formControl} disabled={indexing}>
<ToggleButtonGroup
@@ -1133,29 +1090,6 @@ const SearchPopover = (props: Props) => {
searchQuery={saveSearchDialogOpened}
/>
)}
- <input
- style={{ display: 'none' }}
- ref={fileInputRef}
- accept="*"
- type="file"
- onChange={handleFileInputChange}
- />
- {ExportSearchesDialog && isExportSearchesDialogOpened && (
- <ExportSearchesDialog
- open={isExportSearchesDialogOpened}
- onClose={() => setExportSearchesDialogOpened(false)}
- searches={props.searches}
- />
- )}
- {ImportSearchesDialog && importFile && (
- <ImportSearchesDialog
- open={Boolean(importFile)}
- onClose={() => setImportFile(undefined)}
- importFile={importFile}
- addSearches={props.addSearches}
- searches={props.searches}
- />
- )}
</>
)}
</div>
@@ -1184,9 +1118,7 @@ function mapDispatchToProps(dispatch) {
createLocationsIndexes: LocationIndexActions.createLocationsIndexes,
loadDirectoryContent: AppActions.loadDirectoryContent,
openURLExternally: AppActions.openURLExternally,
- setSearchResults: AppActions.setSearchResults,
- addSearches: SearchActions.addSearches
- // openSearchPanel: AppActions.openSearchPanel
+ setSearchResults: AppActions.setSearchResults
},
dispatch
);
diff --git a/app/components/StoredSearches.tsx b/app/components/StoredSearches.tsx
index 119f116ef..0b00c6b81 100644
--- a/app/components/StoredSearches.tsx
+++ b/app/components/StoredSearches.tsx
@@ -16,7 +16,7 @@
*
*/
-import React, { useState } from 'react';
+import React, { useRef, useState } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import IconButton from '@material-ui/core/IconButton';
@@ -37,6 +37,8 @@ import i18n from '../services/i18n';
import { Pro } from '../pro';
import { actions as SearchActions, getSearches } from '-/reducers/searches';
import { TS } from '-/tagspaces.namespace';
+import SearchMenu from '-/components/menus/SearchMenu';
+import { actions as AppActions } from '-/reducers/app';
interface Props {
style?: any;
@@ -45,6 +47,8 @@ interface Props {
searchLocationIndex: (searchQuery: TS.SearchQuery) => void;
searchAllLocations: (searchQuery: TS.SearchQuery) => void;
showUnixHiddenEntries: boolean;
+ addSearches: (searches: Array<TS.SearchQuery>) => void;
+ openURLExternally: (url: string) => void;
}
const SaveSearchDialog = Pro && Pro.UI ? Pro.UI.SaveSearchDialog : false;
@@ -56,6 +60,31 @@ const StoredSearches = (props: Props) => {
const [storedSearchesVisible, setStoredSearchesVisible] = useState<boolean>(
true
);
+ const [
+ searchMenuAnchorEl,
+ setSearchMenuAnchorEl
+ ] = useState<null | HTMLElement>(null);
+
+ const [
+ isExportSearchesDialogOpened,
+ setExportSearchesDialogOpened
+ ] = useState<boolean>(false);
+
+ const [importFile, setImportFile] = useState<File>(undefined);
+ const fileInputRef = useRef<HTMLInputElement>(null);
+
+ const ExportSearchesDialog =
+ Pro && Pro.UI ? Pro.UI.ExportSearchesDialog : false;
+ const ImportSearchesDialog =
+ Pro && Pro.UI ? Pro.UI.ImportSearchesDialog : false;
+
+ const handleSearchMenu = (event: any) => {
+ setSearchMenuAnchorEl(event.currentTarget);
+ };
+
+ const handleCloseSearchMenu = () => {
+ setSearchMenuAnchorEl(null);
+ };
const editSearch = (uuid: string) => {
const savedSearch = props.searches.find(search => search.uuid === uuid);
@@ -84,6 +113,13 @@ const StoredSearches = (props: Props) => {
}
};
+ function handleFileInputChange(selection: any) {
+ const target = selection.currentTarget;
+ const file = target.files[0];
+ setImportFile(file);
+ target.value = null;
+ }
+
const preventDefault = (event: React.SyntheticEvent) =>
event.preventDefault();
@@ -110,7 +146,22 @@ const StoredSearches = (props: Props) => {
</Typography>
</Grid>
<Grid item xs={2} style={{ alignSelf: 'center' }}>
- <IconButton style={{ minWidth: 'auto', padding: 7 }}>
+ <SearchMenu
+ anchorEl={searchMenuAnchorEl}
+ open={Boolean(searchMenuAnchorEl)}
+ onClose={handleCloseSearchMenu}
+ openURLExternally={props.openURLExternally}
+ exportSearches={() => {
+ setExportSearchesDialogOpened(true);
+ }}
+ importSearches={() => {
+ fileInputRef.current.click();
+ }}
+ />
+ <IconButton
+ style={{ minWidth: 'auto', padding: 7 }}
+ onClick={handleSearchMenu}
+ >
<MenuIcon />
</IconButton>
</Grid>
@@ -177,6 +228,29 @@ const StoredSearches = (props: Props) => {
searchQuery={saveSearchDialogOpened}
/>
)}
+ <input
+ style={{ display: 'none' }}
+ ref={fileInputRef}
+ accept="*"
+ type="file"
+ onChange={handleFileInputChange}
+ />
+ {ExportSearchesDialog && isExportSearchesDialogOpened && (
+ <ExportSearchesDialog
+ open={isExportSearchesDialogOpened}
+ onClose={() => setExportSearchesDialogOpened(false)}
+ searches={props.searches}
+ />
+ )}
+ {ImportSearchesDialog && importFile && (
+ <ImportSearchesDialog
+ open={Boolean(importFile)}
+ onClose={() => setImportFile(undefined)}
+ importFile={importFile}
+ addSearches={props.addSearches}
+ searches={props.searches}
+ />
+ )}
</>
);
};
@@ -194,7 +268,8 @@ function mapDispatchToProps(dispatch) {
{
addSearches: SearchActions.addSearches,
searchAllLocations: LocationIndexActions.searchAllLocations,
- searchLocationIndex: LocationIndexActions.searchLocationIndex
+ searchLocationIndex: LocationIndexActions.searchLocationIndex,
+ openURLExternally: AppActions.openURLExternally
},
dispatch
);
diff --git a/app/components/menus/LocationManagerMenu.tsx b/app/components/menus/LocationManagerMenu.tsx
index 23b3ce5a7..535b5d604 100644
--- a/app/components/menus/LocationManagerMenu.tsx
+++ b/app/components/menus/LocationManagerMenu.tsx
@@ -26,6 +26,7 @@ import ExportImportIcon from '@material-ui/icons/SwapHoriz';
import OpenLinkIcon from '@material-ui/icons/Link';
import HelpIcon from '@material-ui/icons/Help';
import CloseIcon from '@material-ui/icons/Close';
+import UpdateIndexIcon from '@material-ui/icons/Update';
import classNames from 'classnames';
import Typography from '@material-ui/core/Typography';
import IconButton from '@material-ui/core/IconButton';
@@ -38,6 +39,7 @@ import { Pro } from '../../pro';
import { actions as AppActions } from '-/reducers/app';
import Links from '-/links';
import { ProLabel } from '-/components/HelperComponents';
+import { actions as LocationIndexActions } from '-/reducers/location-index';
interface Props {
classes: any;
@@ -47,6 +49,7 @@ interface Props {
toggleOpenLinkDialog: () => void;
closeAllLocations: () => void;
openURLExternally: (url: string, skipConfirmation?: boolean) => void;
+ createLocationsIndexes: () => void;
}
const LocationManagerMenu = (props: Props) => {
@@ -56,6 +59,22 @@ const LocationManagerMenu = (props: Props) => {
] = useState<null | HTMLElement>(null);
const menuItems = [];
+ menuItems.push(
+ <MenuItem
+ key="updateAllLocationIndexes"
+ data-tid="updateAllLocationIndexes"
+ onClick={() => {
+ setLocationManagerMenuAnchorEl(null);
+ props.createLocationsIndexes();
+ }}
+ >
+ <ListItemIcon>
+ <UpdateIndexIcon />
+ </ListItemIcon>
+ <ListItemText primary={i18n.t('core:updateAllLocationIndexes')} />
+ </MenuItem>
+ );
+
if (!AppConfig.locationsReadOnly) {
menuItems.push(
<MenuItem
@@ -204,7 +223,8 @@ const LocationManagerMenu = (props: Props) => {
function mapDispatchToProps(dispatch) {
return bindActionCreators(
{
- closeAllLocations: AppActions.closeAllLocations
+ closeAllLocations: AppActions.closeAllLocations,
+ createLocationsIndexes: LocationIndexActions.createLocationsIndexes
},
dispatch
);
diff --git a/app/components/menus/SearchMenu.tsx b/app/components/menus/SearchMenu.tsx
index 413fd44c7..14b281e6e 100644
--- a/app/components/menus/SearchMenu.tsx
+++ b/app/components/menus/SearchMenu.tsx
@@ -22,7 +22,6 @@ import ListItemIcon from '@material-ui/core/ListItemIcon';
import Menu from '@material-ui/core/Menu';
import MenuItem from '@material-ui/core/MenuItem';
import HelpIcon from '@material-ui/icons/Help';
-import UpdateIndexIcon from '@material-ui/icons/Update';
import ExportImportIcon from '@material-ui/icons/SwapHoriz';
import i18n from '-/services/i18n';
import { Pro } from '../../pro';
@@ -37,26 +36,10 @@ interface Props {
openURLExternally: (url: string, skipConfirmation?: boolean) => void;
importSearches: () => void;
exportSearches: () => void;
- createLocationsIndexes: () => void;
}
const SearchMenu = (props: Props) => {
const menuItems = [];
- menuItems.push(
- <MenuItem
- key="updateAllLocationIndexes"
- data-tid="updateAllLocationIndexes"
- onClick={() => {
- props.onClose();
- props.createLocationsIndexes();
- }}
- >
- <ListItemIcon>
- <UpdateIndexIcon />
- </ListItemIcon>
- <ListItemText primary={i18n.t('core:updateAllLocationIndexes')} />
- </MenuItem>
- );
menuItems.push(
<MenuItem
disabled={!Pro}
diff --git a/app/perspectives/grid-perspective/components/MainContainer.tsx b/app/perspectives/grid-perspective/components/MainContainer.tsx
index ad37a87f4..cc85e8fc2 100644
--- a/app/perspectives/grid-perspective/components/MainContainer.tsx
+++ b/app/perspectives/grid-perspective/components/MainContainer.tsx
@@ -744,7 +744,6 @@ const GridPerspective = (props: Props) => {
openDeleteFileDialog={openDeleteFileDialog}
handleSortingMenu={handleSortingMenu}
handleExportCsvMenu={handleExportCsvMenu}
- isDesktopMode={props.isDesktopMode}
openSettings={openSettings}
/>
<GlobalHotKeys
diff --git a/app/perspectives/grid-perspective/components/MainToolbar.tsx b/app/perspectives/grid-perspective/components/MainToolbar.tsx
index 53e156d63..fe2416259 100644
--- a/app/perspectives/grid-perspective/components/MainToolbar.tsx
+++ b/app/perspectives/grid-perspective/components/MainToolbar.tsx
@@ -31,9 +31,17 @@ import DeSelectAllIcon from '@material-ui/icons/CheckBoxOutlineBlank';
import CopyIcon from '@material-ui/icons/FileCopy';
import DeleteIcon from '@material-ui/icons/Delete';
import ExportIcon from '@material-ui/icons/AssignmentReturn';
+import { connect } from 'react-redux';
+import { bindActionCreators } from 'redux';
import i18n from '-/services/i18n';
import { Pro } from '-/pro';
import AppConfig from '-/config';
+import {
+ actions as LocationIndexActions,
+ getSearchQuery
+} from '-/reducers/location-index';
+import { TS } from '-/tagspaces.namespace';
+import { actions as AppActions } from '-/reducers/app';
interface Props {
classes: any;
@@ -50,8 +58,10 @@ interface Props {
handleSortingMenu: (event: Object) => void;
handleExportCsvMenu: () => void;
layoutType: string;
- isDesktopMode: boolean;
openSettings: () => void;
+ searchQuery: TS.SearchQuery;
+ setSearchQuery: (searchQuery: TS.SearchQuery) => void;
+ openCurrentDirectory: () => void;
}
const MainToolbar = (props: Props) => {
@@ -69,7 +79,6 @@ const MainToolbar = (props: Props) => {
openDeleteFileDialog,
fileOperationsEnabled,
handleSortingMenu,
- isDesktopMode,
openSettings
} = props;
@@ -87,7 +96,17 @@ const MainToolbar = (props: Props) => {
<IconButton
aria-label={i18n.t('core:navigateToParentDirectory')}
data-tid="gridPerspectiveOnBackButton"
- onClick={loadParentDirectoryContent}
+ onClick={() => {
+ if (
+ props.searchQuery &&
+ Object.keys(props.searchQuery).length > 0
+ ) {
+ props.setSearchQuery({});
+ props.openCurrentDirectory();
+ } else {
+ loadParentDirectoryContent();
+ }
+ }}
>
<ParentDirIcon />
</IconButton>
@@ -195,4 +214,19 @@ const MainToolbar = (props: Props) => {
);
};
-export default MainToolbar;
+function mapStateToProps(state) {
+ return {
+ searchQuery: getSearchQuery(state)
+ };
+}
+function mapDispatchToProps(dispatch) {
+ return bindActionCreators(
+ {
+ setSearchQuery: LocationIndexActions.setSearchQuery,
+ openCurrentDirectory: AppActions.openCurrentDirectory
+ },
+ dispatch
+ );
+}
+
+export default connect(mapStateToProps, mapDispatchToProps)(MainToolbar);