1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-10 19:29:56 +00:00

Change search result text (#5871)

* fix warnings

* change search result text
This commit is contained in:
Michael An
2023-12-29 12:20:07 +08:00
committed by GitHub
parent 628e06f7b8
commit 2ab7ca1e90
4 changed files with 76 additions and 58 deletions

View File

@@ -50,6 +50,7 @@ const propTypes = {
onItemRename: PropTypes.func.isRequired, onItemRename: PropTypes.func.isRequired,
posX: PropTypes.number, posX: PropTypes.number,
posY: PropTypes.number, posY: PropTypes.number,
dirent: PropTypes.object,
}; };
class DirentGridView extends React.Component { class DirentGridView extends React.Component {

View File

@@ -49,7 +49,7 @@ export default class AISearch extends Component {
isLoading: false, isLoading: false,
hasMore: true, hasMore: true,
isMaskShow: false, isMaskShow: false,
isResultShow: false, showRecent: true,
isResultGetted: false, isResultGetted: false,
isCloseShow: false, isCloseShow: false,
isSearchInputShow: false, // for mobile isSearchInputShow: false, // for mobile
@@ -228,6 +228,9 @@ export default class AISearch extends Component {
}; };
onChangeHandler = (event) => { onChangeHandler = (event) => {
if (this.state.showRecent) {
this.setState({ showRecent: false });
}
const newValue = event.target.value; const newValue = event.target.value;
this.setState({ value: newValue }, () => { this.setState({ value: newValue }, () => {
if (this.inputValue === newValue.trim()) return; if (this.inputValue === newValue.trim()) return;
@@ -254,7 +257,6 @@ export default class AISearch extends Component {
this.setState({ this.setState({
highlightIndex: 0, highlightIndex: 0,
resultItems: [], resultItems: [],
isResultShow: false,
isResultGetted: false isResultGetted: false
}); });
return; return;
@@ -272,7 +274,6 @@ export default class AISearch extends Component {
this.source.cancel('prev request is cancelled'); this.source.cancel('prev request is cancelled');
} }
this.setState({ this.setState({
isResultShow: true,
isResultGetted: false, isResultGetted: false,
resultItems: [], resultItems: [],
highlightIndex: 0, highlightIndex: 0,
@@ -350,11 +351,11 @@ export default class AISearch extends Component {
value: '', value: '',
isMaskShow: false, isMaskShow: false,
isCloseShow: false, isCloseShow: false,
isResultShow: false,
isResultGetted: false, isResultGetted: false,
resultItems: [], resultItems: [],
highlightIndex: 0, highlightIndex: 0,
isSearchInputShow: false, isSearchInputShow: false,
showRecent: true,
}); });
} }
@@ -403,25 +404,33 @@ export default class AISearch extends Component {
} }
renderSearchResult() { renderSearchResult() {
const { resultItems, highlightIndex, width, searchMode, answeringResult } = this.state; const { resultItems, highlightIndex, width, isResultGetted } = this.state;
if (!width || width === 'default') return null; if (!width || width === 'default') return null;
if (!this.state.isResultShow) { if (this.state.showRecent) {
const { repoID } = this.props; const { repoID } = this.props;
let storeKey = 'sfVisitedAISearchItems'; let storeKey = 'sfVisitedAISearchItems';
if (repoID) { if (repoID) {
storeKey += repoID; storeKey += repoID;
} }
const visitedItems = JSON.parse(localStorage.getItem(storeKey)) || []; const visitedItems = JSON.parse(localStorage.getItem(storeKey)) || [];
return visitedItems.length ? this.renderVisitedItems(visitedItems) : null; if (visitedItems.length) {
return this.renderVisitedItems(visitedItems);
}
} }
if (!this.state.isResultGetted || getValueLength(this.inputValue) < 3) { const searchStrLength = getValueLength(this.inputValue);
return (
<span className="loading-icon loading-tip"></span> if (searchStrLength === 0) {
); return <div className="search-result-none">{gettext('Type characters to start search')}</div>;
} }
if (!resultItems.length) { else if (searchStrLength < 3) {
return <div className="search-result-none">{gettext('Type more characters to start search')}</div>;
}
else if (!isResultGetted) {
return <span className="loading-icon loading-tip"></span>;
}
else if (!resultItems.length) {
return ( return (
<> <>
<li className='search-result-item align-items-center' onClick={this.openAsk}> <li className='search-result-item align-items-center' onClick={this.openAsk}>
@@ -546,7 +555,7 @@ export default class AISearch extends Component {
render() { render() {
let width = this.state.width !== 'default' ? this.state.width : ''; let width = this.state.width !== 'default' ? this.state.width : '';
let style = {'width': width}; let style = {'width': width};
const { isMaskShow, isCloseShow, searchMode, answeringResult, resultItems } = this.state; const { isMaskShow, isCloseShow, searchMode } = this.state;
const placeholder = `${this.props.placeholder}${isMaskShow ? '' : ` (${controlKey} + f )`}`; const placeholder = `${this.props.placeholder}${isMaskShow ? '' : ` (${controlKey} + f )`}`;
if (searchMode === SEARCH_MODE.QA) { if (searchMode === SEARCH_MODE.QA) {

View File

@@ -34,7 +34,7 @@ class Search extends Component {
isLoading: false, isLoading: false,
hasMore: true, hasMore: true,
isMaskShow: false, isMaskShow: false,
isResultShow: false, showRecent: true,
isResultGetted: false, isResultGetted: false,
isCloseShow: false, isCloseShow: false,
isSearchInputShow: false, // for mobile isSearchInputShow: false, // for mobile
@@ -194,6 +194,9 @@ class Search extends Component {
}; };
onChangeHandler = (event) => { onChangeHandler = (event) => {
if (this.state.showRecent) {
this.setState({ showRecent: false });
}
const newValue = event.target.value; const newValue = event.target.value;
this.setState({ value: newValue }, () => { this.setState({ value: newValue }, () => {
if (this.inputValue === newValue.trim()) return; if (this.inputValue === newValue.trim()) return;
@@ -223,7 +226,6 @@ class Search extends Component {
this.setState({ this.setState({
highlightIndex: 0, highlightIndex: 0,
resultItems: [], resultItems: [],
isResultShow: false,
isResultGetted: false isResultGetted: false
}); });
return; return;
@@ -241,7 +243,6 @@ class Search extends Component {
this.source.cancel('prev request is cancelled'); this.source.cancel('prev request is cancelled');
} }
this.setState({ this.setState({
isResultShow: true,
isResultGetted: false, isResultGetted: false,
resultItems: [], resultItems: [],
highlightIndex: 0, highlightIndex: 0,
@@ -281,9 +282,9 @@ class Search extends Component {
}); });
} else { } else {
if (enableSeafileAI) { if (enableSeafileAI) {
this.onAiSearch(queryData, cancelToken) this.onAiSearch(queryData, cancelToken);
} else { } else {
this.onNormalSearch(queryData, cancelToken, page) this.onNormalSearch(queryData, cancelToken, page);
} }
} }
}; };
@@ -381,41 +382,48 @@ class Search extends Component {
value: '', value: '',
isMaskShow: false, isMaskShow: false,
isCloseShow: false, isCloseShow: false,
isResultShow: false,
isResultGetted: false, isResultGetted: false,
resultItems: [], resultItems: [],
highlightIndex: 0, highlightIndex: 0,
isSearchInputShow: false, isSearchInputShow: false,
showRecent: true,
}); });
} }
renderSearchResult() { renderSearchResult() {
const { resultItems, highlightIndex, width } = this.state; const { resultItems, width, showRecent, isResultGetted } = this.state;
if (!width || width === 'default') return null; if (!width || width === 'default') return null;
if (!this.state.isResultShow) { if (showRecent) {
const { repoID } = this.props; const { repoID } = this.props;
let storeKey = 'sfVisitedSearchItems'; let storeKey = 'sfVisitedSearchItems';
if (repoID) { if (repoID) {
storeKey += repoID; storeKey += repoID;
} }
const visitedItems = JSON.parse(localStorage.getItem(storeKey)) || []; const visitedItems = JSON.parse(localStorage.getItem(storeKey)) || [];
return visitedItems.length ? this.renderResults(visitedItems, true) : null; if (visitedItems.length > 0) {
return this.renderResults(visitedItems, true);
}
} }
if (!this.state.isResultGetted || getValueLength(this.inputValue) < 3) { const searchStrLength = getValueLength(this.inputValue);
return (
<span className="loading-icon loading-tip"></span>
);
}
if (!resultItems.length) {
return (
<div className="search-result-none">{gettext('No results matching.')}</div>
);
}
if (searchStrLength === 0) {
return <div className="search-result-none">{gettext('Type characters to start search')}</div>;
}
else if (searchStrLength < 3) {
return <div className="search-result-none">{gettext('Type more characters to start search')}</div>;
}
else if (!isResultGetted) {
return <span className="loading-icon loading-tip"></span>;
}
else if (resultItems.length > 0) {
return this.renderResults(resultItems); return this.renderResults(resultItems);
} }
else {
return <div className="search-result-none">{gettext('No results matching.')}</div>;
}
}
renderResults = (resultItems, isVisited) => { renderResults = (resultItems, isVisited) => {
const { highlightIndex } = this.state; const { highlightIndex } = this.state;

View File

@@ -51,7 +51,7 @@ class SearchViewPanel extends React.Component {
}); });
if (enableSeafileAI) { if (enableSeafileAI) {
this.onAiSearch(params) this.onAiSearch(params);
} else { } else {
this.onNormalSearch(params); this.onNormalSearch(params);
} }
@@ -82,7 +82,7 @@ class SearchViewPanel extends React.Component {
toaster.danger(gettext('Please check the network.'), {duration: 3}); toaster.danger(gettext('Please check the network.'), {duration: 3});
} }
}); });
} };
onAiSearch = (params) => { onAiSearch = (params) => {
let results = []; let results = [];