Skip to content

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

fix: StoredSearches and showFilesWithThisTag (#1531)

Stanimirae6196a6eb02
diff --git a/app/components/SearchInline.tsx b/app/components/SearchInline.tsx
index ec355d5cc..959b6aece 100644
--- a/app/components/SearchInline.tsx
+++ b/app/components/SearchInline.tsx
@@ -16,7 +16,7 @@
*
*/
-import React, { useEffect, useReducer, useRef, useState } from 'react';
+import React, { useEffect, useRef, useState } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { withStyles, Theme, createStyles } from '@material-ui/core/styles';
@@ -45,6 +45,7 @@ import {
parseTextQuery,
removeAllTagsFromQuery
} from '-/utils/misc';
+import useFirstRender from '-/utils/useFirstRender';
// type PropsClasses = Record<keyof StyleProps, string>;
@@ -146,6 +147,8 @@ const SearchInline = (props: Props) => {
const mainSearchField = useRef<HTMLInputElement>(null);
+ const firstRender = useFirstRender();
+
/* useEffect(() => {
// https://github.com/mui-org/material-ui/issues/1594
const timeout = setTimeout(() => {
@@ -160,32 +163,41 @@ const SearchInline = (props: Props) => {
}, []); */
useEffect(() => {
- // mainSearchField.current.value = '';
- if (Object.keys(props.searchQuery).length > 0) {
- props.setSearchQuery({});
+ if (!firstRender) {
+ // mainSearchField.current.value = '';
+ if (Object.keys(props.searchQuery).length > 0) {
+ props.setSearchQuery({});
+ }
}
}, [props.currentDirectory]);
useEffect(() => {
if (Object.keys(props.searchQuery).length > 0) {
+ let emptySearch: boolean = true;
textQueryMask.current = '';
if (props.searchQuery.tagsAND && props.searchQuery.tagsAND.length > 0) {
props.searchQuery.tagsAND.forEach(tag => {
textQueryMask.current += ' +' + tag.title;
});
+ emptySearch = false;
}
if (props.searchQuery.tagsOR && props.searchQuery.tagsOR.length > 0) {
props.searchQuery.tagsOR.forEach(tag => {
textQueryMask.current += ' ?' + tag.title;
});
+ emptySearch = false;
}
if (props.searchQuery.tagsNOT && props.searchQuery.tagsNOT.length > 0) {
props.searchQuery.tagsNOT.forEach(tag => {
textQueryMask.current += ' -' + tag.title;
});
+ emptySearch = false;
}
const txtQuery = removeAllTagsFromQuery(textQuery.current);
+ if (txtQuery) {
+ emptySearch = false;
+ }
/* if (textQueryMask.current) {
txtQuery = textQuery.current.replace(textQueryMask.current, '').trim();
} else if (textQuery.current) {
@@ -212,32 +224,41 @@ const SearchInline = (props: Props) => {
// }
if (props.searchQuery.searchBoxing) {
searchBoxing.current = props.searchQuery.searchBoxing;
+ emptySearch = false;
}
if (props.searchQuery.fileTypes) {
fileTypes.current = props.searchQuery.fileTypes;
+ emptySearch = false;
}
if (props.searchQuery.searchType) {
searchType.current = props.searchQuery.searchType;
+ emptySearch = false;
}
if (props.searchQuery.lastModified) {
lastModified.current = props.searchQuery.lastModified;
+ emptySearch = false;
}
if (props.searchQuery.tagTimePeriodFrom) {
tagTimePeriodFrom.current = props.searchQuery.tagTimePeriodFrom;
+ emptySearch = false;
}
if (props.searchQuery.tagTimePeriodTo) {
tagTimePeriodTo.current = props.searchQuery.tagTimePeriodTo;
+ emptySearch = false;
}
if (props.searchQuery.forceIndexing) {
forceIndexing.current = props.searchQuery.forceIndexing;
}
if (props.searchQuery.fileSize) {
fileSize.current = props.searchQuery.fileSize;
+ emptySearch = false;
}
- if (searchBoxing.current === 'global') {
- props.searchAllLocations(searchQuery);
- } else {
- props.searchLocationIndex(searchQuery);
+ if (!emptySearch) {
+ if (searchBoxing.current === 'global') {
+ props.searchAllLocations(searchQuery);
+ } else {
+ props.searchLocationIndex(searchQuery);
+ }
}
}
}, [props.searchQuery]);
diff --git a/app/components/StoredSearches.tsx b/app/components/StoredSearches.tsx
index 4003a77c8..3b417f44a 100644
--- a/app/components/StoredSearches.tsx
+++ b/app/components/StoredSearches.tsx
@@ -28,10 +28,7 @@ import SearchIcon from '@material-ui/icons/Search';
import ArrowDownIcon from '@material-ui/icons/KeyboardArrowDown';
import ArrowRightIcon from '@material-ui/icons/KeyboardArrowRight';
import Typography from '@material-ui/core/Typography';
-import {
- actions as LocationIndexActions,
- getSearchQuery
-} from '../reducers/location-index';
+import { actions as LocationIndexActions, getSearchQuery } from '-/reducers/location-index';
import { getShowUnixHiddenEntries } from '-/reducers/settings';
import i18n from '../services/i18n';
import { Pro } from '../pro';
@@ -44,9 +41,10 @@ import AppConfig from '-/config';
interface Props {
style?: any;
searchQuery: TS.SearchQuery;
+ setSearchQuery: (searchQuery: TS.SearchQuery) => void;
searches: Array<TS.SearchQuery>;
- searchLocationIndex: (searchQuery: TS.SearchQuery) => void;
- searchAllLocations: (searchQuery: TS.SearchQuery) => void;
+ // searchLocationIndex: (searchQuery: TS.SearchQuery) => void;
+ // searchAllLocations: (searchQuery: TS.SearchQuery) => void;
showUnixHiddenEntries: boolean;
addSearches: (searches: Array<TS.SearchQuery>) => void;
openURLExternally: (url: string) => void;
@@ -102,7 +100,12 @@ const StoredSearches = (props: Props) => {
return true;
}
- if (savedSearch.searchBoxing === 'global') {
+ props.setSearchQuery({
+ ...savedSearch,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ });
+
+ /* if (savedSearch.searchBoxing === 'global') {
props.searchAllLocations({
...savedSearch,
showUnixHiddenEntries: props.showUnixHiddenEntries
@@ -112,7 +115,7 @@ const StoredSearches = (props: Props) => {
...savedSearch,
showUnixHiddenEntries: props.showUnixHiddenEntries
});
- }
+ } */
};
function handleFileInputChange(selection: any) {
@@ -224,7 +227,12 @@ const StoredSearches = (props: Props) => {
onClose={(searchQuery: TS.SearchQuery) => {
setSaveSearchDialogOpened(undefined);
if (searchQuery) {
- if (searchQuery.searchBoxing === 'global') {
+ props.setSearchQuery({
+ ...searchQuery,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ });
+
+ /* if (searchQuery.searchBoxing === 'global') {
props.searchAllLocations({
...searchQuery,
showUnixHiddenEntries: props.showUnixHiddenEntries
@@ -234,7 +242,7 @@ const StoredSearches = (props: Props) => {
...searchQuery,
showUnixHiddenEntries: props.showUnixHiddenEntries
});
- }
+ } */
}
}}
onClearSearch={() => console.log('search deleted')}
@@ -280,8 +288,9 @@ function mapDispatchToProps(dispatch) {
return bindActionCreators(
{
addSearches: SearchActions.addSearches,
- searchAllLocations: LocationIndexActions.searchAllLocations,
- searchLocationIndex: LocationIndexActions.searchLocationIndex,
+ setSearchQuery: LocationIndexActions.setSearchQuery,
+ // searchAllLocations: LocationIndexActions.searchAllLocations,
+ // searchLocationIndex: LocationIndexActions.searchLocationIndex,
openURLExternally: AppActions.openURLExternally
},
dispatch
diff --git a/app/components/menus/EntryTagMenu.tsx b/app/components/menus/EntryTagMenu.tsx
index 6431a30da..888a548bd 100644
--- a/app/components/menus/EntryTagMenu.tsx
+++ b/app/components/menus/EntryTagMenu.tsx
@@ -33,7 +33,6 @@ import { actions as LocationIndexActions } from '-/reducers/location-index';
import { getMaxSearchResults } from '-/reducers/settings';
import { actions as AppActions } from '-/reducers/app';
import { TS } from '-/tagspaces.namespace';
-import OpenFolderIcon from '@material-ui/icons/SubdirectoryArrowLeft';
interface Props {
open: boolean;
@@ -42,9 +41,8 @@ interface Props {
selectedTag: TS.Tag | null;
currentEntryPath: string;
removeTags: (paths: Array<string>, tags: Array<TS.Tag>) => void;
- searchLocationIndex?: (searchQuery: TS.SearchQuery) => void;
+ setSearchQuery: (searchQuery: TS.SearchQuery) => void;
maxSearchResults?: number;
- // openSearchPanel?: () => void;
setIsAddTagDialogOpened?: (tag: TS.Tag) => void;
toggleEditTagDialog?: (tag: TS.Tag) => void;
isReadOnlyMode?: boolean;
@@ -73,8 +71,7 @@ const EntryTagMenu = (props: Props) => {
function showFilesWithThisTag() {
if (props.selectedTag) {
- // props.openSearchPanel();
- props.searchLocationIndex({
+ props.setSearchQuery({
tagsAND: [props.selectedTag],
maxSearchResults: props.maxSearchResults
});
@@ -176,8 +173,7 @@ function mapStateToProps(state) {
function mapDispatchToProps(dispatch) {
return bindActionCreators(
{
- searchLocationIndex: LocationIndexActions.searchLocationIndex,
- // openSearchPanel: AppActions.openSearchPanel,
+ setSearchQuery: LocationIndexActions.setSearchQuery,
toggleEditTagDialog: AppActions.toggleEditTagDialog
},
dispatch
diff --git a/app/components/menus/TagGroupMenu.tsx b/app/components/menus/TagGroupMenu.tsx
index 276b8129a..51b8fca11 100644
--- a/app/components/menus/TagGroupMenu.tsx
+++ b/app/components/menus/TagGroupMenu.tsx
@@ -33,13 +33,12 @@ import MenuItem from '@material-ui/core/MenuItem';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import i18n from '-/services/i18n';
-import { Pro } from '-/pro';
import { getMaxSearchResults } from '-/reducers/settings';
-import { actions as AppActions } from '-/reducers/app';
import { actions as LocationIndexActions } from '-/reducers/location-index';
import { TS } from '-/tagspaces.namespace';
import InfoIcon from '-/components/InfoIcon';
import { ProLabel } from '-/components/HelperComponents';
+
interface Props {
classes?: any;
anchorEl: Element;
@@ -54,8 +53,7 @@ interface Props {
sortTagGroup: (tagGroupId: string) => void;
collectTagsFromLocation: (tagGroup: TS.TagGroup) => void;
handleCloseTagGroupMenu: () => void;
- searchLocationIndex: (searchQuery: TS.SearchQuery) => void;
- // openSearchPanel: () => void;
+ setSearchQuery: (searchQuery: TS.SearchQuery) => void;
maxSearchResults: number;
}
@@ -93,7 +91,7 @@ const TagGroupMenu = (props: Props) => {
function showFilesWithTags() {
if (props.selectedTagGroupEntry) {
// props.openSearchPanel();
- props.searchLocationIndex({
+ props.setSearchQuery({
tagsOR: props.selectedTagGroupEntry.children,
maxSearchResults: props.maxSearchResults
});
@@ -190,8 +188,7 @@ function mapStateToProps(state) {
function mapDispatchToProps(dispatch) {
return bindActionCreators(
{
- // openSearchPanel: AppActions.openSearchPanel,
- searchLocationIndex: LocationIndexActions.searchLocationIndex
+ setSearchQuery: LocationIndexActions.setSearchQuery
},
dispatch
);
diff --git a/app/components/menus/TagMenu.tsx b/app/components/menus/TagMenu.tsx
index 2a7bb2add..d45193285 100644
--- a/app/components/menus/TagMenu.tsx
+++ b/app/components/menus/TagMenu.tsx
@@ -30,7 +30,7 @@ import MenuItem from '@material-ui/core/MenuItem';
import { actions as LocationIndexActions } from '-/reducers/location-index';
import i18n from '-/services/i18n';
import { getMaxSearchResults } from '-/reducers/settings';
-import { actions as AppActions, getSelectedEntries } from '-/reducers/app';
+import { getSelectedEntries } from '-/reducers/app';
import { TS } from '-/tagspaces.namespace';
import TaggingActions from '-/reducers/tagging-actions';
@@ -42,8 +42,7 @@ interface Props {
open?: boolean;
onClose: () => void;
selectedTag?: TS.Tag;
- searchLocationIndex: (searchQuery: TS.SearchQuery) => void;
- // openSearchPanel: () => void;
+ setSearchQuery: (searchQuery: TS.SearchQuery) => void;
showEditTagDialog: () => void;
showDeleteTagDialog: () => void;
maxSearchResults: number;
@@ -59,7 +58,7 @@ const TagMenu = (props: Props) => {
function showFilesWithThisTag() {
if (props.selectedTag) {
// props.openSearchPanel();
- props.searchLocationIndex({
+ props.setSearchQuery({
tagsAND: [props.selectedTag],
maxSearchResults: props.maxSearchResults
});
@@ -134,8 +133,7 @@ function mapStateToProps(state) {
function mapDispatchToProps(dispatch) {
return bindActionCreators(
{
- // openSearchPanel: AppActions.openSearchPanel,
- searchLocationIndex: LocationIndexActions.searchLocationIndex,
+ setSearchQuery: LocationIndexActions.setSearchQuery,
addTags: TaggingActions.addTags
},
dispatch
diff --git a/app/utils/misc.ts b/app/utils/misc.ts
index f509ec138..6ebe098b8 100644
--- a/app/utils/misc.ts
+++ b/app/utils/misc.ts
@@ -106,7 +106,10 @@ export function parseTextQuery(textQuery: string, identifier: string) {
}
export function removeAllTagsFromQuery(query: string) {
- return query.replace(/([+-?]\S+)/g, '').trim();
+ if (query) {
+ return query.replace(/([+-?]\S+)/g, '').trim();
+ }
+ return '';
}
export function mergeWithExtractedTags(