Skip to content

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

feat: enabling global search by no opened location

Ilian Sapundshiev411e865a8b99
diff --git a/app/components/FolderContainer.tsx b/app/components/FolderContainer.tsx
index dbfe5ba62..532bdcc17 100644
--- a/app/components/FolderContainer.tsx
+++ b/app/components/FolderContainer.tsx
@@ -309,7 +309,10 @@ class FolderContainer extends React.Component<Props, State> {
};
renderPerspective() {
- if (!this.props.currentDirectoryPath) {
+ if (
+ !this.props.currentDirectoryPath &&
+ this.props.directoryContent.length < 1
+ ) {
return <WelcomePanelAsync />;
}
if (this.state.currentPerspective === 'gallery') {
@@ -415,71 +418,69 @@ class FolderContainer extends React.Component<Props, State> {
}}
/>
<div className={classes.flexMiddle} />
- {currentDirectoryPath && (
- <React.Fragment>
- {isDesktopMode &&
- this.state.pathParts &&
- this.state.pathParts.map(pathPart => (
+ <React.Fragment>
+ {isDesktopMode &&
+ this.state.pathParts &&
+ this.state.pathParts.map(pathPart => (
+ <Button
+ key={pathPart}
+ onClick={() => loadDirectoryContent(pathPart)}
+ title={'Navigate to: ' + pathPart}
+ style={{
+ paddingLeft: 3,
+ paddingRight: 0,
+ minWidth: 10
+ }}
+ >
+ {extractShortDirectoryName(pathPart, '/')}
+ <FolderSeparatorIcon />
+ </Button>
+ ))}
+ {!isDesktopMode &&
+ this.state.pathParts &&
+ this.state.pathParts.length > 0 && (
+ <React.Fragment>
<Button
- key={pathPart}
- onClick={() => loadDirectoryContent(pathPart)}
- title={'Navigate to: ' + pathPart}
- style={{
- paddingLeft: 3,
- paddingRight: 0,
- minWidth: 10
- }}
+ onClick={loadParentDirectoryContent}
+ data-tid="openParentDirectory"
+ style={{ paddingLeft: 3, paddingRight: 0 }}
>
- {extractShortDirectoryName(pathPart, '/')}
- <FolderSeparatorIcon />
+ <BackButtonIcon />
</Button>
- ))}
- {!isDesktopMode &&
- this.state.pathParts &&
- this.state.pathParts.length > 0 && (
- <React.Fragment>
- <Button
- onClick={loadParentDirectoryContent}
- data-tid="openParentDirectory"
- style={{ paddingLeft: 3, paddingRight: 0 }}
- >
- <BackButtonIcon />
- </Button>
- </React.Fragment>
- )}
- <Button
- data-tid="folderContainerOpenDirMenu"
- title={
- i18n.t('core:openDirectoryMenu') +
- ' - ' +
- (currentDirectoryPath || '')
- }
- className={classes.folderButton}
- onClick={this.openDirectoryMenu}
- onContextMenu={this.openDirectoryMenu}
- >
- {extractShortDirectoryName(
- normalizePath(normalizedCurrentDirPath),
- '/'
- )}
- <MoreVertIcon />
- </Button>
- <DirectoryMenu
- open={this.state.directoryContextMenuOpened}
- onClose={this.closeDirectoryMenu}
- anchorEl={this.state.directoryContextMenuAnchorEl}
- directoryPath={currentDirectoryPath}
- loadDirectoryContent={this.props.loadDirectoryContent}
- openDirectory={this.props.openDirectory}
- reflectCreateEntry={this.props.reflectCreateEntry}
- openFile={this.props.openFile}
- toggleCreateFileDialog={this.props.toggleCreateFileDialog}
- deleteDirectory={this.props.deleteDirectory}
- switchPerspective={this.switchPerspective}
- isReadOnlyMode={this.props.isReadOnlyMode}
- />
- </React.Fragment>
- )}
+ </React.Fragment>
+ )}
+ <Button
+ data-tid="folderContainerOpenDirMenu"
+ title={
+ i18n.t('core:openDirectoryMenu') +
+ ' - ' +
+ (currentDirectoryPath || '')
+ }
+ className={classes.folderButton}
+ onClick={this.openDirectoryMenu}
+ onContextMenu={this.openDirectoryMenu}
+ >
+ {extractShortDirectoryName(
+ normalizePath(normalizedCurrentDirPath),
+ '/'
+ )}
+ <MoreVertIcon />
+ </Button>
+ <DirectoryMenu
+ open={this.state.directoryContextMenuOpened}
+ onClose={this.closeDirectoryMenu}
+ anchorEl={this.state.directoryContextMenuAnchorEl}
+ directoryPath={currentDirectoryPath}
+ loadDirectoryContent={this.props.loadDirectoryContent}
+ openDirectory={this.props.openDirectory}
+ reflectCreateEntry={this.props.reflectCreateEntry}
+ openFile={this.props.openFile}
+ toggleCreateFileDialog={this.props.toggleCreateFileDialog}
+ deleteDirectory={this.props.deleteDirectory}
+ switchPerspective={this.switchPerspective}
+ isReadOnlyMode={this.props.isReadOnlyMode}
+ />
+ </React.Fragment>
</div>
</div>
<div
diff --git a/app/components/Search.tsx b/app/components/Search.tsx
index b944f9ed8..957d4c1c7 100644
--- a/app/components/Search.tsx
+++ b/app/components/Search.tsx
@@ -82,6 +82,7 @@ interface Props {
openURLExternally: (url: string) => void;
hideDrawer?: () => void;
searchQuery: () => any;
+ setSearchResults: (entries: Array<any>) => void;
setSearchQuery: (searchQuery: SearchQuery) => void;
currentDirectory: string;
indexedEntriesCount: number;
@@ -320,7 +321,8 @@ class Search extends React.Component<Props, State> {
const {
setSearchQuery,
loadDirectoryContent,
- currentDirectory
+ currentDirectory,
+ setSearchResults
} = this.props;
setSearchQuery({});
setTimeout(() => {
@@ -347,7 +349,11 @@ class Search extends React.Component<Props, State> {
fileSize: ''
},
() => {
- loadDirectoryContent(currentDirectory);
+ if (currentDirectory) {
+ loadDirectoryContent(currentDirectory);
+ } else {
+ setSearchResults([]);
+ }
this.focusMainSearchFiled();
}
);
@@ -844,7 +850,8 @@ function mapDispatchToProps(dispatch) {
searchLocationIndex: LocationIndexActions.searchLocationIndex,
createLocationsIndexes: LocationIndexActions.createLocationsIndexes,
loadDirectoryContent: AppActions.loadDirectoryContent,
- openURLExternally: AppActions.openURLExternally
+ openURLExternally: AppActions.openURLExternally,
+ setSearchResults: AppActions.setSearchResults
},
dispatch
);
diff --git a/app/reducers/location-index.ts b/app/reducers/location-index.ts
index 42965692b..bd1038d6a 100644
--- a/app/reducers/location-index.ts
+++ b/app/reducers/location-index.ts
@@ -382,10 +382,6 @@ export const actions = {
getState: () => any
) => {
const state = getState();
- const currentLocation: Location = getLocation(
- state,
- state.app.currentLocationId
- );
console.time('globalSearch');
dispatch(
AppActions.showNotification(i18n.t('core:searching'), 'default', false)
@@ -408,7 +404,7 @@ export const actions = {
let directoryIndex = [];
let hasIndex = false;
const dirSeparator =
- currentLocation.type === locationType.TYPE_CLOUD
+ location.type === locationType.TYPE_CLOUD
? '/'
: AppConfig.dirSeparator;
console.log('Searching in: ' + nextPath);