1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-18 17:22:05 +00:00

fix: semantic-search-enter (#5704)

* fix: semantic-search-enter

* fix: semantic-search-enter

* fix: code
This commit is contained in:
杨国璇 2023-10-23 16:03:54 +08:00 committed by GitHub
parent 5d1229cec2
commit 86f535db2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -167,15 +167,23 @@ class Search extends Component {
};
onChangeHandler = (event) => {
const { searchMode } = this.state;
const newValue = event.target.value;
this.setState({ value: newValue }, () => {
if (this.inputValue === newValue.trim()) return;
this.inputValue = newValue.trim();
this.onSearch();
this.onSearch(searchMode === SEARCH_MODE.NORMAL);
});
};
onSearch = () => {
onKeydownHandler = (event) => {
if (isHotkey('enter', event)) {
if (this.state.searchMode === SEARCH_MODE.NORMAL) return;
this.onSearch(true);
}
};
onSearch = (isGetSearchResult) => {
const { value } = this.state;
const { repoID } = this.props;
const _this = this;
@ -190,6 +198,7 @@ class Search extends Component {
});
return;
}
if (!isGetSearchResult) return;
const queryData = {
q: value,
@ -488,18 +497,18 @@ class Search extends Component {
if (searchMode === SEARCH_MODE.SIMILARITY) {
if (currentIndexState === INDEX_STATE.FINISHED) {
this.onSearch();
this.onSearch(true);
return;
}
seafileAPI.queryLibraryIndexState(repoID).then(res => {
const { state: indexState, task_id: taskId } = res.data;
this.setState({ indexState }, () => {
if (indexState === INDEX_STATE.FINISHED) {
this.onSearch();
this.onSearch(true);
return;
}
if (indexState === INDEX_STATE.RUNNING) {
this.queryIndexTaskStatus(taskId, this.onSearch);
this.queryIndexTaskStatus(taskId, () => this.onSearch(true));
return;
}
});
@ -569,6 +578,7 @@ class Search extends Component {
autoComplete="off"
ref={this.inputRef}
readOnly={isCloseShow && enableSeafileAI && SEARCH_MODE.SIMILARITY === searchMode && indexState !== INDEX_STATE.FINISHED}
onKeyDown={this.onKeydownHandler}
/>
{(this.state.isCloseShow && username) &&
<a href={searchPageUrl} className="search-icon-right input-icon-addon fas fa-external-link-alt search-icon-arrow"></a>