Skip to content

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

Tags from stored queries are showed without colors (#1995)

Stanimirc55ac7e07b85
diff --git a/app/components/SearchAutocomplete.tsx b/app/components/SearchAutocomplete.tsx
index 43c84ec9c..55070f506 100644
--- a/app/components/SearchAutocomplete.tsx
+++ b/app/components/SearchAutocomplete.tsx
@@ -189,6 +189,10 @@ function SearchAutocomplete(props: Props) {
}*/
useEffect(() => {
+ processSearchQuery();
+ }, [searchQuery]);
+
+ function processSearchQuery() {
if (Object.keys(searchQuery).length > 0) {
let emptySearch = true;
const actions: SearchOptionType[] = [];
@@ -200,7 +204,9 @@ function SearchAutocomplete(props: Props) {
actions.push({
action: SearchQueryComposition.TAG_AND.shortName,
- label: SearchQueryComposition.TAG_AND.shortName + tag.title
+ label: SearchQueryComposition.TAG_AND.shortName + tag.title,
+ color: tag.color,
+ textcolor: tag.textcolor
});
});
emptySearch = false;
@@ -210,7 +216,9 @@ function SearchAutocomplete(props: Props) {
// textQueryMask.current += ' |' + tag.title;
actions.push({
action: SearchQueryComposition.TAG_OR.shortName,
- label: SearchQueryComposition.TAG_OR.shortName + tag.title
+ label: SearchQueryComposition.TAG_OR.shortName + tag.title,
+ color: tag.color,
+ textcolor: tag.textcolor
});
});
emptySearch = false;
@@ -220,7 +228,9 @@ function SearchAutocomplete(props: Props) {
// textQueryMask.current += ' -' + tag.title;
actions.push({
action: SearchQueryComposition.TAG_NOT.shortName,
- label: SearchQueryComposition.TAG_NOT.shortName + tag.title
+ label: SearchQueryComposition.TAG_NOT.shortName + tag.title,
+ color: tag.color,
+ textcolor: tag.textcolor
});
});
emptySearch = false;
@@ -316,7 +326,7 @@ function SearchAutocomplete(props: Props) {
if (!emptySearch) {
if (actions.length > 0) {
actionValues.current = execActions(
- actions,
+ actions, // todo set tag in actions
actionValues.current,
false
);
@@ -338,8 +348,7 @@ function SearchAutocomplete(props: Props) {
clearSearch();
}*/
}
- }, [searchQuery]);
-
+ }
/*function getInputValue() {
const txtQuery = removeActionsFromQuery(
inputValue.current.trim(),
diff --git a/app/components/StoredSearches.tsx b/app/components/StoredSearches.tsx
index e1c9a95a6..b7c544e49 100644
--- a/app/components/StoredSearches.tsx
+++ b/app/components/StoredSearches.tsx
@@ -74,7 +74,7 @@ const historyKeys = Pro && Pro.history ? Pro.history.historyKeys : {};
function StoredSearches(props: Props) {
const { t } = useTranslation();
- const { setSearchQuery } = useDirectoryContentContext();
+ const { setSearchQuery, findFromSavedSearch } = useDirectoryContentContext();
const [saveSearchDialogOpened, setSaveSearchDialogOpened] = useState<
TS.SearchQuery
>(undefined);
@@ -123,19 +123,6 @@ function StoredSearches(props: Props) {
setSaveSearchDialogOpened(savedSearch);
};
- const handleSavedSearchClick = (uuid: string) => {
- const savedSearch = props.searches.find(search => search.uuid === uuid);
- if (!savedSearch) {
- return true;
- }
-
- setSearchQuery({
- ...savedSearch,
- showUnixHiddenEntries: props.showUnixHiddenEntries,
- executeSearch: true
- });
- };
-
function handleFileInputChange(selection: any) {
const target = selection.currentTarget;
const file = target.files[0];
@@ -275,7 +262,7 @@ function StoredSearches(props: Props) {
fontWeight: 'normal',
justifyContent: 'start'
}}
- onClick={() => handleSavedSearchClick(search.uuid)}
+ onClick={() => findFromSavedSearch(search.uuid)}
>
<SearchIcon />
&nbsp;
diff --git a/app/components/menus/SavedSearchesMenu.tsx b/app/components/menus/SavedSearchesMenu.tsx
index 0758638f8..b0bbba392 100644
--- a/app/components/menus/SavedSearchesMenu.tsx
+++ b/app/components/menus/SavedSearchesMenu.tsx
@@ -36,28 +36,15 @@ interface Props {
function SavedSearchesMenu(props: Props) {
const { open, onClose, anchorEl } = props;
const { t } = useTranslation();
- const { setSearchQuery } = useDirectoryContentContext();
+ const { findFromSavedSearch } = useDirectoryContentContext();
const searches = useSelector(state => getSearches(state));
- const showUnixHiddenEntries = useSelector(getShowUnixHiddenEntries);
-
- const handleSavedSearchClick = (uuid: string) => {
- const savedSearch = searches.find(search => search.uuid === uuid);
- if (!savedSearch) {
- return true;
- }
-
- setSearchQuery({
- ...savedSearch,
- showUnixHiddenEntries: showUnixHiddenEntries
- });
- };
const menuItems = searches.length ? (
searches.map(search => (
<MenuItem
key={search.uuid}
onClick={() => {
- handleSavedSearchClick(search.uuid);
+ findFromSavedSearch(search.uuid);
onClose();
}}
>
diff --git a/app/hooks/DirectoryContentContextProvider.tsx b/app/hooks/DirectoryContentContextProvider.tsx
index 3d8149ce8..1f6b39002 100644
--- a/app/hooks/DirectoryContentContextProvider.tsx
+++ b/app/hooks/DirectoryContentContextProvider.tsx
@@ -47,13 +47,19 @@ import { loadJSONFile, merge, updateFsEntries } from '-/services/utils-io';
import AppConfig from '-/AppConfig';
import { PerspectiveIDs } from '-/perspectives';
import { updateHistory } from '-/utils/dom';
-import { getShowUnixHiddenEntries } from '-/reducers/settings';
+import {
+ getShowUnixHiddenEntries,
+ getTagColor,
+ getTagTextColor
+} from '-/reducers/settings';
import { enhanceEntry, getUuid } from '@tagspaces/tagspaces-common/utils-io';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
import useFirstRender from '-/utils/useFirstRender';
import { useNotificationContext } from '-/hooks/useNotificationContext';
import { loadCurrentDirMeta } from '-/services/meta-loader';
import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';
+import { getSearches } from '-/reducers/searches';
+import { getTagColors } from '-/services/taglibrary-utils';
type DirectoryContentContextData = {
currentDirectoryEntries: TS.FileSystemEntry[];
@@ -107,6 +113,7 @@ type DirectoryContentContextData = {
appendSearchResults: (entries: TS.FileSystemEntry[]) => void;
enterSearchMode: () => void;
exitSearchMode: () => void;
+ findFromSavedSearch: (uuid: string) => void;
};
export const DirectoryContentContext = createContext<
@@ -142,7 +149,8 @@ export const DirectoryContentContext = createContext<
setSearchResults: () => {},
appendSearchResults: () => {},
enterSearchMode: () => {},
- exitSearchMode: () => {}
+ exitSearchMode: () => {},
+ findFromSavedSearch: () => {}
});
export type DirectoryContentContextProviderProps = {
@@ -165,6 +173,9 @@ export const DirectoryContentContextProvider = ({
//const useGenerateThumbnails = useSelector(getUseGenerateThumbnails);
const showUnixHiddenEntries = useSelector(getShowUnixHiddenEntries);
const editedEntryPaths = useSelector(getEditedEntryPaths);
+ const searches = useSelector(getSearches);
+ const defaultBackgroundColor = useSelector(getTagColor);
+ const defaultTextColor = useSelector(getTagTextColor);
//const enableWS = useSelector(getEnableWS);
const [currentDirectoryEntries, setCurrentDirectoryEntries] = useState<
@@ -503,7 +514,7 @@ export const DirectoryContentContextProvider = ({
function openCurrentDirectory(
showHiddenEntries = undefined
): Promise<boolean> {
- if (currentDirectoryPath.current) {
+ if (currentDirectoryPath.current !== undefined) {
return openDirectory(currentDirectoryPath.current, showHiddenEntries);
}
return Promise.resolve(false);
@@ -698,6 +709,42 @@ export const DirectoryContentContextProvider = ({
}
}
+ function updateTagColors(tags: TS.Tag[]) {
+ return tags.map(tag => {
+ const tagColors = getTagColors(
+ tag.title,
+ defaultTextColor,
+ defaultBackgroundColor
+ );
+ return {
+ ...tag,
+ ...tagColors
+ };
+ });
+ }
+
+ function findFromSavedSearch(uuid: string) {
+ const savedSearch = searches.find(search => search.uuid === uuid);
+ if (!savedSearch) {
+ return true;
+ }
+
+ setSearchQuery({
+ ...savedSearch,
+ ...(savedSearch.tagsAND && {
+ tagsAND: updateTagColors(savedSearch.tagsAND)
+ }),
+ ...(savedSearch.tagsNOT && {
+ tagsNOT: updateTagColors(savedSearch.tagsNOT)
+ }),
+ ...(savedSearch.tagsOR && {
+ tagsOR: updateTagColors(savedSearch.tagsOR)
+ }),
+ showUnixHiddenEntries,
+ executeSearch: true
+ });
+ }
+
const context = useMemo(() => {
return {
currentDirectoryEntries: currentDirectoryEntries,
@@ -730,7 +777,8 @@ export const DirectoryContentContextProvider = ({
setSearchResults,
appendSearchResults,
enterSearchMode,
- exitSearchMode
+ exitSearchMode,
+ findFromSavedSearch
};
}, [
currentLocation,
diff --git a/app/hooks/OpenedEntryContextProvider.tsx b/app/hooks/OpenedEntryContextProvider.tsx
index 38016f78b..8c3957399 100644
--- a/app/hooks/OpenedEntryContextProvider.tsx
+++ b/app/hooks/OpenedEntryContextProvider.tsx
@@ -863,7 +863,7 @@ export const OpenedEntryContextProvider = ({
}
function createFile() {
- if (currentDirectoryPath) {
+ if (currentDirectoryPath !== undefined) {
const filePath =
currentDirectoryPath +
PlatformIO.getDirSeparator() +