From 86f535db2dff8993e87eb236b23f2bc22ae2a18d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=9B=BD=E7=92=87?= <37972689+er-pai-r@users.noreply.github.com> Date: Mon, 23 Oct 2023 16:03:54 +0800 Subject: [PATCH] fix: semantic-search-enter (#5704) * fix: semantic-search-enter * fix: semantic-search-enter * fix: code --- frontend/src/components/search/search.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/search/search.js b/frontend/src/components/search/search.js index d9c83a7abf..bcb4dc66a0 100644 --- a/frontend/src/components/search/search.js +++ b/frontend/src/components/search/search.js @@ -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) &&