Skip to content

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

TSN917 - Saved searches with text in Search input is not saved or performed (#1735)

Stanimirbb9cd184169d
diff --git a/app/components/FolderContainer.tsx b/app/components/FolderContainer.tsx
index f7557ac37..a7242f144 100644
--- a/app/components/FolderContainer.tsx
+++ b/app/components/FolderContainer.tsx
@@ -73,6 +73,7 @@ import Links from '-/links';
import { PerspectiveIDs, AvailablePerspectives } from '-/perspectives';
import MainSearchField from '-/components/MainSearchField';
import LoadingAnimation from '-/components/LoadingAnimation';
+import SearchBox from '-/components/SearchBox';
const GridPerspective = React.lazy(() =>
import(
@@ -561,43 +562,12 @@ function FolderContainer(props: Props) {
>
<MenuIcon />
</CustomButton>
- {isSearchVisible ? (
- <>
- <SearchInline />
- <Tooltip title={i18n.t('core:advancedSearch')}>
- <CustomButton
- id="advancedButton"
- data-tid="advancedSearch"
- onClick={(event: React.MouseEvent<HTMLButtonElement>) =>
- setAnchorSearch(event.currentTarget)
- }
- >
- <AdvancedSearchIcon />
- </CustomButton>
- </Tooltip>
- <Popover
- open={Boolean(anchorSearch)}
- anchorEl={anchorSearch}
- onClose={() => setAnchorSearch(null)}
- anchorOrigin={{
- vertical: 'bottom',
- horizontal: 'right'
- }}
- PaperProps={{
- style: {
- overflow: 'hidden',
- height: 720
- }
- }}
- transformOrigin={{
- vertical: 'top',
- horizontal: 'right'
- }}
- >
- <SearchPopover onClose={() => setAnchorSearch(null)} />
- </Popover>
- </>
- ) : (
+ <SearchBox
+ open={isSearchVisible}
+ anchorSearch={anchorSearch}
+ setAnchorSearch={setAnchorSearch}
+ />
+ {!isSearchVisible && (
<>
<div
style={{
diff --git a/app/components/SearchBox.tsx b/app/components/SearchBox.tsx
new file mode 100644
index 000000000..65494372a
--- /dev/null
+++ b/app/components/SearchBox.tsx
@@ -0,0 +1,123 @@
+/**
+ * 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, { useEffect, useRef, useState } from 'react';
+import { bindActionCreators } from 'redux';
+import { connect } from 'react-redux';
+import makeStyles from '@mui/styles/makeStyles';
+import ClearSearchIcon from '@mui/icons-material/Close';
+import HelpOutlineIcon from '@mui/icons-material/HelpOutline';
+import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
+import Button from '@mui/material/Button';
+import Tooltip from '@mui/material/Tooltip';
+import IconButton from '@mui/material/IconButton';
+import InputAdornment from '@mui/material/InputAdornment';
+import Typography from '@mui/material/Typography';
+import {
+ escapeRegExp,
+ parseTextQuery,
+ removeAllTagsFromSearchQuery
+} from '@tagspaces/tagspaces-platforms/misc';
+import { actions as AppActions, getDirectoryPath } from '../reducers/app';
+import {
+ actions as LocationIndexActions,
+ getIndexedEntriesCount,
+ isIndexing,
+ getSearchQuery
+} from '../reducers/location-index';
+import {
+ isDesktopMode,
+ getMaxSearchResults,
+ getShowUnixHiddenEntries,
+ getCurrentLanguage
+} from '-/reducers/settings';
+import i18n from '-/services/i18n';
+import { FileTypeGroups } from '-/services/search';
+import { TS } from '-/tagspaces.namespace';
+import { Pro } from '../pro';
+import useFirstRender from '-/utils/useFirstRender';
+import MainSearchField from '-/components/MainSearchField';
+import SavedSearchesMenu from '-/components/menus/SavedSearchesMenu';
+import SearchInline from '-/components/SearchInline';
+import AdvancedSearchIcon from '@mui/icons-material/FilterAlt';
+import Popover from '@mui/material/Popover';
+import SearchPopover from '-/components/SearchPopover';
+import SearchIcon from '@mui/icons-material/Search';
+import withStyles from '@mui/styles/withStyles';
+
+// type PropsClasses = Record<keyof StyleProps, string>;
+
+interface Props {
+ open: boolean;
+ setAnchorSearch: (HTMLButtonElement) => void;
+ anchorSearch: HTMLButtonElement | null;
+}
+
+const CustomButton: any = withStyles(theme => ({
+ root: {
+ // borderRadius: 15,
+ // minWidth: 45,
+ // height: 40
+ }
+}))(IconButton);
+
+function SearchBox(props: Props) {
+ return (
+ <>
+ <SearchInline open={props.open} />
+ {props.open && (
+ <>
+ <Tooltip title={i18n.t('core:advancedSearch')}>
+ <CustomButton
+ id="advancedButton"
+ data-tid="advancedSearch"
+ onClick={(event: React.MouseEvent<HTMLButtonElement>) =>
+ props.setAnchorSearch(event.currentTarget)
+ }
+ >
+ <AdvancedSearchIcon />
+ </CustomButton>
+ </Tooltip>
+ <Popover
+ open={Boolean(props.anchorSearch)}
+ anchorEl={props.anchorSearch}
+ onClose={() => props.setAnchorSearch(null)}
+ anchorOrigin={{
+ vertical: 'bottom',
+ horizontal: 'right'
+ }}
+ PaperProps={{
+ style: {
+ overflow: 'hidden',
+ height: 720
+ }
+ }}
+ transformOrigin={{
+ vertical: 'top',
+ horizontal: 'right'
+ }}
+ >
+ <SearchPopover onClose={() => props.setAnchorSearch(null)} />
+ </Popover>
+ </>
+ )}
+ </>
+ );
+}
+
+export default SearchBox;
diff --git a/app/components/SearchInline.tsx b/app/components/SearchInline.tsx
index a02310efb..82dd22167 100644
--- a/app/components/SearchInline.tsx
+++ b/app/components/SearchInline.tsx
@@ -72,6 +72,7 @@ interface Props {
indexing: boolean;
showUnixHiddenEntries: boolean;
isDesktop: boolean;
+ open: boolean;
}
const useStyles = makeStyles(theme => ({
@@ -89,7 +90,7 @@ function SearchInline(props: Props) {
openSavedSearches,
setOpenSavedSearches
] = useState<null | HTMLElement>(null);
- const textQuery = useRef<string>(props.searchQuery.textQuery);
+ const textQuery = useRef<string>(props.searchQuery.textQuery || '');
const textQueryMask = useRef<string>('');
const fileTypes = useRef<Array<string>>(
props.searchQuery.fileTypes
@@ -135,10 +136,15 @@ function SearchInline(props: Props) {
const firstRender = useFirstRender();
useEffect(() => {
- if (!firstRender) {
+ /*if (!firstRender) {
if (Object.keys(props.searchQuery).length > 0) {
props.setSearchQuery({});
}
+ }*/
+ if (!firstRender && !props.open) {
+ if (Object.keys(props.searchQuery).length > 0) {
+ clearSearch();
+ }
}
}, [props.currentDirectory]);
@@ -172,7 +178,8 @@ function SearchInline(props: Props) {
});
emptySearch = false;
}
- const txtQuery = removeAllTagsFromSearchQuery(textQuery.current);
+ let txtQuery = textQuery.current.trim() || props.searchQuery.textQuery;
+ txtQuery = removeAllTagsFromSearchQuery(txtQuery);
if (txtQuery) {
emptySearch = false;
}
@@ -259,6 +266,7 @@ function SearchInline(props: Props) {
executeSearch();
} else if (event.key === 'Escape' || event.keyCode === 27) {
clearSearch();
+ props.openCurrentDirectory();
}
};
@@ -278,7 +286,7 @@ function SearchInline(props: Props) {
forceIndexing.current = false;
fileSize.current = '';
props.setSearchQuery({});
- props.openCurrentDirectory();
+ // props.openCurrentDirectory();
};
const removeTagsFromQuery = (
@@ -387,8 +395,11 @@ function SearchInline(props: Props) {
props.setSearchQuery(searchQuery);
};
- const { indexing, isDesktop } = props;
+ const { indexing, isDesktop, open } = props;
+ if (!open) {
+ return null;
+ }
return (
<>
<div
@@ -479,7 +490,10 @@ function SearchInline(props: Props) {
<Tooltip title={i18n.t('clearSearch') + ' (ESC)'}>
<IconButton
id="clearSearchID"
- onClick={clearSearch}
+ onClick={()=>{
+ clearSearch();
+ props.openCurrentDirectory();
+ }}
size="small"
edge="end"
>
@@ -546,6 +560,7 @@ function mapDispatchToProps(dispatch) {
}
const areEqual = (prevProp, nextProp) =>
+ nextProp.open === prevProp.open &&
nextProp.language === prevProp.language &&
nextProp.indexing === prevProp.indexing &&
nextProp.searchQuery === prevProp.searchQuery &&