TagSpaces is an offline, open source, document manager with tagging support
Fix search results are not updating correctly (#1914)
Stanimir1c644240c42e
diff --git a/app/components/FolderContainer.tsx b/app/components/FolderContainer.tsxindex a779e335d..12feee446 100644--- a/app/components/FolderContainer.tsx+++ b/app/components/FolderContainer.tsx@@ -43,7 +43,6 @@ import {import {actions as AppActions,getDirectoryContent,- getSearchResultCount,isReadOnlyMode,getCurrentLocationPath,getCurrentDirectoryPerspective,@@ -51,8 +50,8 @@ import {getSelectedEntries,getProgress,getEditedEntryPaths,- getSearchResultsCount,- isSearchMode+ isSearchMode,+ getLastSearchTimestamp} from '../reducers/app';import TaggingActions from '../reducers/tagging-actions';import LoadingLazy from '../components/LoadingLazy';@@ -168,7 +167,7 @@ interface Props {windowWidth: number;directoryContent: Array<TS.FileSystemEntry>;currentDirectoryPath: string | null;- searchResultCount: number;+ //searchResultCount: number;addTags: () => void;removeTags: () => void;removeAllTags: () => void;@@ -212,7 +211,7 @@ interface Props {editedEntryPaths: Array<TS.EditedEntryPath>;goBack: () => void;goForward: () => void;- searchResultsCount: number;+ lastSearchTimestamp: number;isSearchMode: boolean;openMoveCopyFilesDialog: () => void;}@@ -305,7 +304,7 @@ function FolderContainer(props: Props) {const showWelcomePanel =!currentDirectoryPath &&directoryContent.length < 1 &&- !(props.isSearchMode && props.searchResultsCount >= 0);+ !(props.isSearchMode && props.lastSearchTimestamp);const renderPerspective = () => {if (showWelcomePanel) {@@ -315,7 +314,7 @@ function FolderContainer(props: Props) {return (<ListPerspectiveAsyncdirectoryContent={props.directoryContent}- searchResultsCount={props.searchResultsCount}+ lastSearchTimestamp={props.lastSearchTimestamp}loadDirectoryContent={loadDirectoryContent}openFsEntry={openFsEntry}openRenameEntryDialog={() => setIsRenameEntryDialogOpened(true)}@@ -336,7 +335,7 @@ function FolderContainer(props: Props) {return (<GalleryPerspectiveAsyncdirectoryContent={props.directoryContent}- searchResultsCount={props.searchResultsCount}+ lastSearchTimestamp={props.lastSearchTimestamp}openFsEntry={openFsEntry}currentDirectoryPath={props.currentDirectoryPath}windowWidth={props.windowWidth}@@ -348,7 +347,7 @@ function FolderContainer(props: Props) {return (<MapiquePerspectiveAsyncdirectoryContent={props.directoryContent}- searchResultsCount={props.searchResultsCount}+ lastSearchTimestamp={props.lastSearchTimestamp}currentDirectoryPath={props.currentDirectoryPath}windowWidth={props.windowWidth}switchPerspective={switchPerspective}@@ -360,7 +359,7 @@ function FolderContainer(props: Props) {return (<KanBanPerspectiveAsyncdirectoryContent={props.directoryContent}- searchResultsCount={props.searchResultsCount}+ lastSearchTimestamp={props.lastSearchTimestamp}loadDirectoryContent={props.loadDirectoryContent}openFsEntry={props.openFsEntry}openRenameEntryDialog={() => setIsRenameEntryDialogOpened(true)}@@ -382,7 +381,7 @@ function FolderContainer(props: Props) {return (<GridPerspectiveAsyncdirectoryContent={props.directoryContent}- searchResultsCount={props.searchResultsCount}+ lastSearchTimestamp={props.lastSearchTimestamp}loadDirectoryContent={props.loadDirectoryContent}openFsEntry={props.openFsEntry}openRenameEntryDialog={() => setIsRenameEntryDialogOpened(true)}@@ -664,7 +663,7 @@ function mapStateToProps(state) {selectedEntries: getSelectedEntries(state),directoryContent: getDirectoryContent(state),currentDirectoryPerspective: getCurrentDirectoryPerspective(state),- searchResultCount: getSearchResultCount(state),+ //searchResultCount: getSearchResultCount(state),currentLocationPath: getCurrentLocationPath(state),maxSearchResults: getMaxSearchResults(state),isDesktopMode: getDesktopMode(state),@@ -674,7 +673,7 @@ function mapStateToProps(state) {searchQuery: getSearchQuery(state),defaultPerspective: getDefaultPerspective(state),editedEntryPaths: getEditedEntryPaths(state),- searchResultsCount: getSearchResultsCount(state),+ lastSearchTimestamp: getLastSearchTimestamp(state),isSearchMode: isSearchMode(state)};}@@ -731,7 +730,7 @@ const areEqual = (prevProp: Props, nextProp: Props) =>nextProp.language === prevProp.language &&nextProp.windowHeight === prevProp.windowHeight &&nextProp.searchQuery === prevProp.searchQuery &&- nextProp.searchResultsCount === prevProp.searchResultsCount &&+ nextProp.lastSearchTimestamp === prevProp.lastSearchTimestamp &&nextProp.isSearchMode === prevProp.isSearchMode;export default connect(diff --git a/app/perspectives/grid-perspective/components/GridPagination.tsx b/app/perspectives/grid-perspective/components/GridPagination.tsxindex b31a975e6..ae13cbafd 100644--- a/app/perspectives/grid-perspective/components/GridPagination.tsx+++ b/app/perspectives/grid-perspective/components/GridPagination.tsx@@ -38,14 +38,13 @@ import {actions as AppActions,getCurrentDirectoryColor,getIsMetaLoaded,- getSearchResultCount,getCurrentDirectoryTags,isLoading,getCurrentDirectoryDescription,getLastBackgroundImageChange,getLastThumbnailImageChange,- getLastSelectedEntryPath-} from '-/reducers/app';+ getLastSelectedEntryPath, getLastSearchTimestamp+} from "-/reducers/app";import EntryIcon from '-/components/EntryIcon';import TagsPreview from '-/components/TagsPreview';import TagContainer from '-/components/TagContainer';@@ -96,7 +95,6 @@ interface Props {gridPageLimit: number;currentLocationPath: string;currentDirectoryPath: string;- searchResultCount: number;onContextMenu: (event: React.MouseEvent<HTMLDivElement>) => void;openRenameEntryDialog: () => void;onClick: (event: React.MouseEvent<HTMLDivElement>) => void;@@ -130,7 +128,7 @@ interface Props {) => void;moveFiles: (files: Array<string>, destination: string) => Promise<boolean>;clearSelection: () => void;- searchResultsCount: number;+ lastSearchTimestamp: number;}function GridPagination(props: Props) {@@ -231,7 +229,7 @@ function GridPagination(props: Props) {}, [props.currentLocationPath,props.currentDirectoryPath,- props.searchResultCount+ props.lastSearchTimestamp]);const setThumbs = (@@ -692,7 +690,8 @@ function mapStateToProps(state) {return {isAppLoading: isLoading(state),currentDirectoryColor: getCurrentDirectoryColor(state),- searchResultCount: getSearchResultCount(state),+ lastSearchTimestamp: getLastSearchTimestamp(state),+ // searchResultCount: getSearchResultCount(state),// pageEntries: getPageEntries(state),currentDirectoryTags: getCurrentDirectoryTags(state),isMetaLoaded: getIsMetaLoaded(state),@@ -729,7 +728,7 @@ const areEqual = (prevProp: Props, nextProp: Props) =>nextProp.thumbnailMode === prevProp.thumbnailMode &&nextProp.entrySize === prevProp.entrySize &&nextProp.gridPageLimit === prevProp.gridPageLimit &&- nextProp.searchResultsCount === prevProp.searchResultsCount &&+ nextProp.lastSearchTimestamp === prevProp.lastSearchTimestamp &&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 af3e87ce2..1a0bb3c34 100644--- a/app/perspectives/grid-perspective/components/MainContainer.tsx+++ b/app/perspectives/grid-perspective/components/MainContainer.tsx@@ -119,7 +119,7 @@ interface Props {toggleDeleteMultipleEntriesDialog: () => void;directoryMeta: TS.FileSystemEntryMeta;setDirectoryMeta: (fsEntryMeta: TS.FileSystemEntryMeta) => void;- searchResultsCount: number;+ lastSearchTimestamp: number;searchFilter: string;editedEntryPaths: Array<TS.EditedEntryPath>;}@@ -183,7 +183,7 @@ function GridPerspective(props: Props) {: defaultSettings.orderBy);const sortedDirContent = useRef<Array<TS.FileSystemEntry>>(- props.searchResultsCount < 0 ? props.directoryContent : GlobalSearch.results+ !props.lastSearchTimestamp ? props.directoryContent : GlobalSearch.results);const layoutType = useRef<string>(settings && settings.layoutType@@ -289,14 +289,13 @@ function GridPerspective(props: Props) {}, [// props.currentDirectoryPath, // open subdirsprops.directoryContent, // open subdirs todo rethink this (replace with useEffect for currDirPath changes only)- // props.searchResultsCount,sortBy.current,orderBy.current]);useEffect(() => {if (!firstRender) {- if (props.searchResultsCount > -1) {+ if (props.lastSearchTimestamp) {sortBy.current = 'byRelevance';// orderBy.current = false;} else {@@ -311,10 +310,10 @@ function GridPerspective(props: Props) {}setSortedDirContent();}- }, [props.searchResultsCount]);+ }, [props.lastSearchTimestamp]);function setSortedDirContent() {- if (props.searchResultsCount < 0) {+ if (!props.lastSearchTimestamp) {// not in search modesortedDirContent.current = sortByCriteria(props.directoryContent,@@ -348,7 +347,7 @@ function GridPerspective(props: Props) {useEffect(() => {// HANDLE (ADD/REMOVE sidecar TAGS) IN SEARCH RESULTS- if (!firstRender && props.searchResultsCount > -1) {+ if (!firstRender && props.lastSearchTimestamp) {sortedDirContent.current = GlobalSearch.results;forceUpdate();}@@ -517,7 +516,7 @@ function GridPerspective(props: Props) {if (someFileSelected) {clearSelection();} else {- if (props.searchResultsCount < 0) {+ if (!props.lastSearchTimestamp) {props.setSelectedEntries(props.directoryContent);} else {props.setSelectedEntries(GlobalSearch.results);@@ -825,7 +824,6 @@ 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}@@ -963,7 +961,7 @@ function GridPerspective(props: Props) {sortBy={sortBy.current}orderBy={orderBy.current}handleSortBy={handleSortBy}- searchModeEnabled={props.searchResultsCount > -1}+ searchModeEnabled={props.lastSearchTimestamp !== undefined}/>)}{Boolean(optionsContextMenuAnchorEl) && (diff --git a/app/perspectives/list/components/MainContainer.tsx b/app/perspectives/list/components/MainContainer.tsxindex adadfdb47..32c07b82a 100644--- a/app/perspectives/list/components/MainContainer.tsx+++ b/app/perspectives/list/components/MainContainer.tsx@@ -119,7 +119,7 @@ interface Props {toggleDeleteMultipleEntriesDialog: () => void;directoryMeta: TS.FileSystemEntryMeta;setDirectoryMeta: (fsEntryMeta: TS.FileSystemEntryMeta) => void;- searchResultsCount: number;+ lastSearchTimestamp: number;searchFilter: string;editedEntryPaths: Array<TS.EditedEntryPath>;}@@ -183,7 +183,7 @@ function GridPerspective(props: Props) {: defaultSettings.orderBy);const sortedDirContent = useRef<Array<TS.FileSystemEntry>>(- props.searchResultsCount < 0 ? props.directoryContent : GlobalSearch.results+ !props.lastSearchTimestamp ? props.directoryContent : GlobalSearch.results);const layoutType = useRef<string>(settings && settings.layoutType@@ -289,14 +289,13 @@ function GridPerspective(props: Props) {}, [// props.currentDirectoryPath, // open subdirsprops.directoryContent, // open subdirs todo rethink this (replace with useEffect for currDirPath changes only)- // props.searchResultsCount,sortBy.current,orderBy.current]);useEffect(() => {if (!firstRender) {- if (props.searchResultsCount > -1) {+ if (props.lastSearchTimestamp) {sortBy.current = 'byRelevance';// orderBy.current = false;} else {@@ -311,10 +310,10 @@ function GridPerspective(props: Props) {}setSortedDirContent();}- }, [props.searchResultsCount]);+ }, [props.lastSearchTimestamp]);function setSortedDirContent() {- if (props.searchResultsCount < 0) {+ if (!props.lastSearchTimestamp) {// not in search modesortedDirContent.current = sortByCriteria(props.directoryContent,@@ -348,7 +347,7 @@ function GridPerspective(props: Props) {useEffect(() => {// HANDLE (ADD/REMOVE sidecar TAGS) IN SEARCH RESULTS- if (!firstRender && props.searchResultsCount > -1) {+ if (!firstRender && props.lastSearchTimestamp) {sortedDirContent.current = GlobalSearch.results;forceUpdate();}@@ -517,7 +516,7 @@ function GridPerspective(props: Props) {if (someFileSelected) {clearSelection();} else {- if (props.searchResultsCount < 0) {+ if (!props.lastSearchTimestamp) {props.setSelectedEntries(props.directoryContent);} else {props.setSelectedEntries(GlobalSearch.results);@@ -822,7 +821,6 @@ 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}@@ -961,7 +959,7 @@ function GridPerspective(props: Props) {sortBy={sortBy.current}orderBy={orderBy.current}handleSortBy={handleSortBy}- searchModeEnabled={props.searchResultsCount > -1}+ searchModeEnabled={props.lastSearchTimestamp !== undefined}/>)}{Boolean(optionsContextMenuAnchorEl) && (diff --git a/app/reducers/app.ts b/app/reducers/app.tsindex b25523170..fb2af8576 100644--- a/app/reducers/app.ts+++ b/app/reducers/app.ts@@ -261,7 +261,6 @@ export const initialState = {locationManagerPanelOpened: showLocations,tagLibraryPanelOpened: showTagLibrary,searchPanelOpened: showSearch,- searchResultsCount: -1,user: window.ExtDemoUser? {attributes: window.ExtDemoUser,@@ -557,8 +556,7 @@ export default (state: any = initialState, action: any) => {GlobalSearch.results = action.searchResults;return {...state,- // currentDirectoryEntries: action.searchResults,- searchResultsCount: action.searchResults.length,+ lastSearchTimestamp: new Date().getTime(),isLoading: false};}@@ -567,7 +565,7 @@ export default (state: any = initialState, action: any) => {return {...state,searchMode: false,- searchResultsCount: -1,+ lastSearchTimestamp: undefined,searchFilter: undefined,isLoading: false};@@ -576,7 +574,6 @@ export default (state: any = initialState, action: any) => {GlobalSearch.results = [];return {...state,- // searchResultsCount: -1,searchMode: true,searchFilter: undefined,isLoading: false@@ -594,7 +591,7 @@ export default (state: any = initialState, action: any) => {}return {...state,- searchResultsCount: GlobalSearch.results.length,+ lastSearchTimestamp: new Date().getTime(),// currentDirectoryEntries: newDirEntries,isLoading: false};@@ -2986,10 +2983,12 @@ export const isProgressOpened = (state: any) => state.app.progressDialogOpened;export const getOpenedFiles = (state: any) => state.app.openedFiles;export const getNotificationStatus = (state: any) =>state.app.notificationStatus;+/*export const getSearchResultCount = (state: any) =>Object.keys(state.locationIndex.searchQuery).length === 0? 0: state.app.currentDirectoryEntries.length;+*/export const getCurrentLocationId = (state: any) => state.app.currentLocationId;export const isEntryInFullWidth = (state: any) => state.app.isEntryInFullWidth;export const isLoading = (state: any) => state.app.isLoading;@@ -3000,8 +2999,8 @@ 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;+export const getLastSearchTimestamp = (state: any) =>+ state.app.lastSearchTimestamp;export const isSearchMode = (state: any) => state.app.searchMode;export const getSearchFilter = (state: any) => state.app.searchFilter;