Skip to content

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

chore: refactoring for using config of the search from AppConfig

Ilian Sapundshievce93fa5965ff
diff --git a/src/renderer/AppConfig.ts b/src/renderer/AppConfig.ts
index 3712070bc..6fcfc8d4b 100644
--- a/src/renderer/AppConfig.ts
+++ b/src/renderer/AppConfig.ts
@@ -54,14 +54,15 @@ AppConfig.SearchSizes = {
large: { key: 'sizeLarge', thresholdBytes: 1024 * 1024 * 1024 }, // 50MB - 1GB
huge: { key: 'sizeHuge', thresholdBytes: 1024 * 1024 * 1024 }, // over 1GB
};
+// periodSpan is currently not used
AppConfig.SearchTimePeriods = {
- today: { key: 'today' },
- yesterday: { key: 'yesterday' },
- past7Days: { key: 'past7Days' },
- past30Days: { key: 'past30Days' },
- past6Months: { key: 'past6Months' },
- pastYear: { key: 'pastYear' },
- moreThanYear: { key: 'moreThanYear' },
+ today: { key: 'today', periodSpan: 86400000 },
+ yesterday: { key: 'yesterday', periodSpan: 172800000 }, // 48 hours
+ past7Days: { key: 'past7Days', periodSpan: 604800000 },
+ past30Days: { key: 'past30Days', periodSpan: 2592000000 },
+ past6Months: { key: 'past6Months', periodSpan: 15778476000 },
+ pastYear: { key: 'pastYear', periodSpan: 31556952000 },
+ moreThanYear: { key: 'moreThanYear', periodSpan: 31556952001 },
};
AppConfig.SearchTypeGroups =
typeof window !== 'undefined' && window.ExtSearchTypeGroups !== undefined
diff --git a/src/renderer/components/SearchAutocomplete.tsx b/src/renderer/components/SearchAutocomplete.tsx
index bbca790a9..0f476c892 100644
--- a/src/renderer/components/SearchAutocomplete.tsx
+++ b/src/renderer/components/SearchAutocomplete.tsx
@@ -16,63 +16,62 @@
*
*/
-import React, {
- useContext,
- useEffect,
- useReducer,
- useRef,
- useState,
-} from 'react';
-import Fuse from 'fuse.js';
-import { useSelector, useDispatch } from 'react-redux';
-import { format, formatDistanceToNow } from 'date-fns';
-import HelpOutlineIcon from '@mui/icons-material/HelpOutline';
-import TsButton from '-/components/TsButton';
-import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
-import Tooltip from '-/components/Tooltip';
-import TsIconButton from '-/components/TsIconButton';
-import AdvancedSearchIcon from '@mui/icons-material/TuneOutlined';
-import { actions as AppActions, AppDispatch } from '../reducers/app';
-import {
- getMaxSearchResults,
- getShowUnixHiddenEntries,
-} from '-/reducers/settings';
-import { haveSearchFilters } from '-/services/search';
-import { TS } from '-/tagspaces.namespace';
-import { Pro } from '-/pro';
import AppConfig from '-/AppConfig';
-import { Autocomplete, Box } from '@mui/material';
+import { CloseIcon } from '-/components/CommonIcons';
import {
- accuracy,
ActionType,
ExecActions,
- FileSize,
- findAction,
- isAction,
- LastModified,
- scope,
ScopeType,
SearchActions,
SearchOptionType,
SearchQueryComposition,
+ accuracy,
+ findAction,
+ isAction,
+ scope,
} from '-/components/SearchOptions';
-import { CloseIcon } from '-/components/CommonIcons';
-import { getTagLibrary } from '-/services/taglibrary-utils';
import { getSearchOptions } from '-/components/SearchOptionsMenu';
+import Tooltip from '-/components/Tooltip';
+import TsButton from '-/components/TsButton';
+import TsIconButton from '-/components/TsIconButton';
import TsTextField from '-/components/TsTextField';
-import { dataTidFormat } from '-/services/test';
-import { useTheme } from '@mui/material/styles';
-import { useTranslation } from 'react-i18next';
-import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';
+import { useBrowserHistoryContext } from '-/hooks/useBrowserHistoryContext';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';
import { useLocationIndexContext } from '-/hooks/useLocationIndexContext';
-import { removePrefix } from '-/services/utils-io';
-import { isDesktopMode } from '-/reducers/settings';
+import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';
import { useSavedSearchesContext } from '-/hooks/useSavedSearchesContext';
-import { useBrowserHistoryContext } from '-/hooks/useBrowserHistoryContext';
-import useFirstRender from '-/utils/useFirstRender';
import { useSearchQueryContext } from '-/hooks/useSearchQueryContext';
+import { Pro } from '-/pro';
+import {
+ getMaxSearchResults,
+ getShowUnixHiddenEntries,
+ isDesktopMode,
+} from '-/reducers/settings';
+import { haveSearchFilters } from '-/services/search';
+import { getTagLibrary } from '-/services/taglibrary-utils';
+import { dataTidFormat } from '-/services/test';
+import { removePrefix } from '-/services/utils-io';
+import { TS } from '-/tagspaces.namespace';
+import useFirstRender from '-/utils/useFirstRender';
+import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
+import HelpOutlineIcon from '@mui/icons-material/HelpOutline';
+import AdvancedSearchIcon from '@mui/icons-material/TuneOutlined';
+import { Autocomplete, Box } from '@mui/material';
+import { useTheme } from '@mui/material/styles';
+import { formatFileSize } from '@tagspaces/tagspaces-common/misc';
+import { format, formatDistanceToNow } from 'date-fns';
+import Fuse from 'fuse.js';
+import React, {
+ useContext,
+ useEffect,
+ useReducer,
+ useRef,
+ useState,
+} from 'react';
+import { useTranslation } from 'react-i18next';
+import { useDispatch, useSelector } from 'react-redux';
+import { actions as AppActions, AppDispatch } from '../reducers/app';
interface Props {
style?: any;
@@ -718,24 +717,45 @@ function SearchAutocomplete(props: Props) {
currentOptions.current = action;
const options = [];
- Object.entries(FileSize).forEach(([key, value]) => {
+ Object.entries(AppConfig.SearchSizes).forEach((size: any) => {
let descr = '';
- if (value > 0) {
- if (value < 1000000) {
- descr = value / 1000 + 'KB';
- } else if (value < 1000000000) {
- descr = value / 1000000 + 'MB';
- } else if (value === 1000000000) {
- descr = value / 1000000000 + 'G';
- } else {
- descr = 'over 1GB';
- }
+ if (size[1].key === AppConfig.SearchSizes.empty.key) {
+ descr = formatFileSize(size[1].thresholdBytes);
+ } else if (size[1].key === AppConfig.SearchSizes.tiny.key) {
+ descr =
+ formatFileSize(AppConfig.SearchSizes.empty.thresholdBytes) +
+ ' < ' +
+ formatFileSize(AppConfig.SearchSizes.tiny.thresholdBytes);
+ } else if (size[1].key === AppConfig.SearchSizes.verySmall.key) {
+ descr =
+ formatFileSize(AppConfig.SearchSizes.tiny.thresholdBytes) +
+ ' < ' +
+ formatFileSize(AppConfig.SearchSizes.verySmall.thresholdBytes);
+ } else if (size[1].key === AppConfig.SearchSizes.small.key) {
+ descr =
+ formatFileSize(AppConfig.SearchSizes.verySmall.thresholdBytes) +
+ ' < ' +
+ formatFileSize(AppConfig.SearchSizes.small.thresholdBytes);
+ } else if (size[1].key === AppConfig.SearchSizes.medium.key) {
+ descr =
+ formatFileSize(AppConfig.SearchSizes.small.thresholdBytes) +
+ ' < ' +
+ formatFileSize(AppConfig.SearchSizes.medium.thresholdBytes);
+ } else if (size[1].key === AppConfig.SearchSizes.large.key) {
+ descr =
+ formatFileSize(AppConfig.SearchSizes.medium.thresholdBytes) +
+ ' < ' +
+ formatFileSize(AppConfig.SearchSizes.large.thresholdBytes);
+ } else if (size[1].key === AppConfig.SearchSizes.huge.key) {
+ descr =
+ ' > ' +
+ formatFileSize(AppConfig.SearchSizes.large.thresholdBytes);
}
options.push({
- id: key,
+ id: size[1].key,
action: ExecActions.SIZE_SEARCH,
- label: t('core:' + key),
- descr: descr,
+ label: t('core:' + size[1].key),
+ descr: '(' + descr + ')',
filter,
});
});
@@ -750,11 +770,11 @@ function SearchAutocomplete(props: Props) {
currentOptions.current = action;
const options = [];
- Object.entries(LastModified).forEach(([key, value]) => {
+ Object.entries(AppConfig.SearchTimePeriods).forEach((period: any) => {
options.push({
- id: key,
+ id: period[1].key,
action: ExecActions.LAST_MODIFIED_SEARCH,
- label: t('core:' + key),
+ label: t('core:' + period[1].key),
filter,
});
});
diff --git a/src/renderer/components/SearchOptions.ts b/src/renderer/components/SearchOptions.ts
index 6e992ca72..cce1b2993 100644
--- a/src/renderer/components/SearchOptions.ts
+++ b/src/renderer/components/SearchOptions.ts
@@ -48,12 +48,6 @@ export const SearchQueryComposition = {
},
};
-/*export const searchMode = {
- NOT_IN_SEARCH_MODE: 'NOT_IN_SEARCH_MODE',
- // search mode but search is not started
- INITIAL_SEARCH_MODE: 'NOT_IN_SEARCH_MODE'
-};*/
-
export const SearchActions = {
LOCATION: {
shortName: 'l:',
@@ -81,19 +75,6 @@ export const SearchActions = {
},
};
-/*export const SearchCommandFullNames = {
- TYPE: 'type:',
- SIZE: 'size:',
- LAST_MODIFIED: 'lastmod:',
- SCOPE: 'scope:',
- ACCURACY: 'accuracy:',
- LOCATION: 'location:',
- FILTER: 'filter:',
- HISTORY: 'history:',
- BOOK: 'bookmark:',
- SEARCH: 'search:'
-};*/
-
export const ExecActions = {
OPEN_LOCATION: 'open_location',
OPEN_HISTORY: 'open_history',
@@ -109,25 +90,6 @@ export const ExecActions = {
ACCURACY_SEARCH: 'accuracy_search',
};
-export const FileSize = {
- sizeEmpty: 0,
- sizeTiny: 10000, // 10KB
- sizeVerySmall: 100000, // 100KB
- sizeSmall: 1000000, // 1MB
- sizeMedium: 50000000, // 50 mB
- sizeLarge: 1000000000, // 1GB
- sizeHuge: 1000000001, // over 1GB
-};
-
-export const LastModified = {
- today: 86400000, // 1 day
- yesterday: 172800000, // 48 hours
- past7Days: 604800000, // 7 days
- past30Days: 2592000000, // 30 days
- past6Months: 15778476000, // 6 months
- pastYear: 31556952000, // 1 year
- moreThanYear: 31556952001, // over 1 year
-};
export const scope = {
location: 'location' as ScopeType,
folder: 'folder' as ScopeType,
@@ -142,18 +104,6 @@ export const accuracy = {
export type ScopeType = 'location' | 'folder' | 'global';
-/*export function toActionFullName(action): string {
- const actions = {
- ...SearchQueryComposition,
- ...SearchActions
- };
- const actionFind = Object.entries(actions).find(a => a[1] === action);
- if (actionFind && SearchCommandFullNames[actionFind[0]]) {
- return SearchCommandFullNames[actionFind[0]];
- }
- return action;
-}*/
-
export function isAction(action: string, actionType: ActionType): boolean {
return (
action !== undefined &&
@@ -173,9 +123,6 @@ export function findAction(option: string, equal = false): string {
);
if (action) {
return action.fullName ? action.fullName : action.shortName;
- /*action = Object.values(SearchCommandFullNames).find(a =>
- equal ? option === a : option.startsWith(a)
- );*/
}
return undefined;
}