TagSpaces is an offline, open source, document manager with tagging support
Make redux aware of displaying search results (#1819)
Stanimird31a41bae60d
diff --git a/app/components/FolderContainer.tsx b/app/components/FolderContainer.tsxindex 8b1521143..bb2c59afb 100644--- a/app/components/FolderContainer.tsx+++ b/app/components/FolderContainer.tsx@@ -50,7 +50,8 @@ import {OpenedEntry,getSelectedEntries,getProgress,- getEditedEntryPaths+ getEditedEntryPaths,+ getSearchResultsCount} from '../reducers/app';import TaggingActions from '../reducers/tagging-actions';import LoadingLazy from '../components/LoadingLazy';@@ -217,6 +218,7 @@ interface Props {editedEntryPaths: Array<TS.EditedEntryPath>;goBack: () => void;goForward: () => void;+ searchResultsCount: number;}function FolderContainer(props: Props) {@@ -335,6 +337,7 @@ function FolderContainer(props: Props) {return (<ListPerspectiveAsyncdirectoryContent={props.directoryContent}+ searchResultsCount={props.searchResultsCount}loadDirectoryContent={loadDirectoryContent}openFsEntry={openFsEntry}openRenameEntryDialog={() => setIsRenameEntryDialogOpened(true)}@@ -355,6 +358,7 @@ function FolderContainer(props: Props) {return (<GalleryPerspectiveAsyncdirectoryContent={props.directoryContent}+ searchResultsCount={props.searchResultsCount}openFsEntry={openFsEntry}currentDirectoryPath={props.currentDirectoryPath}windowWidth={props.windowWidth}@@ -366,6 +370,7 @@ function FolderContainer(props: Props) {return (<MapiquePerspectiveAsyncdirectoryContent={props.directoryContent}+ searchResultsCount={props.searchResultsCount}currentDirectoryPath={props.currentDirectoryPath}windowWidth={props.windowWidth}switchPerspective={switchPerspective}@@ -377,6 +382,7 @@ function FolderContainer(props: Props) {return (<KanBanPerspectiveAsyncdirectoryContent={props.directoryContent}+ searchResultsCount={props.searchResultsCount}loadDirectoryContent={props.loadDirectoryContent}openFsEntry={props.openFsEntry}openRenameEntryDialog={() => setIsRenameEntryDialogOpened(true)}@@ -398,6 +404,7 @@ function FolderContainer(props: Props) {return (<GridPerspectiveAsyncdirectoryContent={props.directoryContent}+ searchResultsCount={props.searchResultsCount}loadDirectoryContent={props.loadDirectoryContent}openFsEntry={props.openFsEntry}openRenameEntryDialog={() => setIsRenameEntryDialogOpened(true)}@@ -713,7 +720,8 @@ function mapStateToProps(state) {searchQuery: getSearchQuery(state),// keyBindings: getKeyBindingObject(state),defaultPerspective: getDefaultPerspective(state),- editedEntryPaths: getEditedEntryPaths(state)+ editedEntryPaths: getEditedEntryPaths(state),+ searchResultsCount: getSearchResultsCount(state)};}@@ -768,7 +776,8 @@ const areEqual = (prevProp: Props, nextProp: Props) =>nextProp.windowHeight === prevProp.windowHeight &&nextProp.language === prevProp.language &&nextProp.windowHeight === prevProp.windowHeight &&- nextProp.searchQuery === prevProp.searchQuery;+ nextProp.searchQuery === prevProp.searchQuery &&+ nextProp.searchResultsCount === prevProp.searchResultsCount;export default connect(mapStateToProps,diff --git a/app/components/SearchInline.tsx b/app/components/SearchInline.tsxindex 5d88e47d7..b4a8d1888 100644--- a/app/components/SearchInline.tsx+++ b/app/components/SearchInline.tsx@@ -66,7 +66,7 @@ interface Props {// loadDirectoryContent: (path: string, generateThumbnails: boolean, loadDirMeta?: boolean) => void;openURLExternally: (url: string) => void;searchQuery: TS.SearchQuery; // () => any;- openCurrentDirectory: () => void;+ // openCurrentDirectory: () => void;setSearchQuery: (searchQuery: TS.SearchQuery) => void;openLink: (url: string, options?: any) => void;currentDirectory: string;@@ -269,7 +269,7 @@ function SearchInline(props: Props) {executeSearch();} else if (event.key === 'Escape' || event.keyCode === 27) {clearSearch();- props.openCurrentDirectory();+ // props.openCurrentDirectory();}};@@ -289,6 +289,7 @@ function SearchInline(props: Props) {forceIndexing.current = false;fileSize.current = '';props.setSearchQuery({});+ // props.setSearchResults([]);props.watchForChanges();// props.openCurrentDirectory();};@@ -502,7 +503,7 @@ function SearchInline(props: Props) {id="clearSearchID"onClick={() => {clearSearch();- props.openCurrentDirectory();+ // props.openCurrentDirectory();}}size="small"edge="end"@@ -563,7 +564,7 @@ function mapDispatchToProps(dispatch) {// loadDirectoryContent: AppActions.loadDirectoryContent,openLink: AppActions.openLink,openURLExternally: AppActions.openURLExternally,- openCurrentDirectory: AppActions.openCurrentDirectory,+ // openCurrentDirectory: AppActions.openCurrentDirectory,watchForChanges: AppActions.watchForChanges},dispatchdiff --git a/app/locales/en/core.json b/app/locales/en/core.jsonindex 922f433a9..b40cdeba8 100644--- a/app/locales/en/core.json+++ b/app/locales/en/core.json@@ -403,6 +403,7 @@"tagDelimiterUnderscore": "underscore (_)","tagDelimiterComma": "comma (,)","maxSearchResultChoose": "Max Search Results",+ "searchResults": "Search Results","releaseToDrop": "Drop files to import them...","releaseToMoveDrop": "Move files here...","loading": "Loading...",diff --git a/app/package.json b/app/package.jsonindex 8051d6238..b514ccacf 100644--- a/app/package.json+++ b/app/package.json@@ -16,7 +16,7 @@"@tagspaces/extensions": "1.0.48"},"nodeDependencies": {- "@tagspaces/tagspaces-ws": "2.1.9",+ "@tagspaces/tagspaces-ws": "2.1.10","@tagspaces/extensions": "1.0.48","sharp": "^0.30.7"}diff --git a/app/perspectives/grid-perspective/components/GridPagination.tsx b/app/perspectives/grid-perspective/components/GridPagination.tsxindex 76e51715f..6080de6b2 100644--- a/app/perspectives/grid-perspective/components/GridPagination.tsx+++ b/app/perspectives/grid-perspective/components/GridPagination.tsx@@ -130,6 +130,7 @@ interface Props {) => void;moveFiles: (files: Array<string>, destination: string) => Promise<boolean>;clearSelection: () => void;+ searchResultsCount: number;}function GridPagination(props: Props) {@@ -725,6 +726,7 @@ const areEqual = (prevProp: Props, nextProp: Props) =>nextProp.thumbnailMode === prevProp.thumbnailMode &&nextProp.entrySize === prevProp.entrySize &&nextProp.gridPageLimit === prevProp.gridPageLimit &&+ nextProp.searchResultsCount === prevProp.searchResultsCount &&nextProp.currentDirectoryDescription ===prevProp.currentDirectoryDescription &&JSON.stringify(nextProp.files) === JSON.stringify(prevProp.files) &&diff --git a/app/perspectives/grid-perspective/components/MainContainer.tsx b/app/perspectives/grid-perspective/components/MainContainer.tsxindex 924cde06a..668559d7a 100644--- a/app/perspectives/grid-perspective/components/MainContainer.tsx+++ b/app/perspectives/grid-perspective/components/MainContainer.tsx@@ -72,6 +72,7 @@ import Links from '-/content/links';import { defaultSettings } from '../index';import { PerspectiveIDs } from '-/perspectives';import { fileOperationsEnabled } from '-/perspectives/common/main-container';+import GlobalSearch from '-/services/search-index';interface Props {classes: any;@@ -115,6 +116,7 @@ interface Props {toggleDeleteMultipleEntriesDialog: () => void;directoryMeta: TS.FileSystemEntryMeta;setDirectoryMeta: (fsEntryMeta: TS.FileSystemEntryMeta) => void;+ searchResultsCount: number;}function getSettings(directoryMeta: TS.FileSystemEntryMeta): TS.FolderSettings {@@ -548,10 +550,14 @@ function GridPerspective(props: Props) {.filter(fsEntry => fsEntry.isFile).map(fsentry => fsentry.path): [];- const sortedDirectories = sortedDirContentMemoized.filter(- entry => !entry.isFile- );- const sortedFiles = sortedDirContentMemoized.filter(entry => entry.isFile);+ const sortedDirectories =+ props.searchResultsCount > 0+ ? []+ : sortedDirContentMemoized.filter(entry => !entry.isFile);+ const sortedFiles =+ props.searchResultsCount > 0+ ? GlobalSearch.results+ : sortedDirContentMemoized.filter(entry => entry.isFile);const locationPath = props.currentLocation? PlatformIO.getLocationPath(props.currentLocation): '';@@ -702,6 +708,7 @@ function GridPerspective(props: Props) {singleClickAction={singleClickAction.current}currentLocation={props.currentLocation}directoryContent={props.directoryContent}+ searchResultsCount={props.searchResultsCount}supportedFileTypes={props.supportedFileTypes}openFsEntry={props.openFsEntry}openFileNatively={props.openFileNatively}diff --git a/app/perspectives/list/components/MainContainer.tsx b/app/perspectives/list/components/MainContainer.tsxindex 5d25d56f8..f6ad411a0 100644--- a/app/perspectives/list/components/MainContainer.tsx+++ b/app/perspectives/list/components/MainContainer.tsx@@ -71,6 +71,7 @@ import Links from '-/content/links';import { defaultSettings } from '../index';import { PerspectiveIDs } from '-/perspectives';import { fileOperationsEnabled } from '-/perspectives/common/main-container';+import GlobalSearch from '-/services/search-index';interface Props {classes: any;@@ -114,6 +115,7 @@ interface Props {toggleDeleteMultipleEntriesDialog: () => void;directoryMeta: TS.FileSystemEntryMeta;setDirectoryMeta: (fsEntryMeta: TS.FileSystemEntryMeta) => void;+ searchResultsCount: number;}function getSettings(directoryMeta: TS.FileSystemEntryMeta): TS.FolderSettings {@@ -555,10 +557,14 @@ function GridPerspective(props: Props) {.filter(fsEntry => fsEntry.isFile).map(fsentry => fsentry.path): [];- const sortedDirectories = sortedDirContentMemoized.filter(- entry => !entry.isFile- );- const sortedFiles = sortedDirContentMemoized.filter(entry => entry.isFile);+ const sortedDirectories =+ props.searchResultsCount > 0+ ? []+ : sortedDirContentMemoized.filter(entry => !entry.isFile);+ const sortedFiles =+ props.searchResultsCount > 0+ ? GlobalSearch.results+ : sortedDirContentMemoized.filter(entry => entry.isFile);const locationPath = props.currentLocation? PlatformIO.getLocationPath(props.currentLocation): '';@@ -704,6 +710,7 @@ function GridPerspective(props: Props) {currentLocation={props.currentLocation}// lastSelectedEntry={props.lastSelectedEntry}directoryContent={props.directoryContent}+ searchResultsCount={props.searchResultsCount}supportedFileTypes={props.supportedFileTypes}openFsEntry={props.openFsEntry}openFileNatively={props.openFileNatively}diff --git a/app/reducers/app.ts b/app/reducers/app.tsindex 33941faba..e8230a98e 100644--- a/app/reducers/app.ts+++ b/app/reducers/app.ts@@ -76,6 +76,7 @@ import {setTagLibrary} from '-/services/taglibrary-utils';import { getProTeaserSlideIndex } from '-/content/ProTeaserSlides';+import GlobalSearch from '-/services/search-index';export const types = {DEVICE_ONLINE: 'APP/DEVICE_ONLINE',@@ -245,7 +246,7 @@ export const initialState = {locationManagerPanelOpened: showLocations,tagLibraryPanelOpened: showTagLibrary,searchPanelOpened: showSearch,- helpFeedbackPanelOpened: false,+ searchResultsCount: 0,user: window.ExtDemoUser? {attributes: window.ExtDemoUser,@@ -518,25 +519,28 @@ export default (state: any = initialState, action: any) => {};}case types.SET_SEARCH_RESULTS: {+ GlobalSearch.results = action.searchResults;return {...state,- currentDirectoryEntries: action.searchResults,+ // currentDirectoryEntries: action.searchResults,+ searchResultsCount: action.searchResults.length,isLoading: false};}case types.APPEND_SEARCH_RESULTS: {- const newDirEntries = [...state.currentDirectoryEntries];+ // const newDirEntries = [...state.currentDirectoryEntries];for (let i = 0; i < action.searchResults.length; i += 1) {- const index = newDirEntries.findIndex(+ const index = GlobalSearch.results.findIndex(entry => entry.path === action.searchResults[i].path);if (index === -1) {- newDirEntries.push(action.searchResults[i]);+ GlobalSearch.results.push(action.searchResults[i]);}}return {...state,- currentDirectoryEntries: newDirEntries,+ searchResultsCount: GlobalSearch.results.length,+ // currentDirectoryEntries: newDirEntries,isLoading: false};}@@ -2752,3 +2756,4 @@ export const isTagLibraryPanelOpened = (state: any) =>export const isSearchPanelOpened = (state: any) => state.app.searchPanelOpened;export const isHelpFeedbackPanelOpened = (state: any) =>state.app.helpFeedbackPanelOpened;+export const getSearchResultsCount = (state: any) => state.app.searchResultsCount;diff --git a/app/reducers/location-index.ts b/app/reducers/location-index.tsindex 483fda148..83a82255d 100644--- a/app/reducers/location-index.ts+++ b/app/reducers/location-index.ts@@ -179,7 +179,15 @@ export default (state: any = initialState, action: any) => {};export const actions = {- setSearchQuery: (searchQuery: TS.SearchQuery) => ({+ setSearchQuery: (searchQuery: TS.SearchQuery) => (+ dispatch: (action) => void+ ) => {+ dispatch(actions.setSearchQueryInt(searchQuery));+ if (Object.keys(searchQuery).length === 0) {+ dispatch(AppActions.setSearchResults([]));+ }+ },+ setSearchQueryInt: (searchQuery: TS.SearchQuery) => ({type: types.SET_SEARCH_QUERY,searchQuery}),diff --git a/app/services/search-index.ts b/app/services/search-index.tsindex 19849844e..113b1831e 100644--- a/app/services/search-index.ts+++ b/app/services/search-index.ts@@ -18,6 +18,7 @@const GlobalSearch = {indexLoadedOn: undefined,- index: []+ index: [],+ results: []};export default GlobalSearch;diff --git a/app/services/utils-io.ts b/app/services/utils-io.tsindex 283a0e522..5e2028de2 100644--- a/app/services/utils-io.ts+++ b/app/services/utils-io.ts@@ -43,7 +43,8 @@ import {extractDirectoryName,getThumbFileLocationForFile,getThumbFileLocationForDirectory,- getBgndFileLocationForDirectory+ getBgndFileLocationForDirectory,+ cleanFrontDirSeparator} from '@tagspaces/tagspaces-common/paths';import AppConfig from '-/AppConfig';import PlatformIO from './platform-facade';@@ -1423,16 +1424,3 @@ export function getRelativeEntryPath(relEntryPath = cleanFrontDirSeparator(relEntryPath);return relEntryPath;}--export function cleanFrontDirSeparator(dirPath) {- if (dirPath) {- if (dirPath.startsWith('\\')) {- return dirPath.substring(1);- }- if (dirPath.startsWith('/')) {- return dirPath.substring(1);- }- return dirPath;- }- return '';-}diff --git a/package-lock.json b/package-lock.jsonindex 62637280d..844b50d6a 100644--- a/package-lock.json+++ b/package-lock.json@@ -21,7 +21,7 @@"@mui/styles": "5.10.15","@mui/x-date-pickers": "^5.0.8","@tagspaces/tagspaces-md": "2.1.6",- "@tagspaces/tagspaces-platforms": "2.1.9",+ "@tagspaces/tagspaces-platforms": "2.1.10","aws-amplify": "^4.3.8","aws-sdk": "^2.1036.0","babel-polyfill": "^6.26.0",@@ -13820,9 +13820,9 @@}},"node_modules/@tagspaces/tagspaces-platforms": {- "version": "2.1.9",- "resolved": "https://registry.npmjs.org/@tagspaces/tagspaces-platforms/-/tagspaces-platforms-2.1.9.tgz",- "integrity": "sha512-wjeVw5c72ZN9p0XTuBMHfjEQ+XftunC8sSEFxzpcxIV9GWYK6Pz7J9oh3byhrM+DDKU4RKehzTguDsL4DgLVXQ==",+ "version": "2.1.10",+ "resolved": "https://registry.npmjs.org/@tagspaces/tagspaces-platforms/-/tagspaces-platforms-2.1.10.tgz",+ "integrity": "sha512-zQs3p2JKoMHyBi15OD0fbEPgU8e2OgZK4dWwD2ovwSAj2kkVzT6x+DJkSmgkmt+2DJO8/0OuwoOAxOrq2Wnxbg==","hasInstallScript": true},"node_modules/@testim/chrome-version": {@@ -59479,9 +59479,9 @@}},"@tagspaces/tagspaces-platforms": {- "version": "2.1.9",- "resolved": "https://registry.npmjs.org/@tagspaces/tagspaces-platforms/-/tagspaces-platforms-2.1.9.tgz",- "integrity": "sha512-wjeVw5c72ZN9p0XTuBMHfjEQ+XftunC8sSEFxzpcxIV9GWYK6Pz7J9oh3byhrM+DDKU4RKehzTguDsL4DgLVXQ=="+ "version": "2.1.10",+ "resolved": "https://registry.npmjs.org/@tagspaces/tagspaces-platforms/-/tagspaces-platforms-2.1.10.tgz",+ "integrity": "sha512-zQs3p2JKoMHyBi15OD0fbEPgU8e2OgZK4dWwD2ovwSAj2kkVzT6x+DJkSmgkmt+2DJO8/0OuwoOAxOrq2Wnxbg=="},"@testim/chrome-version": {"version": "1.1.3",diff --git a/package.json b/package.jsonindex d37a4570e..a91f2f3bb 100644--- a/package.json+++ b/package.json@@ -158,7 +158,7 @@"@mui/styles": "5.10.15","@mui/x-date-pickers": "^5.0.8","@tagspaces/tagspaces-md": "2.1.6",- "@tagspaces/tagspaces-platforms": "2.1.9",+ "@tagspaces/tagspaces-platforms": "2.1.10","aws-amplify": "^4.3.8","aws-sdk": "^2.1036.0","babel-polyfill": "^6.26.0",